Author: DartPeng
Date: 2009-05-20 05:41:53 -0400 (Wed, 20 May 2009)
New Revision: 15359
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectoreSelectionDialog.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
Log:
JBIDE-4232
active the node which is new creation
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectoreSelectionDialog.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectoreSelectionDialog.java 2009-05-20
09:10:40 UTC (rev 15358)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SelectoreSelectionDialog.java 2009-05-20
09:41:53 UTC (rev 15359)
@@ -112,7 +112,8 @@
viewer = new TreeViewer(composite, SWT.BORDER);
viewer.setContentProvider(new CompoundStructuredDataContentProvider());
viewer.setLabelProvider(new CompoundStructuredDataLabelProvider());
- viewer.setInput(generateInputData());
+ List<Object> inputList = generateInputData();
+ viewer.setInput(inputList);
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
okPressed();
@@ -153,6 +154,9 @@
handleButtons();
getShell().setText("Selector generate dialog");
+
+ SmooksUIUtils.expandSelectorViewer(inputList, viewer);
+
return composite;
}
@@ -172,7 +176,7 @@
});
}
- protected List<?> generateInputData() {
+ protected List<Object> generateInputData() {
List<Object> list = new ArrayList<Object>();
if (this.graphicsExt != null) {
IJavaProject project = SmooksUIUtils.getJavaProject(graphicsExt);
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java 2009-05-20
09:10:40 UTC (rev 15358)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksConfigurationFormPage.java 2009-05-20
09:41:53 UTC (rev 15359)
@@ -283,6 +283,7 @@
}
}
};
+
runnable.run();
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java 2009-05-20
09:10:40 UTC (rev 15358)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMasterDetailBlock.java 2009-05-20
09:41:53 UTC (rev 15359)
@@ -29,6 +29,7 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -55,15 +56,13 @@
import org.eclipse.ui.forms.widgets.Section;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
import org.jboss.tools.smooks.model.common.AbstractAnyType;
-import org.jboss.tools.smooks.model.smooks.SmooksResourceListType;
/**
* @author Dart Peng (dpeng(a)redhat.com)
* <p>
* Date Apr 1, 2009
*/
-public class SmooksMasterDetailBlock extends MasterDetailsBlock implements
IMenuListener,
- ISelectionChangedListener {
+public class SmooksMasterDetailBlock extends MasterDetailsBlock implements IMenuListener,
ISelectionChangedListener {
private Section configurationSection;
private SectionPart sectionPart;
@@ -95,8 +94,6 @@
createSmooksTreeViewer(tool, managedForm, parent);
}
-
-
@Override
public void createContent(IManagedForm managedForm) {
super.createContent(managedForm);
@@ -131,18 +128,16 @@
// provider.registePage(ResourceType.class, new
// SmooksStuffPropertyDetailPage());
detailsPart.registerPage(EObject.class, new SmooksStuffPropertyDetailPage(
- (SmooksMultiFormEditor) this.formEditor));
+ (SmooksMultiFormEditor) this.formEditor));
}
-
- protected void refreshSmooksTreeViewer(){
+
+ protected void refreshSmooksTreeViewer() {
smooksTreeViewer.refresh();
}
- protected void createSmooksTreeViewer(FormToolkit tool, final IManagedForm managedForm,
- Composite rootMainControl) {
+ protected void createSmooksTreeViewer(FormToolkit tool, final IManagedForm managedForm,
Composite rootMainControl) {
configurationSection = tool.createSection(rootMainControl, Section.TITLE_BAR);
- configurationSection
- .setDescription("Define Smooks elements for configuration file in the following
section.");
+ configurationSection.setDescription("Define Smooks elements for configuration file
in the following section.");
configurationSection.setText("Message Filtering Resources");
sectionPart = new SectionPart(configurationSection);
managedForm.addPart(sectionPart);
@@ -162,12 +157,9 @@
tableComposite.setLayout(fillLayout);
smooksTreeViewer = new TreeViewer(tableComposite, SWT.NONE);
smooksTreeViewer.addSelectionChangedListener(this);
-
-
-
- smooksTreeViewer.setContentProvider(new AdapterFactoryContentProvider(editingDomain
- .getAdapterFactory()));
-
+
+ smooksTreeViewer.setContentProvider(new
AdapterFactoryContentProvider(editingDomain.getAdapterFactory()));
+
smooksTreeViewer.setLabelProvider(new DecoratingLabelProvider(new
AdapterFactoryLabelProvider(editingDomain
.getAdapterFactory()) {
@@ -188,6 +180,38 @@
}
},
SmooksConfigurationActivator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
+ if(true)
+ {
+ smooksTreeViewer.setComparer(new IElementComparer() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang
+ * .Object, java.lang.Object)
+ */
+ public boolean equals(Object a, Object b) {
+ Object elementA = AdapterFactoryEditingDomain.unwrap(a);
+ Object elementB = AdapterFactoryEditingDomain.unwrap(b);
+ if (elementA == elementB) {
+ return true;
+ }
+ return elementA == null ? elementB == null : elementA.equals(elementB);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.
+ * lang.Object)
+ */
+ public int hashCode(Object element) {
+ return element.hashCode();
+ }
+
+ });
+ }
+
smooksTreeViewer.setFilters(new ViewerFilter[] { new TextEObjectModelFilter() });
Object smooksModel = ((SmooksMultiFormEditor) this.formEditor).getSmooksModel();
if (smooksModel != null) {
@@ -197,12 +221,12 @@
formEditor.getSite().setSelectionProvider(smooksTreeViewer);
if (formEditor.getEditorSite().getActionBarContributor() instanceof
ISelectionChangedListener) {
- smooksTreeViewer.addSelectionChangedListener((ISelectionChangedListener) formEditor
- .getEditorSite().getActionBarContributor());
+ smooksTreeViewer.addSelectionChangedListener((ISelectionChangedListener)
formEditor.getEditorSite()
+ .getActionBarContributor());
}
smooksTreeViewer.addSelectionChangedListener(this);
- tableComposite.setBackground(new Color(null,128,128,128));
-
+ tableComposite.setBackground(new Color(null, 128, 128, 128));
+
gd = new GridData(GridData.FILL_BOTH);
tableComposite.setLayoutData(gd);
tool.paintBordersFor(tableComposite);
@@ -233,20 +257,20 @@
gd.widthHint = 0;
buttonComposite.setLayoutData(gd);
buttonComposite.setVisible(false);
-
+
hookButtons();
}
protected List<?> getViewerSelections() {
IStructuredSelection selections = (IStructuredSelection)
smooksTreeViewer.getSelection();
return selections.toList();
-// List<Object> nl = new ArrayList<Object>();
-// for (Iterator<?> iterator = l.iterator(); iterator.hasNext();) {
-// Object object = (Object) iterator.next();
-// // object = AdapterFactoryEditingDomain.unwrap(object);
-// nl.add(object);
-// }
-// return l;
+ // List<Object> nl = new ArrayList<Object>();
+ // for (Iterator<?> iterator = l.iterator(); iterator.hasNext();) {
+ // Object object = (Object) iterator.next();
+ // // object = AdapterFactoryEditingDomain.unwrap(object);
+ // nl.add(object);
+ // }
+ // return l;
}
private void hookButtons() {
@@ -269,7 +293,7 @@
downButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
List<?> list = getViewerSelections();
- if(list.size() == 1){
+ if (list.size() == 1) {
Object obj = list.get(0);
EObject v = (EObject) AdapterFactoryEditingDomain.unwrap(obj);
EObject parent = v.eContainer();
@@ -289,14 +313,14 @@
private void createMenuForViewer(TreeViewer smooksTreeViewer2) {
MenuManager contextMenu = new MenuManager();
-// contextMenu.add(new Separator("additions"));
+ // contextMenu.add(new Separator("additions"));
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(this);
Menu menu = contextMenu.createContextMenu(smooksTreeViewer2.getControl());
smooksTreeViewer2.getControl().setMenu(menu);
-// formEditor.getSite().registerContextMenu(contextMenu,
-// new UnwrappingSelectionProvider(smooksTreeViewer2));
+ // formEditor.getSite().registerContextMenu(contextMenu,
+ // new UnwrappingSelectionProvider(smooksTreeViewer2));
}
public TreeViewer getSmooksTreeViewer() {
@@ -308,8 +332,7 @@
}
public void menuAboutToShow(IMenuManager menuManager) {
- ((IMenuListener) formEditor.getEditorSite().getActionBarContributor())
- .menuAboutToShow(menuManager);
+ ((IMenuListener)
formEditor.getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
}
private class TextEObjectModelFilter extends ViewerFilter {
@@ -320,11 +343,11 @@
if (obj instanceof BasicFeatureMapEntry) {
EStructuralFeature sf = ((BasicFeatureMapEntry) obj).getEStructuralFeature();
if (sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT)
- || sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA)) {
+ || sf.equals(XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA)) {
return false;
}
- }else{
- if(obj.getClass() == String.class){
+ } else {
+ if (obj.getClass() == String.class) {
return false;
}
}
@@ -345,39 +368,42 @@
* @param selections
*/
protected void updateButtons(List<?> selections) {
- removeButton.setEnabled(true);
- upButton.setEnabled(true);
- downButton.setEnabled(true);
- if (selections.size() >= 1) {
- for (Iterator<?> iterator = selections.iterator(); iterator.hasNext();) {
- Object object = (Object) iterator.next();
- object = AdapterFactoryEditingDomain.unwrap(object);
- if (object instanceof SmooksResourceListType
- || object instanceof org.jboss.tools.smooks10.model.smooks.SmooksResourceListType)
{
- removeButton.setEnabled(false);
- break;
- }
- }
- }
- if (selections.size() == 1) {
- Object selection = selections.get(0);
- if (selection instanceof SmooksResourceListType
- || selection instanceof org.jboss.tools.smooks10.model.smooks.SmooksResourceListType)
{
- upButton.setEnabled(false);
- downButton.setEnabled(false);
- } else {
- if (selection instanceof EObject) {
- EObject parent = ((EObject) selection).eContainer();
- int index = parent.eContents().indexOf(selection);
- if (index <= 0) {
- upButton.setEnabled(false);
- }
- if (index >= parent.eContents().size() - 1) {
- downButton.setEnabled(false);
- }
- }
- }
- }
+ // removeButton.setEnabled(true);
+ // upButton.setEnabled(true);
+ // downButton.setEnabled(true);
+ // if (selections.size() >= 1) {
+ // for (Iterator<?> iterator = selections.iterator();
+ // iterator.hasNext();) {
+ // Object object = (Object) iterator.next();
+ // object = AdapterFactoryEditingDomain.unwrap(object);
+ // if (object instanceof SmooksResourceListType
+ // || object instanceof
+ // org.jboss.tools.smooks10.model.smooks.SmooksResourceListType) {
+ // removeButton.setEnabled(false);
+ // break;
+ // }
+ // }
+ // }
+ // if (selections.size() == 1) {
+ // Object selection = selections.get(0);
+ // if (selection instanceof SmooksResourceListType
+ // || selection instanceof
+ // org.jboss.tools.smooks10.model.smooks.SmooksResourceListType) {
+ // upButton.setEnabled(false);
+ // downButton.setEnabled(false);
+ // } else {
+ // if (selection instanceof EObject) {
+ // EObject parent = ((EObject) selection).eContainer();
+ // int index = parent.eContents().indexOf(selection);
+ // if (index <= 0) {
+ // upButton.setEnabled(false);
+ // }
+ // if (index >= parent.eContents().size() - 1) {
+ // downButton.setEnabled(false);
+ // }
+ // }
+ // }
+ // }
}
/*
@@ -397,11 +423,10 @@
objList.add(obj);
}
if (objList.isEmpty()) {
- sectionPart.getManagedForm()
- .fireSelectionChanged(sectionPart, event.getSelection());
+ sectionPart.getManagedForm().fireSelectionChanged(sectionPart,
event.getSelection());
} else {
sectionPart.getManagedForm().fireSelectionChanged(sectionPart,
- new StructuredSelection(objList.toArray()));
+ new StructuredSelection(objList.toArray()));
}
updateButtons(objList);
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java 2009-05-20
09:10:40 UTC (rev 15358)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/SmooksMultiFormEditor.java 2009-05-20
09:41:53 UTC (rev 15359)
@@ -33,17 +33,19 @@
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.edit.provider.IWrapperItemProvider;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.jface.text.DocumentEvent;
@@ -56,7 +58,6 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.views.properties.PropertySheetPage;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
import org.jboss.tools.smooks.configuration.SmooksConstants;
@@ -100,7 +101,7 @@
protected EditingDomain editingDomain = null;
- private PropertySheetPage propertySheetPage = null;
+// private PropertySheetPage propertySheetPage = null;
private SmooksGraphicsExtType smooksGraphicsExt = null;
@@ -126,13 +127,26 @@
handleEMFModelChange();
// Try to select the affected objects.
//
- Command mostRecentCommand = ((CommandStack)
event.getSource()).getMostRecentCommand();
- if (mostRecentCommand != null && (mostRecentCommand instanceof AddCommand))
{
- setSelectionToViewer(mostRecentCommand.getAffectedObjects());
- }
- if (propertySheetPage != null &&
!propertySheetPage.getControl().isDisposed()) {
- propertySheetPage.refresh();
- }
+ final Command mostRecentCommand = ((CommandStack)
event.getSource()).getMostRecentCommand();
+ getContainer().getDisplay().asyncExec
+ (new Runnable() {
+ public void run() {
+ if (mostRecentCommand != null) {
+ Command rawCommand = mostRecentCommand;
+ while (rawCommand instanceof CommandWrapper) {
+ rawCommand = ((CommandWrapper) rawCommand).getCommand();
+ }
+ if (rawCommand instanceof SetCommand || rawCommand instanceof AddCommand ||
rawCommand instanceof DeleteCommand) {
+ setSelectionToViewer(mostRecentCommand.getAffectedObjects());
+ }
+ }
+ }
+ });
+
+//
+// if (propertySheetPage != null &&
!propertySheetPage.getControl().isDisposed()) {
+// propertySheetPage.refresh();
+// }
}
});
}
@@ -221,9 +235,10 @@
List<Object> newList = new ArrayList<Object>();
for (Iterator<?> iterator = theSelection.iterator(); iterator.hasNext();) {
Object object = (Object) iterator.next();
- if (object instanceof IWrapperItemProvider) {
- newList.add(((IWrapperItemProvider) object).getValue());
- }
+ // if (object instanceof IWrapperItemProvider) {
+ // newList.add(((IWrapperItemProvider) object).getValue());
+ // }
+ newList.add(object);
}
configurationPage.setSelectionToViewer(newList);
}
@@ -475,7 +490,7 @@
*/
public void setDiagnosticList(List<Diagnostic> d) {
this.diagnosticList = d;
-
+
if (markerHelper != null) {
Resource resource = editingDomain.getResourceSet().getResources().get(0);
if (resource != null) {
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-05-20
09:10:40 UTC (rev 15358)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-05-20
09:41:53 UTC (rev 15359)
@@ -45,6 +45,7 @@
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
@@ -121,6 +122,8 @@
public static int VALUE_TYPE_CDATA = 0;
+ public static final int SELECTOR_EXPAND_MAX_LEVEL = 5;
+
public static void createMixedTextFieldEditor(String label, AdapterFactoryEditingDomain
editingdomain,
FormToolkit toolkit, Composite parent, Object model, boolean linkLabel,
IHyperlinkListener listener) {
createMixedTextFieldEditor(label, editingdomain, toolkit, parent, model, false, 0,
linkLabel, false, listener,
@@ -331,10 +334,10 @@
return createStringFieldEditor(label, parent, editingdomain, toolkit,
itemPropertyDescriptor, model, false,
true, true, 0, listener, valueType, action);
}
-
- public static boolean isLinuxOS(){
+
+ public static boolean isLinuxOS() {
Object osName = System.getProperties().get("os.name");
- if(osName != null && "linux".equalsIgnoreCase(osName.toString())){
+ if (osName != null && "linux".equalsIgnoreCase(osName.toString())) {
return true;
}
return false;
@@ -438,9 +441,9 @@
}
gd = new GridData(GridData.FILL_HORIZONTAL);
-
+
int textType = SWT.FLAT;
- if(isLinuxOS()){
+ if (isLinuxOS()) {
textType = SWT.BORDER;
}
if (multiText) {
@@ -1134,7 +1137,32 @@
}
}
}
+
+ private static void expandSelectorViewer(IXMLStructuredObject model,TreeViewer viewer ,
List<String> expandedModel , int level){
+ if(level >= SELECTOR_EXPAND_MAX_LEVEL) return;
+ level++;
+ if(expandedModel.contains(model.getNodeName())){
+ return;
+ }else{
+ expandedModel.add(model.getNodeName());
+ viewer.expandToLevel(model, 0);
+ List<IXMLStructuredObject> children = model.getChildren();
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ IXMLStructuredObject structuredObject = (IXMLStructuredObject) iterator.next();
+ expandSelectorViewer(structuredObject, viewer,expandedModel,level);
+ }
+ }
+ }
+ public static void expandSelectorViewer(List<Object> models, TreeViewer viewer) {
+ for (Iterator<?> iterator = models.iterator(); iterator.hasNext();) {
+ Object model = (Object) iterator.next();
+ if (model instanceof IXMLStructuredObject) {
+ expandSelectorViewer((IXMLStructuredObject)model,viewer,new
ArrayList<String>(),0);
+ }
+ }
+ }
+
public static void showErrorDialog(Shell shell, Status status) {
ErrorDialog.openError(shell, "Error", "error", status);
//$NON-NLS-1$ //$NON-NLS-2$
}