Author: scabanovich
Date: 2011-03-17 18:14:22 -0400 (Thu, 17 Mar 2011)
New Revision: 29891
Modified:
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/XAttributeSupport.java
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/ComboBoxFieldEditor.java
Log:
JBIDE-8567
https://issues.jboss.org/browse/JBIDE-8567
Modified:
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/XAttributeSupport.java
===================================================================
---
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/XAttributeSupport.java 2011-03-17
22:09:02 UTC (rev 29890)
+++
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/XAttributeSupport.java 2011-03-17
22:14:22 UTC (rev 29891)
@@ -42,18 +42,25 @@
import org.eclipse.swt.widgets.Layout;
import org.eclipse.ui.actions.ActionFactory;
import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.meta.XModelEntity;
import org.jboss.tools.common.meta.action.XAttributeData;
import org.jboss.tools.common.meta.action.XEntityData;
import org.jboss.tools.common.meta.key.WizardKeys;
+import org.jboss.tools.common.model.XModelFactory;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.model.ui.widgets.DefaultSettings;
import org.jboss.tools.common.model.ui.widgets.IWidgetSettings;
+import org.jboss.tools.common.model.util.ModelFeatureFactory;
/**
* @author eskimo
*/
public class XAttributeSupport {
+ public static interface IAttributeDependency extends java.beans.PropertyChangeListener
{
+ public void setSupport(XAttributeSupport support);
+ }
+
boolean isDebugging = ModelUIPlugin.getDefault().isDebugging();
private ArrayList<IModelPropertyEditorAdapter> adapters = new
ArrayList<IModelPropertyEditorAdapter>();
@@ -114,6 +121,8 @@
alwaysGreedy.add(attribute[i].getName());
}
}
+
+ initDependencies(xmo.getModelEntity());
}
public void init(XModelObject xmo, XEntityData data, boolean useObject) {
@@ -145,7 +154,17 @@
}
}
+ initDependencies(data.getModelEntity());
}
+
+ void initDependencies(XModelEntity entity) {
+ String dependencies = entity.getProperty("formDependencies");
+ if(dependencies == null || dependencies.length() == 0) return;
+ IAttributeDependency d =
(IAttributeDependency)ModelFeatureFactory.getInstance().createFeatureInstance(dependencies);
+ if(d == null) return;
+ d.setSupport(this);
+ addPropertyChangeListener(d);
+ }
public void dispose() {
if (editors!=null) {
@@ -398,7 +417,7 @@
}
public void save() {
- if(xmo == null) throw new IllegalArgumentException("" + //$NON-NLS-1$
+ if(xmo == null) throw new IllegalArgumentException("" + //$NON-NLS-1$
"Init support with XModelObject before saving"); //$NON-NLS-1$
if(xmo.getModel()==null) throw new IllegalArgumentException("Cannot store deleted
or removed XModel object"); //$NON-NLS-1$
xmo.getModel().saveOptions();
Modified:
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/ComboBoxFieldEditor.java
===================================================================
---
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/ComboBoxFieldEditor.java 2011-03-17
22:09:02 UTC (rev 29890)
+++
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/ComboBoxFieldEditor.java 2011-03-17
22:14:22 UTC (rev 29891)
@@ -83,6 +83,8 @@
private ModifyListener modifyListener;
private DisposeListener disposeListener;
+ private SimpleContentProposalProvider cpp;
+
public ComboBoxFieldEditor() {
// setStyle(SWT.DROP_DOWN | SWT.BORDER);
}
@@ -253,14 +255,7 @@
}
String[] ts = getTags();
- Set<String> set = new TreeSet<String>();
- for (int i = 0; i < ts.length; i++) set.add(ts[i]);
- if(elements != null) for (int i = 0; i < elements.length; i++) {
- set.add(elements[i].toString());
- }
-
-
- SimpleContentProposalProvider cpp = new SimpleContentProposalProvider(set.toArray(new
String[0]));
+ cpp = new SimpleContentProposalProvider(prepareProposals(ts, elements));
cpp.setFiltering(true);
KeyStroke ks = AttributeContentProposalProviderFactory.getCtrlSpaceKeyStroke();
@@ -280,6 +275,15 @@
return comboField;
}
+ private String[] prepareProposals(String[] tags, Object[] elements) {
+ Set<String> set = new TreeSet<String>();
+ for (int i = 0; i < tags.length; i++) set.add(tags[i]);
+ if(elements != null) for (int i = 0; i < elements.length; i++) {
+ set.add(elements[i].toString());
+ }
+ return set.toArray(new String[0]);
+ }
+
protected void valueChanged() {
/*added by Max Areshkau
*hack which was applied for fix JBIDE-1694
@@ -444,14 +448,17 @@
String v = comboField.getText();
valueProvider.removeValueChangeListener(this);
String[] tags = getTags();
+ cpp.setProposals(prepareProposals(tags, elements));
comboField.setItems(tags);
comboField.setText(v);
int i = comboField.getSelectionIndex();
valueProvider.addValueChangeListener(this);
- if(i < 0 && tags != null && tags.length > 0) {
- comboField.setText(tags[0]);
- } else if(i < 0) {
- comboField.setText(""); //$NON-NLS-1$
+ if((propertyEditor.getInput() instanceof DefaultValueAdapter) &&
!((DefaultValueAdapter)propertyEditor.getInput()).getAttribute().getConstraint().accepts("anyRandomValue"))
{
+ if(i < 0 && tags != null && tags.length > 0) {
+ comboField.setText(tags[0]);
+ } else if(i < 0) {
+ comboField.setText(""); //$NON-NLS-1$
+ }
}
}
}
@@ -532,4 +539,15 @@
comboField.setFocus();
}
}
+
+ public void setFocusAndKeepSelection() {
+ if (comboField != null) {
+ Point p = comboField.getSelection();
+ comboField.getParent().setFocus();
+ comboField.setFocus();
+ if(p != null) {
+ comboField.setSelection(p);
+ }
+ }
+ }
}