Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2011-05-11 11:37:09 +0000
committervlorenzo2011-05-11 11:37:09 +0000
commit1bd83a8f833d73c4cd6957d24f4ab7abe7f3f363 (patch)
tree534bb89ea8de97646f281375a9597ba83e1f84ca /incoming
parenta7ca029c4d506f503f8119a23b4cf99916a10895 (diff)
downloadorg.eclipse.papyrus-1bd83a8f833d73c4cd6957d24f4ab7abe7f3f363.tar.gz
org.eclipse.papyrus-1bd83a8f833d73c4cd6957d24f4ab7abe7f3f363.tar.xz
org.eclipse.papyrus-1bd83a8f833d73c4cd6957d24f4ab7abe7f3f363.zip
NEW - bug 340430: [Widget] creation of dialog box based on the model explorer
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340430 C. Letavernier contribution.
Diffstat (limited to 'incoming')
-rw-r--r--incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/AdvancedMETreeDialog.java87
-rw-r--r--incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/ModelExplorerBasedTreeSelectorDialog.java67
-rw-r--r--incoming/org.eclipse.papyrus.uml.modelexplorer.widgets/src/org/eclipse/papyrus/uml/modelexplorer/widgets/UMLTreeSelectorDialog.java104
3 files changed, 181 insertions, 77 deletions
diff --git a/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/AdvancedMETreeDialog.java b/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/AdvancedMETreeDialog.java
index 52e45eaf7a0..44247bbac7d 100644
--- a/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/AdvancedMETreeDialog.java
+++ b/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/AdvancedMETreeDialog.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Added a lighter constructor
*
*****************************************************************************/
package org.eclipse.papyrus.modelexplorer.widgets;
@@ -22,7 +23,6 @@ import java.util.List;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -32,29 +32,51 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
/**
- * this dialog box has the possibility to select by the user interface the kind of wanted meta-class.
- *
+ * this dialog box has the possibility to select by the user interface the kind of wanted meta-class.
+ *
*/
public class AdvancedMETreeDialog extends ModelExplorerBasedTreeSelectorDialog {
- protected Label metaclassLabel=null;
+ protected Label metaclassLabel = null;
+
protected Combo combo;
+
protected EPackage metaModel;
- protected ArrayList<Object> metaclasses=new ArrayList<Object>();
+
+ protected ArrayList<Object> metaclasses = new ArrayList<Object>();
/**
*
* Constructor to display this dialog
- *
- * @param parentShell a shell
- * @param root the Eobject that will be the root of the Tree, it can be null
- * @param wantedEClass, in order to filter the tree by taking in account only this kind of object
- * @param metaClassNotWanted the list of not wanted object (to be pertinent, it has to be a subclass of wantedEclass
- * @param metaModel an Epackage that represent the domain model
+ *
+ * @param parentShell
+ * a shell
+ * @param root
+ * the Eobject that will be the root of the Tree, it can be null
+ * @param wantedEClass
+ * , in order to filter the tree by taking in account only this kind of object
+ * @param metaClassNotWanted
+ * the list of not wanted object (to be pertinent, it has to be a subclass of wantedEclass
+ * @param metaModel
+ * an Epackage that represent the domain model
*/
- public AdvancedMETreeDialog(Shell parentShell, EObject root, Object wantedEClass, List<Object> metaClassNotWanted,EPackage metaModel) {
+ public AdvancedMETreeDialog(Shell parentShell, EObject root, Object wantedEClass, List<Object> metaClassNotWanted, EPackage metaModel) {
super(parentShell, root, wantedEClass, metaClassNotWanted);
- this.metaModel=metaModel;
+ this.metaModel = metaModel;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * a shell
+ * @param metaModel
+ * an Epackage that represent the domain model
+ */
+ public AdvancedMETreeDialog(Shell parentShell, EPackage metaModel) {
+ super(parentShell);
+ this.metaModel = metaModel;
}
@Override
@@ -64,55 +86,64 @@ public class AdvancedMETreeDialog extends ModelExplorerBasedTreeSelectorDialog {
metaclassLabel = new Label(getDialogArea(), SWT.WRAP);
metaclassLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
metaclassLabel.setText("Metaclass:");
- setDescription("Look for "+ metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
+ setDescription("Look for " + metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
//install combo
combo = new Combo(getDialogArea(), SWT.NONE);
combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
combo.addSelectionListener(new SelectionListener() {
+
//creation of inner class for the selection
public void widgetSelected(SelectionEvent e) {
//look for the new wantedEClass
- int index=combo.getSelectionIndex();
+ int index = combo.getSelectionIndex();
contentProvider.setMetaClassWanted(metaclasses.get(index));
- setDescription("Look for "+metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
+ setDescription("Look for " + metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
contentProvider.setMetaClassNotWanted(new ArrayList<Object>());
- if(getViewer()!=null){
+ if(getViewer() != null) {
getViewer().refresh();
}
}
- public void widgetDefaultSelected(SelectionEvent e) {}
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
});
-
+
fillmetaclassList(metaModel);
fillMetaclassCombo(metaclasses, new EclassComparator());
getShell().pack();
}
+
/**
* Put into the list metaclasses all element from the Epackage
* border effect the list metaclasses is filled
- * @param ePackage that represent the domain model
+ *
+ * @param ePackage
+ * that represent the domain model
*/
- protected void fillmetaclassList(EPackage ePackage){
+ protected void fillmetaclassList(EPackage ePackage) {
metaclasses.clear();
for(Iterator<EObject> iterator = ePackage.eContents().iterator(); iterator.hasNext();) {
EObject type = iterator.next();
- if(type instanceof EClass){
- metaclasses.add(((EClass)type));
+ if(type instanceof EClass) {
+ metaclasses.add(type);
}
}
}
+
/**
* take in account all metaclasses and fill the combo by taking account order done by the comparator.
* Border effect: the variable combo is filled by all element contained in the parameter metaclasses
- * @param metaclasses the list of metaclasses
- * @param comparator a comparator
+ *
+ * @param metaclasses
+ * the list of metaclasses
+ * @param comparator
+ * a comparator
*/
- protected void fillMetaclassCombo( ArrayList<Object> metaclasses,Comparator<Object> comparator ){
- this.metaclasses=metaclasses;
+ protected void fillMetaclassCombo(ArrayList<Object> metaclasses, Comparator<Object> comparator) {
+ this.metaclasses = metaclasses;
//fill the list of meta-classes
combo.removeAll();
Collections.sort(metaclasses, comparator);
@@ -120,6 +151,6 @@ public class AdvancedMETreeDialog extends ModelExplorerBasedTreeSelectorDialog {
for(Iterator<Object> iterator = metaclasses.iterator(); iterator.hasNext();) {
combo.add(metaclassLabelProvider.getText(iterator.next()));
}
-
+
}
}
diff --git a/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/ModelExplorerBasedTreeSelectorDialog.java b/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/ModelExplorerBasedTreeSelectorDialog.java
index 4f422d392c3..44356421cc9 100644
--- a/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/ModelExplorerBasedTreeSelectorDialog.java
+++ b/incoming/org.eclipse.papyrus.modelexplorerbasedwidgets/src/org/eclipse/papyrus/modelexplorer/widgets/ModelExplorerBasedTreeSelectorDialog.java
@@ -9,13 +9,13 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Added a lighter constructor
*
*****************************************************************************/
package org.eclipse.papyrus.modelexplorer.widgets;
import java.util.List;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ViewerFilter;
@@ -26,18 +26,21 @@ import org.eclipse.papyrus.widgets.editors.TreeSelectorDialog;
import org.eclipse.swt.widgets.Shell;
/**
- * create a tree dialog box,with a specific researched meta-class. you can also specify the instance of the top element of your tree
- *
+ * create a tree dialog box,with a specific researched meta-class. you can also specify the instance of the top element of your tree
+ *
*/
public class ModelExplorerBasedTreeSelectorDialog extends TreeSelectorDialog {
protected EclassModelExplorerBasedContentProvider contentProvider;
- protected EObject root=null;
- protected LabelProvider metaclassLabelProvider= new MetaclassLabelProvider();
-
-
+
+ protected EObject root = null;
+
+ protected LabelProvider metaclassLabelProvider = new MetaclassLabelProvider();
+
+
/**
* get the label provider used to display metaclasses in the combo
+ *
* @return the label provider
*/
public LabelProvider getMetaclassLabelProvider() {
@@ -46,21 +49,54 @@ public class ModelExplorerBasedTreeSelectorDialog extends TreeSelectorDialog {
/**
* set the label provider that will display text in the combo that represent the available list of metaclasses
+ *
* @param metaclassLabelProvider
*/
public void setMetaclassLabelProvider(LabelProvider metaclassLabelProvider) {
this.metaclassLabelProvider = metaclassLabelProvider;
}
+
/**
- * constructor
+ *
+ * Constructor.
+ *
* @param parentShell
- * @param root the root of the tree , can be null
- * @param wantedEClass the meta-classes wanted, can be null
- * @param metaClassNotWanted, the list of sub meta-classes not wanted, can not be null
+ * a shell
+ * @param root
+ * the root of the tree , can be null
+ * @param wantedEClass
+ * the meta-classes wanted, can be null
+ * @param metaClassNotWanted
+ * , the list of sub meta-classes not wanted, can not be null
*/
public ModelExplorerBasedTreeSelectorDialog(Shell parentShell, EObject root, Object wantedEClass, List<Object> metaClassNotWanted) {
super(parentShell);
- this.root= root;
+ init(root, wantedEClass, metaClassNotWanted);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * a shell
+ */
+ public ModelExplorerBasedTreeSelectorDialog(Shell parentShell) {
+ super(parentShell);
+ }
+
+ /**
+ * Sets the preferences for initializing this Dialog's ContentProvider.
+ *
+ * @param root
+ * the root of the tree , can be null
+ * @param wantedEClass
+ * the meta-classes wanted, can be null
+ * @param metaClassNotWanted
+ * , the list of sub meta-classes not wanted, can not be null
+ */
+ public void init(EObject root, Object wantedEClass, List<Object> metaClassNotWanted) {
+ this.root = root;
contentProvider = new EclassModelExplorerBasedContentProvider(root);
contentProvider.setMetaClassWanted(wantedEClass);
contentProvider.setMetaClassNotWanted(metaClassNotWanted);
@@ -68,14 +104,15 @@ public class ModelExplorerBasedTreeSelectorDialog extends TreeSelectorDialog {
this.setLabelProvider(new MoDiscoLabelProviderWTooltips());
this.setInput(EditorUtils.getMultiDiagramEditor().getServicesRegistry());
}
+
@Override
public void create() {
// TODO Auto-generated method stub
super.create();
- setDescription("Look for "+metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
- ViewerFilter[] filters= { new HierarchicViewerFilter(contentProvider)};
+ setDescription("Look for " + metaclassLabelProvider.getText(contentProvider.getMetaClassWanted()));
+ ViewerFilter[] filters = { new HierarchicViewerFilter(contentProvider) };
getViewer().setFilters(filters);
-
+
Activator.getDefault().getCustomizationManager().installCustomPainter(getViewer().getTree());
}
}
diff --git a/incoming/org.eclipse.papyrus.uml.modelexplorer.widgets/src/org/eclipse/papyrus/uml/modelexplorer/widgets/UMLTreeSelectorDialog.java b/incoming/org.eclipse.papyrus.uml.modelexplorer.widgets/src/org/eclipse/papyrus/uml/modelexplorer/widgets/UMLTreeSelectorDialog.java
index 32968e14ef1..6b275a11bf2 100644
--- a/incoming/org.eclipse.papyrus.uml.modelexplorer.widgets/src/org/eclipse/papyrus/uml/modelexplorer/widgets/UMLTreeSelectorDialog.java
+++ b/incoming/org.eclipse.papyrus.uml.modelexplorer.widgets/src/org/eclipse/papyrus/uml/modelexplorer/widgets/UMLTreeSelectorDialog.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Added a lighter constructor
*
*****************************************************************************/
package org.eclipse.papyrus.uml.modelexplorer.widgets;
@@ -22,7 +23,6 @@ import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.core.services.ServiceException;
import org.eclipse.papyrus.core.services.ServicesRegistry;
import org.eclipse.papyrus.core.utils.EditorUtils;
import org.eclipse.papyrus.modelexplorer.widgets.AdvancedMETreeDialog;
@@ -46,77 +46,112 @@ import org.eclipse.uml2.uml.UMLPackage;
/**
* this dialog box display a Tree dialog by using the model explorer and propose to filter by taking in account metaclasses of UML, or
* stereotypes of applied profiles
- *
+ *
*/
public class UMLTreeSelectorDialog extends AdvancedMETreeDialog {
//display of UML domain model
protected static final String UML = "UML";
+
//the list of applied profiles
- protected HashSet<Profile> appliedProfiles=null;
+ protected HashSet<Profile> appliedProfiles = null;
+
//the combo that show metamodels and profiles
protected Combo comboMetamodel;
+
/**
*
* Constructor.
- *
- * @param parentShell a shell
- * @param root the root element that can be display at the top of the tree, can be null
- * @param wantedEClass the object use to filter in the tree all object that are instance of wantedEclasse
- * it can be stereotype of Eclass (can be null)
*
- * @param metaClassNotWanted list of not wanted metaclass or stereotypes (can be null)
+ * @param parentShell
+ * a shell
+ * @param root
+ * the root element that can be display at the top of the tree, can be null
+ * @param wantedEClass
+ * the object use to filter in the tree all object that are instance of wantedEclasse
+ * it can be stereotype of Eclass (can be null)
+ *
+ * @param metaClassNotWanted
+ * list of not wanted metaclass or stereotypes (can be null)
*/
public UMLTreeSelectorDialog(Shell parentShell, EObject root, EClass wantedEClass, List<Object> metaClassNotWanted) {
super(parentShell, root, wantedEClass, metaClassNotWanted, UMLPackage.eINSTANCE);
+ init(root, wantedEClass, metaClassNotWanted);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * a shell
+ */
+ public UMLTreeSelectorDialog(Shell parentShell) {
+ super(parentShell, UMLPackage.eINSTANCE);
+ }
+
+ /**
+ * Sets the preferences for initializing this Dialog's ContentProvider.
+ *
+ * @param root
+ * the root element that can be display at the top of the tree, can be null
+ * @param wantedEClass
+ * the object use to filter in the tree all object that are instance of wantedEclasse
+ * it can be stereotype of Eclass (can be null)
+ * @param metaClassNotWanted
+ * list of not wanted metaclass or stereotypes (can be null)
+ */
+ public void init(EObject root, EClass wantedEClass, List<Object> metaClassNotWanted) {
+ super.init(root, wantedEClass, metaClassNotWanted);
contentProvider = new UMLElementMEBContentProvider(root);
contentProvider.setMetaClassWanted(wantedEClass);
contentProvider.setMetaClassNotWanted(metaClassNotWanted);
- appliedProfiles=getAppliedProfile();
+ appliedProfiles = getAppliedProfile();
}
-
+
@Override
public void create() {
super.create();
//create the label
- Label metamodelLabel= new Label(getDialogArea(), SWT.WRAP);
+ Label metamodelLabel = new Label(getDialogArea(), SWT.WRAP);
metamodelLabel.setText("Metamodel:");
//create the combo
comboMetamodel = new Combo(getDialogArea(), SWT.NONE);
comboMetamodel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
+
//fill the combo for domain model
- final ArrayList<Profile> profiles= new ArrayList<Profile>();
+ final ArrayList<Profile> profiles = new ArrayList<Profile>();
profiles.addAll(appliedProfiles);
Collections.sort(profiles, new NamedElementComparator());
for(Iterator<Profile> iterator = profiles.iterator(); iterator.hasNext();) {
- Profile profile = (Profile)iterator.next();
+ Profile profile = iterator.next();
comboMetamodel.add(profile.getQualifiedName());
}
comboMetamodel.add(UML);
-
+
comboMetamodel.addSelectionListener(new SelectionListener() {
+
//creation of inner class for the selection
public void widgetSelected(SelectionEvent e) {
// a metamodel has been choosen, we have to update the list of metaclass or stereotypes
- int index=comboMetamodel.getSelectionIndex();
+ int index = comboMetamodel.getSelectionIndex();
//in the case of UML this is management by using EClass
- if( comboMetamodel.getItem(index).equals(UML)){
+ if(comboMetamodel.getItem(index).equals(UML)) {
fillmetaclassList(UMLPackage.eINSTANCE);
- setMetaclassLabelProvider( new MetaclassLabelProvider());
+ setMetaclassLabelProvider(new MetaclassLabelProvider());
fillMetaclassCombo(metaclasses, new EclassComparator());
- }
- else{
+ } else {
//in the case of profile, this a uml specific management due to stereotypes
- Profile selectedProfile= profiles.get(index);
- ArrayList<Object> stereotypesList= new ArrayList<Object>(selectedProfile.getOwnedStereotypes());
+ Profile selectedProfile = profiles.get(index);
+ ArrayList<Object> stereotypesList = new ArrayList<Object>(selectedProfile.getOwnedStereotypes());
setMetaclassLabelProvider(new StereotypeMetaclassLabelProvider());
fillMetaclassCombo(stereotypesList, new NamedElementComparator());
}
}
- public void widgetDefaultSelected(SelectionEvent e) {}
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
});
getShell().pack();
@@ -130,17 +165,17 @@ public class UMLTreeSelectorDialog extends AdvancedMETreeDialog {
* @throws ServiceException
*/
protected HashSet<Profile> getAppliedProfile() {
- HashSet<Profile> profileList= new HashSet<Profile>();
+ HashSet<Profile> profileList = new HashSet<Profile>();
//a root has been given.
- if( root!=null && root instanceof Package){
+ if(root != null && root instanceof Package) {
profileList.addAll(((Package)root).getAllAppliedProfiles());
return profileList;
}
//look for from contentprovider
- ServicesRegistry servicesRegistry = (ServicesRegistry)EditorUtils.getMultiDiagramEditor().getServicesRegistry();
- if( servicesRegistry!=null){
- UmlModel umlModel=null;
+ ServicesRegistry servicesRegistry = EditorUtils.getMultiDiagramEditor().getServicesRegistry();
+ if(servicesRegistry != null) {
+ UmlModel umlModel = null;
try {
ModelSet modelSet = ModelUtils.getModelSetChecked(servicesRegistry);
umlModel = (UmlUtils.getUmlModel(modelSet));
@@ -148,18 +183,19 @@ public class UMLTreeSelectorDialog extends AdvancedMETreeDialog {
} catch (Exception e) {
Activator.log.error("Cannot succeed to access to modelSet by using service Registry", e);
}
- if( umlModel == null)
+ if(umlModel == null) {
return profileList;
+ }
EList<EObject> contents = umlModel.getResource().getContents();
Iterator<EObject> iterator = contents.iterator();
- while (iterator.hasNext()) {
- EObject eObject = (EObject) iterator.next();
- if (eObject instanceof Package){
+ while(iterator.hasNext()) {
+ EObject eObject = iterator.next();
+ if(eObject instanceof Package) {
profileList.addAll(((Package)eObject).getAllAppliedProfiles());
}
}
}
- return profileList;
+ return profileList;
}
}

Back to the top