Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-10-18 09:35:15 +0000
committervlorenzo2012-10-18 09:35:15 +0000
commit43c3a8b16d2096eec9216a84850fcdfe05197b90 (patch)
tree002fa4f3fb7a7ec0db456e4905f50242117940da
parent06f8d178c6c515dbaedf05a26f58563ad293ca93 (diff)
downloadorg.eclipse.papyrus-43c3a8b16d2096eec9216a84850fcdfe05197b90.tar.gz
org.eclipse.papyrus-43c3a8b16d2096eec9216a84850fcdfe05197b90.tar.xz
org.eclipse.papyrus-43c3a8b16d2096eec9216a84850fcdfe05197b90.zip
389601: [Table] Papyrus should provides an easy way to edit the properties of the stereotypes using a Dialog Show/Hide columns
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389601 A save of my work -> works fine for UML Primitive Type
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF5
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml2
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java65
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java322
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToShowDialog.java384
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/Constants.java17
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/EcoreENamedElementComparator.java14
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java423
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetOperationUtils.java230
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FilteredCheckboxTree.java456
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java617
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java69
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/StereotypeManagement.java51
13 files changed, 1883 insertions, 772 deletions
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF
index c3869ecc38e..e2d68056628 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF
@@ -19,6 +19,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
org.eclipse.emf.facet.widgets.celleditors.ecore;bundle-version="0.2.1",
- org.eclipse.emf.facet.efacet.core
+ org.eclipse.emf.facet.efacet.core,
+ org.eclipse.papyrus.uml.tools;bundle-version="0.9.1",
+ org.eclipse.papyrus.uml.tools.utils,
+ org.eclipse.papyrus.uml.umlefacet.metamodel;bundle-version="0.9.2"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml
index 210ca285d87..c363cecf8ee 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml
@@ -18,7 +18,7 @@
locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="org.eclipse.papyrus.infra.table.efacet.menu.command.select.columns"
- label="Select Columns"
+ label="Select Columns To Show"
style="push"
tooltip="Select the columns to display">
</command>
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java
index 994fb134fb9..6e522d3f108 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2012 CEA LIST.
*
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,7 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.table.efacet.menu.factory;
@@ -21,6 +21,7 @@ import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.ETypedElement;
@@ -55,30 +56,44 @@ import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetInte
//EMF-Facet should provides a best way to hide columns
public final class TableInstanceCommandFactory {
- public static Command createShowHideColumnCommand(final ITableWidgetInternal widgetController,final EditingDomain editingDomain, ICommandFactory commandFactory, final Table table, final List<Column> columnsToShow, final List<Column> columnsToHide, final boolean putOnTheTop) {
- CompoundCommand compoundCommand = new CompoundCommand("Show/hide column"); //$NON-NLS-1$
+ public static Command createShowHideColumnCommand(final ITableWidgetInternal widgetController,final EditingDomain editingDomain, final ICommandFactory commandFactory, final Table table, final List<Column> columnsToShow, final List<Column> columnsToHide, final boolean putOnTheTop) {
+ final CompoundCommand compoundCommand = new CompoundCommand("Show/hide column"); //$NON-NLS-1$
- for(Column current : columnsToShow) {
+ for(final Column current : columnsToShow) {
if(current instanceof SourceColumn) {
- Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.FALSE);
+ final Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.FALSE);
if(cmd.canExecute()) {
compoundCommand.append(cmd);
}
}
}
// HashSet<FeatureColumn> fColumnsToHide = new HashSet<FeatureColumn>();
- HashSet<ETypedElement> featureToHide = new HashSet<ETypedElement>();
- for(Column current : columnsToHide) {
+ final HashSet<ETypedElement> featureToHide = new HashSet<ETypedElement>();
+ for(final Column current : columnsToHide) {
if(current instanceof FeatureColumn) {
// fColumnsToHide.add((FeatureColumn)current);
featureToHide.add(((FeatureColumn)current).getFeature());
} else {
- Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.TRUE);
+ final Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.TRUE);
compoundCommand.append(cmd);
}
}
- Command tmp = createHideColumnCommand(widgetController,editingDomain, table,featureToHide);
-
+
+ final EList<Column> currentColumns = table.getColumns();
+ final List<Column> toHide2 = new ArrayList<Column>(currentColumns);
+ toHide2.removeAll(columnsToHide);
+ toHide2.removeAll(columnsToShow);
+ final List<Column> visibleColumns = widgetController.getVisibleColumns(false);
+ for(final Column col : toHide2) {
+ if(visibleColumns.contains(col)) {
+ columnsToShow.add(col);
+ } else if(col instanceof FeatureColumn) {
+ featureToHide.add(((FeatureColumn)col).getFeature());
+ }
+ }
+
+ final Command tmp = createHideColumnCommand(widgetController,editingDomain, table,featureToHide);
+
if(tmp != null) {
compoundCommand.append(tmp);
}
@@ -107,14 +122,14 @@ public final class TableInstanceCommandFactory {
//}
-
+
private TableInstanceCommandFactory() {
// Prevents instantiation
}
/**
* This method retruns an EMF command deleting the a collection of EObject
- *
+ *
* @param label
* This label will be visible in the menu 'Edit'.
* @param eObjects
@@ -122,9 +137,9 @@ public final class TableInstanceCommandFactory {
* @return
*/
public static Command delete(final String label, final Collection<? extends EObject> eObjects, final EditingDomain domain, final ICommandFactory factory) {
- List<Command> cmdList = new ArrayList<Command>();
- for(EObject eObject : eObjects) {
- Command command = factory.createDeleteCommand(domain, eObject);
+ final List<Command> cmdList = new ArrayList<Command>();
+ for(final EObject eObject : eObjects) {
+ final Command command = factory.createDeleteCommand(domain, eObject);
cmdList.add(command);
}
Command result = null;
@@ -136,13 +151,13 @@ public final class TableInstanceCommandFactory {
/**
* This method create a command deleting use less row and columns.
- *
+ *
* @param controller
* @return null if no action has to be performed.
*/
public static final Command createRemoveUselessRowsAndColumnsCommand(final EditingDomain domain, final ICommandFactory factory, final Table table) {
- List<Command> cmdList = new ArrayList<Command>();
- List<Row> rowsToRemove = TableInstanceUtils.findUselessRow(table);
+ final List<Command> cmdList = new ArrayList<Command>();
+ final List<Row> rowsToRemove = TableInstanceUtils.findUselessRow(table);
// if(TableWidgetController.DEBUG_REMOVE_USELESS_ROWS_AND_COLUMNS) {
// DebugUtils.debug("Rows to be removed: " + rowsToRemove.size()); //$NON-NLS-1$
// }
@@ -168,7 +183,7 @@ public final class TableInstanceCommandFactory {
}
/**
- *
+ *
* @param column
* a column
* @param isHidden
@@ -208,7 +223,7 @@ public final class TableInstanceCommandFactory {
IsOneOfQuery conformanceQuery;
if(typeCustomization == null) {
conformanceQuery = QueryFactory.eINSTANCE.createIsOneOfQuery();
- ICommandFactoryResult<EClassCustomization> createEClassCustom = customCmdFactory.createEClassCustomization(customization, EcorePackage.eINSTANCE.getETypedElement(), conformanceQuery);
+ final ICommandFactoryResult<EClassCustomization> createEClassCustom = customCmdFactory.createEClassCustomization(customization, EcorePackage.eINSTANCE.getETypedElement(), conformanceQuery);
typeCustomization = createEClassCustom.getResult();
resultCmd.append(createEClassCustom.getCommand());
} else {
@@ -216,7 +231,7 @@ public final class TableInstanceCommandFactory {
// throw new TableWidgetRuntimeException("Unexpected type for the variable 'featureContainer'"); //$NON-NLS-1$
//TODO
}
- DerivedTypedElement conformanceTE = (DerivedTypedElement)typeCustomization.getConformanceTypedElement();
+ final DerivedTypedElement conformanceTE = (DerivedTypedElement)typeCustomization.getConformanceTypedElement();
conformanceQuery = (IsOneOfQuery)conformanceTE.getQuery();
}
// final HashSet<ETypedElement> featuresToHide = new HashSet<ETypedElement>();
@@ -263,7 +278,7 @@ public final class TableInstanceCommandFactory {
// /**
// * This method retruns an EMF command deleting the a collection of EObject
- // *
+ // *
// * @param label
// * This label will be visible in the menu 'Edit'.
// * @param eObjects
@@ -285,7 +300,7 @@ public final class TableInstanceCommandFactory {
//
// /**
// * This method create a command deleting use less row and columns.
- // *
+ // *
// * @param controller
// * @return null if no action has to be performed.
// */
@@ -316,7 +331,7 @@ public final class TableInstanceCommandFactory {
private static class CommandList extends LinkedList<Command> {
/**
- *
+ *
*/
private static final long serialVersionUID = 4393120485370832319L;
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java
deleted file mode 100644
index 3105880d84a..00000000000
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Gregoire Dupe (Mia-Software) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
- * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
- * Nicolas Bros (Mia-Software) - Bug 344247 - illegal API use in org.eclipse.emf.facet.widgets.nattable.internal.dialogs.ColumnsToHideDialog
- * Gregoire Dupe (Mia-Software) - Bug 366804 - [Restructuring] Table widget upgrade
- *****************************************************************************/
-package org.eclipse.papyrus.infra.table.efacet.menu.handler;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.ETypedElement;
-import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
-
-//import org.eclipse.emf.facet.widgets.table.ui.internal.comparator.ColumnComparator;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.SelectionDialog;
-
-public class ColumnsToHideDialog extends SelectionDialog {
-
- // private final Object inputElement;
- private final ILabelProvider labelProvider;
-
- private final SortedColumnContentProvider contentProvider;
-
- private CheckboxTreeViewer listViewer;
-
- //
- // private static final int DIALOG_WIDTH = 300;
- // private static final int DIALOG_HEIGHT = 300;
- //
- // /** indicates if the local customization files should be set at the top */
- // private boolean setAtTheTop;
- //
- // /** the initial selection */
- // private List<Column> initialSelection;
- //
- // private final boolean askToPutOnTheTopTheLocalCustomization;Z
- //
- // private boolean mustAskTheUserNextTime;
- //
- // private PutOnTheTopQuestionDialog putOnTheTopQuestionDialog;
-
- private final Collection<EObject> input;
-
- private final Collection<ETypedElement> initialSelection;
-
- public ColumnsToHideDialog(final Shell parentShell, final Collection<EObject> classifiers, final Collection<ETypedElement> initialSelection, final ILabelProvider labelProvider) {
- super(parentShell);
- setTitle("Select the columns to show");
- this.input = classifiers;
- this.labelProvider = labelProvider;
- this.contentProvider = new SortedColumnContentProvider();
- this.initialSelection = initialSelection;
- }
-
- // /**
- // * Visually checks the previously-specified elements in this dialog's list
- // * viewer.
- // */
- // private void checkInitialSelections() {
- // Iterator<?> itemsToCheck = getInitialElementSelections().iterator();
- //
- // while(itemsToCheck.hasNext()) {
- // this.listViewer.setChecked(itemsToCheck.next(), true);
- // }
- // }
-
- @Override
- protected void configureShell(final Shell shell) {
- super.configureShell(shell);
- // shell.setImage(ImageProvider.getInstance().getSelectColumnsToHide());
- }
-
- @Override
- protected Control createDialogArea(final Composite parent) {
- // page group
- Composite composite = (Composite)super.createDialogArea(parent);
-
- initializeDialogUnits(composite);
-
- createMessageArea(composite);
-
- this.listViewer = new CheckboxTreeViewer(composite, 0);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.heightHint = 300;
- // data.widthHint = ColumnsToHideDialog.DIALOG_WIDTH;
- this.listViewer.getTree().setLayoutData(data);
-
- this.listViewer.setLabelProvider(this.labelProvider);
- this.listViewer.setContentProvider(this.contentProvider);
-
- // addSelectionButtons(composite);
-
- this.listViewer.setInput(input);
- this.listViewer.setCheckedElements((this.initialSelection.toArray()));
- this.listViewer.expandAll();
- // initialize page
- // if(!getInitialElementSelections().isEmpty()) {
- // // checkInitialSelections();
- // }
-
- // this checkbox allows sorting the columns by name
- // final Button cbSort = new Button(composite, SWT.CHECK);
- // cbSort.setText("Sort Columns By Name"); //$NON-NLS-1$ // TODO should be externalized
- // cbSort.pack();
- // cbSort.addSelectionListener(new SelectionAdapter() {
- //
- // @Override
- // public void widgetSelected(final SelectionEvent e) {
- // ColumnsToHideDialog.this.contentProvider.setIsSorted(cbSort.getSelection());
- // getViewer().refresh();
- // }
- // });
- Dialog.applyDialogFont(composite);
- return composite;
-
- }
-
- /**
- * Returns the viewer used to show the list.
- *
- * @return the viewer, or <code>null</code> if not yet created
- */
- protected CheckboxTreeViewer getViewer() {
- return this.listViewer;
- }
-
- //
- // /** Add the selection and deselection buttons to the dialog. */
- // private void addSelectionButtons(final Composite composite) {
- // Composite buttonComposite = new Composite(composite, SWT.NONE);
- // GridLayout layout = new GridLayout();
- // layout.numColumns = 0;
- // layout.marginWidth = 0;
- // layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- // buttonComposite.setLayout(layout);
- // buttonComposite.setLayoutData(new GridData(SWT.END, SWT.TOP, true, false));
- //
- // Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, "&Select All", false); //$NON-NLS-1$ // TODO should be externalized
- //
- // SelectionListener listener = new SelectionAdapter() {
- //
- // @Override
- // public void widgetSelected(final SelectionEvent e) {
- // selectAll();
- // }
- // };
- // selectButton.addSelectionListener(listener);
- //
- // Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, "&Deselect All", false); //$NON-NLS-1$ // TODO should be externalized
- //
- // listener = new SelectionAdapter() {
- //
- // @Override
- // public void widgetSelected(final SelectionEvent e) {
- // deselectAll();
- // }
- // };
- // deselectButton.addSelectionListener(listener);
- // }
-
- /**
- *
- * @see org.eclipse.jface.window.Window#open()
- *
- * @return
- */
- @Override
- public int open() {
- // if(this.askToPutOnTheTopTheLocalCustomization) {
- // this.putOnTheTopQuestionDialog = openPutOnTheTopQuestionDialog();
- // }
- // this.initialSelection = getVisibleColumns(this.setAtTheTop);
- // setInitialElementSelections(this.initialSelection);
- return super.open();
- }
-
- // /**
- // *
- // * @return <ul>
- // * <li>IDialogConstants.NO_ID</li>
- // * <li>IDialogConstants.YES_ID</li>
- // * <li><code>-1<code> in other cases</li>
- // * </ul>
- // */
- // private PutOnTheTopQuestionDialog openPutOnTheTopQuestionDialog() {
- // String message = TableWidgetPreferencePage.DISPLAYED_MESSAGE_1 + " " + TableWidgetPreferencePage.DISPLAYED_MESSAGE_2 + "\n\n" + TableWidgetPreferencePage.DISPLAYED_QUESTION; //$NON-NLS-1$//$NON-NLS-2$
- // String toggleMessage = TableWidgetPreferencePage.DONT_DISPLAY_NEXT_TIME;
- // final PutOnTheTopQuestionDialog dialog = new PutOnTheTopQuestionDialog(getShell(), Messages.NatTableWidget_selectColumnToShowHide, ImageProvider.getInstance().getSelectColumnsToHide(), message, MessageDialog.WARNING, new String[]{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, toggleMessage, false) {
- //
- // @Override
- // public boolean close() {
- // ColumnsToHideDialog.this.setAtTheTop = isPutOnTheTop();
- // ColumnsToHideDialog.this.mustAskTheUserNextTime = this.isAskTheUserNextTime();
- // return super.close();
- // }
- // };
- // Display.getDefault().asyncExec(new Runnable() {
- //
- // public void run() {
- // dialog.open();
- // }
- // });
- // return dialog;
- // }
-
- // public boolean isPutOnTheTop() {
- // return this.setAtTheTop;
- // }
-
- // /**
- // *
- // * @see org.eclipse.emf.facet.widgets.nattable.internal.IColumnsToHideDialog#getInitialSelection()
- // *
- // * @return the initial selection
- // */
- // public List<Column> getInitialSelection() {
- // return this.initialSelection;
- // }
- //
- // public IPutOnTheTopQuestionDialog isPutOnTheTopQuestionDialog() {
- // return this.putOnTheTopQuestionDialog;
- // }
-
- public void pressOk() {
- okPressed();
- }
-
- // public abstract List<Column> getVisibleColumns(boolean putOnTheTop);
-
- public List<Column> getSelectedColumns() {
- List<Column> resultList = new ArrayList<Column>();
- for(Object result : getResult()) {
- if(result instanceof Column) {
- Column column = (Column)result;
- resultList.add(column);
- }
- }
- return resultList;
- }
-
- // public boolean isMustAskTheUserNextTime() {
- // return this.mustAskTheUserNextTime;
- // }
-
- public void selectAll() {
- getViewer().setAllChecked(true);
- }
-
- public void deselectAll() {
- getViewer().setAllChecked(false);
- }
-
- /**
- * The <code>ListSelectionDialog</code> implementation of this <code>Dialog</code> method builds a list of the selected elements for
- * later retrieval by the client and closes this dialog.
- */
- @Override
- protected void okPressed() {
- setResult(Arrays.asList(this.listViewer.getCheckedElements()));
- // // Get the input children.
- // Object[] children = this.contentProvider.getElements(this.inputElement);
- //
- // // Build a list of selected children.
- // if(children != null) {
- // ArrayList<Object> list = new ArrayList<Object>();
- // for(int i = 0; i < children.length; ++i) {
- // Object element = children[i];
- // if(this.listViewer.getChecked(element)) {
- // list.add(element);
- // }
- // }
- // setResult(list);
- // }
-
- super.okPressed();
- }
-
- // public IPutOnTheTopQuestionDialog getPutOnTheTopQuestionDialog() {
- // return this.putOnTheTopQuestionDialog;
- // }
-}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToShowDialog.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToShowDialog.java
new file mode 100644
index 00000000000..9ea0802cf45
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToShowDialog.java
@@ -0,0 +1,384 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+
+public class ColumnsToShowDialog extends SelectionDialog {
+
+ /** the label provider used by the tree viewer */
+ private final ILabelProvider labelProvider;
+
+ /** the content provider used by the tree viewer */
+ private final IContentProvider contentProvider;
+
+ /** the with of the dialog */
+ private static final int DIALOG_WIDTH = 1000;
+
+ /** the height of the dialog */
+ private static final int DIALOG_HEIGHT = 600;
+
+ /** the direct features */
+ private final Collection<ETypedElement> directFeatures;
+
+ /** the additional features */
+ private final Collection<ENamedElement> additionalFeatures;
+
+ /** the initial selection */
+ private final Collection<ETypedElement> initialSelection;
+
+ /** the tree used to display the direct features */
+ private FilteredTree directFeaturesTree;
+
+ /** the tree used to display the additional features */
+ private FilteredTree additionnalFeaturesTree;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parentShell
+ * the parent shell
+ * @param features
+ * the direct features
+ * @param additionalFeatures
+ * the additional features (FacetSet, Facets or ETypedElement)
+ * @param initialSelection
+ * the initial selection
+ * @param labelProvider
+ * the label provider used by the viewers
+ * @param contentProvider
+ * the content provider used by the viewers
+ */
+ public ColumnsToShowDialog(final Shell parentShell, final Collection<ETypedElement> features, final Collection<ENamedElement> additionalFeatures, final Collection<ETypedElement> initialSelection, final ILabelProvider labelProvider, final IContentProvider contentProvider) {
+ super(parentShell);
+ setTitle("Select the columns to show");
+ this.directFeatures = features;
+ this.additionalFeatures = additionalFeatures;
+ this.labelProvider = labelProvider;
+ this.contentProvider = contentProvider;
+ this.initialSelection = initialSelection;
+ }
+
+ @Override
+ public void create() {
+ super.create();
+
+ final Composite parent = (Composite)getDialogArea();
+ final GridLayout layout = (GridLayout)parent.getLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = true;
+
+ final Composite selectorPane = new Composite(parent, SWT.NONE);
+ selectorPane.setLayout(new GridLayout(2, false));
+ selectorPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ final Composite selectedPane = new Composite(parent, SWT.NONE);
+ selectedPane.setLayout(new GridLayout(2, false));
+ selectedPane.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ createDirectFeaturesSection(selectorPane);
+ createAdditionalFeaturesSection(selectedPane);
+
+ getShell().setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
+ getShell().layout();
+
+ //TODO
+ // super.getShell().setImage(Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @param parent
+ * the parent of the button panel
+ * @return
+ * the composite used as parent for the buttons
+ */
+ protected Composite createButtonPanel(final Composite parent) {
+ final Composite buttonsPanel = new Composite(parent, SWT.NONE);
+ final GridLayout buttonPanelLayout = new GridLayout(2, true);
+ buttonPanelLayout.marginWidth = 0;
+ buttonPanelLayout.marginHeight = 0;
+ buttonsPanel.setLayout(buttonPanelLayout);
+ buttonsPanel.setLayoutData(new GridData(SWT.END, SWT.FILL, false, false));
+ return buttonsPanel;
+ }
+
+ /**
+ * Create the direct features section
+ *
+ * @param parent
+ * crate the feature section
+ *
+ */
+ protected void createDirectFeaturesSection(final Composite parent) {
+ //1. create the composite used for this section
+ final Composite featureComposite = new Composite(parent, SWT.BORDER);
+ featureComposite.setLayout(new GridLayout(1, false));
+ featureComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ //2. create the label of the section
+ final Label label = new Label(featureComposite, SWT.NONE);
+ label.setText("Direct Features");
+
+ //3. create the tree
+ this.directFeaturesTree = new FilteredCheckboxTree(featureComposite, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK, new PatternFilter());
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(this.directFeaturesTree);
+
+ this.directFeaturesTree.getViewer().setLabelProvider(this.labelProvider);
+ this.directFeaturesTree.getViewer().setContentProvider(this.contentProvider);
+ this.directFeaturesTree.getViewer().setInput(this.directFeatures);
+
+ //3.bis set the initial selection
+ ((ContainerCheckedTreeViewer)this.directFeaturesTree.getViewer()).setCheckedElements(this.initialSelection.toArray());
+
+ //4. create the buttons select all and deselect all
+ final Composite buttonsPanel = createButtonPanel(featureComposite);
+ final Button selectAllFeaturesButton = new Button(buttonsPanel, SWT.NONE);
+ selectAllFeaturesButton.setText("Select All");
+ selectAllFeaturesButton.setToolTipText("Select all available features.");
+ selectAllFeaturesButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ selectAllFeaturesButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(final SelectionEvent e) {
+ selectAllDirectFeatures();
+ }
+
+ public void widgetDefaultSelected(final SelectionEvent e) {
+ //nothing to do
+ }
+ });
+
+ final Button deselectAllFeaturesButton = new Button(buttonsPanel, SWT.NONE);
+ deselectAllFeaturesButton.setText("Deselect All");
+ deselectAllFeaturesButton.setToolTipText("Deselect all available features.");
+ deselectAllFeaturesButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ deselectAllFeaturesButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(final SelectionEvent e) {
+ deselectAllDirectFeatures();
+ }
+
+ public void widgetDefaultSelected(final SelectionEvent e) {
+ //nothing to do
+ }
+ });
+
+ }
+
+
+
+ protected void createAdditionalFeaturesSection(final Composite facetPane) {
+ //1. create the composite used for this section
+ final Composite facetComposite = new Composite(facetPane, SWT.BORDER);
+ facetComposite.setLayout(new GridLayout(1, true));
+ facetComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ //2. create the label for this section
+ final Label label = new Label(facetComposite, SWT.NONE);
+ label.setText("Additional Features");
+
+ //3. create the tree for this section
+ this.additionnalFeaturesTree = new FilteredCheckboxTree(facetComposite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK, new PatternFilter());//, true);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(this.additionnalFeaturesTree);
+ this.additionnalFeaturesTree.getViewer().expandAll();
+ this.additionnalFeaturesTree.getViewer().setLabelProvider(this.labelProvider);
+ this.additionnalFeaturesTree.getViewer().setContentProvider(this.contentProvider);
+ this.additionnalFeaturesTree.getViewer().setInput(this.additionalFeatures);
+ this.additionnalFeaturesTree.getViewer().expandAll();
+ ((ContainerCheckedTreeViewer)this.additionnalFeaturesTree.getViewer()).setCheckedElements(this.initialSelection.toArray());
+
+ //4. create the buttons select all and deselect all
+ final Composite buttonsPanel = createButtonPanel(facetComposite);
+ final Button selectAllAdditionalFeaturesButton = new Button(buttonsPanel, SWT.NONE);
+ selectAllAdditionalFeaturesButton.setText("Select All");
+ selectAllAdditionalFeaturesButton.setToolTipText("Select all available additional features.");
+ selectAllAdditionalFeaturesButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ selectAllAdditionalFeaturesButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(final SelectionEvent e) {
+ selectAllAdditionalFeatures();
+ }
+
+ public void widgetDefaultSelected(final SelectionEvent e) {
+ //nothing to do
+ }
+ });
+
+ final Button deselectAllAdditionalFeaturesButton = new Button(buttonsPanel, SWT.NONE);
+ deselectAllAdditionalFeaturesButton.setText("Deselect All");
+ deselectAllAdditionalFeaturesButton.setToolTipText("Deselect all available additional features.");
+ deselectAllAdditionalFeaturesButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ deselectAllAdditionalFeaturesButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(final SelectionEvent e) {
+ deselectAllAdditionalFeatures();
+ }
+
+ public void widgetDefaultSelected(final SelectionEvent e) {
+ //nothing to do
+ }
+ });
+ }
+
+
+
+ /**
+ * select all additional features
+ */
+ protected void selectAllAdditionalFeatures() {
+ final ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer)this.additionnalFeaturesTree.getViewer();
+ for(final Object current : this.additionalFeatures) {
+ viewer.setSubtreeChecked(current, true);
+ }
+ }
+
+ /**
+ * deselect all additional features
+ */
+ protected void deselectAllAdditionalFeatures() {
+ final ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer)this.additionnalFeaturesTree.getViewer();
+ for(final Object current : this.additionalFeatures) {
+ viewer.setSubtreeChecked(current, false);
+ }
+ }
+
+ /**
+ * select all direct features
+ */
+ protected void selectAllDirectFeatures() {
+ final ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer)this.directFeaturesTree.getViewer();
+ for(final Object current : this.directFeatures) {
+ viewer.setSubtreeChecked(current, true);
+ }
+ }
+
+ /**
+ * deselect all direct features
+ */
+ protected void deselectAllDirectFeatures() {
+ final ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer)this.directFeaturesTree.getViewer();
+ for(final Object current : this.directFeatures) {
+ viewer.setSubtreeChecked(current, false);
+ }
+ }
+
+ public void pressOk() {
+ okPressed();
+ }
+
+ /**
+ * The <code>ListSelectionDialog</code> implementation of this <code>Dialog</code> method builds a list of the selected elements for
+ * later retrieval by the client and closes this dialog.
+ */
+ @Override
+ protected void okPressed() {
+ final Collection<ETypedElement> selectedFeatures = getAllChechedElements(this.directFeaturesTree);
+ final Collection<ETypedElement> selectedAdditionalFeatures = getAllChechedElements(this.additionnalFeaturesTree);
+
+ final List<Collection<ETypedElement>> result = new ArrayList<Collection<ETypedElement>>();
+ result.add(selectedFeatures);
+ result.add(selectedAdditionalFeatures);
+ setResult(result);
+ super.okPressed();
+ }
+
+ /**
+ *
+ * @param tree
+ * a tree
+ * @return
+ * all items checked ignoring grayed elements
+ */
+ protected Collection<ETypedElement> getAllChechedElements(final FilteredTree tree) {
+ final Collection<ETypedElement> checkedElements = new HashSet<ETypedElement>();
+ final TreeViewer viewer = tree.getViewer();
+ final TreeItem[] items = viewer.getTree().getItems();
+ for(final TreeItem treeItem : items) {
+ if(treeItem.getChecked()) {
+ final Object data = treeItem.getData();
+ if(data instanceof ETypedElement) {
+ checkedElements.add((ETypedElement)data);
+ }
+ }
+ if(treeItem.getChecked() || treeItem.getGrayed()) {
+ checkedElements.addAll(getAllCheckedSubItems(treeItem));
+ }
+ }
+ return checkedElements;
+ }
+
+ /**
+ *
+ * @param item
+ * a item
+ * @return
+ * all sub items checked ignoring grayed items
+ */
+ protected Collection<ETypedElement> getAllCheckedSubItems(final TreeItem item) {
+ final Collection<ETypedElement> checkedElements = new HashSet<ETypedElement>();
+ for(final TreeItem current : item.getItems()) {
+ if(current.getGrayed()) {
+
+ } else if(current.getChecked()) {
+ final Object data = current.getData();
+ if(data instanceof ETypedElement) {
+ checkedElements.add((ETypedElement)data);
+ }
+ }
+ checkedElements.addAll(getAllCheckedSubItems(current));
+ }
+
+ return checkedElements;
+ }
+
+ /**
+ *
+ *
+ * @return
+ * the result of the dialog :
+ * an array of 2 List<ETypeElement> : the first list contains the direct features selected and the second one contains the additional
+ * features
+ */
+ @Override
+ public Object[] getResult() {
+ //overriden only for the documentation of the methods
+ return super.getResult();
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/Constants.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/Constants.java
new file mode 100644
index 00000000000..90b660e8650
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/Constants.java
@@ -0,0 +1,17 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+//TODO merge with the same class in oep.uml.efacet
+public class Constants {
+
+
+ private Constants() {
+ //to prevent instanciation
+ }
+
+ public static final String STEREOTYPE_QUALIFIED_NAME = "stereotypeQualifiedName";
+ public static final String STEREOTYPE_PROPERTY_NAME = "stereotypePropertyName";
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/EcoreENamedElementComparator.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/EcoreENamedElementComparator.java
new file mode 100644
index 00000000000..68f74f01e9e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/EcoreENamedElementComparator.java
@@ -0,0 +1,14 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.Comparator;
+
+import org.eclipse.emf.ecore.ENamedElement;
+
+
+public class EcoreENamedElementComparator implements Comparator<ENamedElement> {
+
+ public int compare(final ENamedElement o1, final ENamedElement o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java
index 31224c33ba4..805eefea3fb 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java
@@ -1,34 +1,35 @@
package org.eclipse.papyrus.infra.table.efacet.menu.handler;
-import java.io.ObjectInputStream.GetField;
+import java.util.ArrayList;
+import java.util.Collection;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManager;
-import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
-import org.eclipse.emf.facet.efacet.core.exception.FacetManagerException;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetFactory;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetAttribute;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetReference;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.EObjectLiteralQuery;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.OperationCallQuery;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryFactory;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.StringLiteralQuery;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacetcatalog.EfacetcatalogFactory;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.ProfileFacetSet;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.StereotypeFacet;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.StereotypePropertyFacetAttribute;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.StereotypePropertyFacetReference;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.UmlEFacetFactory;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.emf.facet.efacet.core.*;
public class FacetFactory {
@@ -37,8 +38,18 @@ public class FacetFactory {
//to prevent instanciation
}
+ public static final String UML_BOOLEAN = "Boolean";
+
+ public static final String UML_INTEGER = "Integer";
+
+ public static final String UML_STRING = "String";
+
+ public static final String UML_REAL = "Real";
+
+ public static final String UML_UNLIMITED_NATURAL = "UnlimitedNatural";
+
public static final FacetSet createFacetSet(final String name, final String nsPrefix, final String nsURI, final String documentation) {
- FacetSet set = EFacetFactory.eINSTANCE.createFacetSet();
+ final FacetSet set = EFacetFactory.eINSTANCE.createFacetSet();
set.setName(name);
set.setNsPrefix(nsPrefix);
set.setNsURI(nsURI);
@@ -46,217 +57,231 @@ public class FacetFactory {
return set;
}
- public static final Facet createFacet(final Stereotype stereotype) {
- Facet facet = EFacetFactory.eINSTANCE.createFacet();
+ /**
+ *
+ * @param profile
+ * @return
+ * the ProfileFacetSet for this profile or <code>null</code> if the profile argument doesn't contains steretoypes with properties
+ */
+ public static final ProfileFacetSet createProfileFacetSet(final Profile profile) {
+ final ProfileFacetSet set = UmlEFacetFactory.eINSTANCE.createProfileFacetSet();
+ set.setName(profile.getName());
+ set.setProfileQualifiedName(profile.getQualifiedName());
+ profile.getPackagedElements();
+ for(final PackageableElement packagedElement : profile.getPackagedElements()) {
+ if(packagedElement instanceof Profile) {
+ final ProfileFacetSet subProfile = createProfileFacetSet((Profile)packagedElement);
+ //We ignore empty facetSet
+ if(subProfile != null && (subProfile.getEClassifiers().size() != 0 || subProfile.getESubpackages().size() != 0)) {
+ set.getESubpackages().add(subProfile);
+ }
+ } else if(packagedElement instanceof Stereotype) {
+ //TODO and inherited properties
+ //we ignore stereotypes without properties
+ final StereotypeFacet stereotypeFacet = createFacet((Stereotype)packagedElement);
+ if(stereotypeFacet.getFacetElements().size() != 0) {
+ set.getEClassifiers().add(stereotypeFacet);
+ }
+ }
+ }
+
+ //TODO
+ // set.setNsPrefix(nsPrefix);
+ // set.setNsURI(nsURI);
+ // set.setDocumentation(documentation);
+
+ if(set.getEClassifiers().size() != 0 || set.getESubpackages().size() != 0) {
+ return set;
+ }
+ return null;
+
+ }
+
+ public static final StereotypeFacet createFacet(final Stereotype stereotype) {
+ final StereotypeFacet facet = UmlEFacetFactory.eINSTANCE.createStereotypeFacet();
+ facet.setStereotypeQualifiedName(stereotype.getQualifiedName());
facet.setName(stereotype.getName());
facet.setDocumentation("This facet represents the eClass " + stereotype.getName());
// facet.setConformanceTypedElement(value);//TODO
facet.setExtendedMetaclass(UMLPackage.eINSTANCE.getElement());//TODO
+ //TODO and inherited properties?
+ final Collection<String> ignoredPropertyName = new ArrayList<String>();
+
+ final String BASE_ = "base_"; //TODO move it in another plugin!
+ for(final Class tutu : stereotype.getExtendedMetaclasses()) {
+ ignoredPropertyName.add(BASE_ + tutu.getName());
+ }
for(final Property attribute : stereotype.getOwnedAttributes()) {
- FacetAttribute facetAttr = createFacetAttribute2(attribute, stereotype);
- facet.getFacetElements().add(facetAttr);
+ if(ignoredPropertyName.contains(attribute.getName())) {
+ continue;
+ }
+ if(attribute.getType() instanceof DataType) {
+ final StereotypePropertyFacetAttribute facetAttr = createFacetAttribute(attribute, stereotype);
+ facet.getFacetElements().add(facetAttr);
+ } else if(attribute.getType() instanceof Element) {//or EObject TODO ?
+ final StereotypePropertyFacetReference facetRef = createFacetReference(attribute, stereotype);
+ facet.getFacetElements().add(facetRef);
+ }
}
- //We create the query to get the reprensentedStereotype
- FacetOperation operation = EFacetFactory.eINSTANCE.createFacetOperation();
- operation.setLowerBound(1);
- operation.setUpperBound(1);
- operation.setDocumentation("Returns the qualified name of the represented stereotype");
- operation.setName("getStereotypeQualifiedName");
- // operation.setEType(); //string
- StringLiteralQuery query = QueryFactory.eINSTANCE.createStringLiteralQuery();
- query.setValue(stereotype.getQualifiedName());
- operation.setQuery(query);
+ // //We create the query to get the reprensentedStereotype
+ // final FacetOperation operation = EFacetFactory.eINSTANCE.createFacetOperation();
+ // operation.setLowerBound(1);
+ // operation.setUpperBound(1);
+ // operation.setDocumentation("Returns the qualified name of the represented stereotype");
+ // operation.setName("getStereotypeQualifiedName");
+ // // operation.setEType(); //string
+ // final StringLiteralQuery query = QueryFactory.eINSTANCE.createStringLiteralQuery();
+ // query.setValue(stereotype.getQualifiedName());
+ // operation.setQuery(query);
return facet;
}
- private static FacetOperation singleStringValueOperation;
- private static FacetOperation singleStringValueOperation2;
- private static FacetOperation multiStringValueOperation;
- private static FacetOperation singlePrimitiveTypeValueOperation;
- private static FacetOperation multiPrimitiveTypeValueOperation;
- private static Facet stereotypedElementFacet;
+ public static final StereotypePropertyFacetReference createFacetReference(final Property attribute2, final Stereotype ste) {
+ final StereotypePropertyFacetReference facetReference = UmlEFacetFactory.eINSTANCE.createStereotypePropertyFacetReference();
+ facetReference.setIsDerived(attribute2.isDerived());
+ facetReference.setPropertyName(attribute2.getName());
+ facetReference.setName(attribute2.getName());
+ facetReference.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
+ facetReference.setChangeable(!attribute2.isDerived());
+ facetReference.setDerived(true);
+ final Type type = attribute2.getType();
+ final EClassifier eType = EcorePackage.eINSTANCE.getEObject(); //TODO or element ?
+ OperationCallQuery query;
+ FacetOperation facetOperationCalled = null;
+ final int upperBound = attribute2.upperBound();
+
+ //UML primitive type
+ if(type instanceof Element) {
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getEObjectMultiReferenceOperation(attribute2.eResource().getResourceSet());
+ } else {
+ facetOperationCalled = FacetOperationUtils.getEObjectSingleReferenceOperation(attribute2.eResource().getResourceSet());
+ }
+ //we prepare the arguments
+ query = QueryFactory.eINSTANCE.createOperationCallQuery();
+ query.setCanHaveSideEffects(false);
- private static final Facet getStereotypedElementFacet(final ResourceSet resourceSet) {
- if(stereotypedElementFacet == null) {
- IFacetSetCatalogManager manager = IFacetSetCatalogManagerFactory.DEFAULT.getOrCreateFacetSetCatalogManager(resourceSet);
- for(FacetSet set : manager.getRegisteredFacetSets()) {
- if("org.eclipse.papyrus.uml.efacet/0.9/UML_stereotype".equals(set.getNsURI())) {
- stereotypedElementFacet = (Facet)set.getEClassifier("stereotyped_element");
- break;
- }
- }
- }
- return stereotypedElementFacet;
- }
+ final EObjectLiteralQuery featureQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ featureQuery.setElement(facetReference);
+ query.getArguments().add(featureQuery);
+// final StringLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+// qualifiedNameQuery.setValue(ste.getQualifiedName());
+// query.getArguments().add(qualifiedNameQuery);
+//
+// final StringLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+// propertyNameQuery.setValue(attribute2.getName());
+// query.getArguments().add(propertyNameQuery);
+
+ facetReference.setQuery(query);
- private static FacetOperation getMultiPrimitiveTypeValueOperation(final ResourceSet resourceSet) {
- if(singleStringValueOperation == null) {
- final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
- if(stereotypedElementFacet != null)
- for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
- if("getMultiPrimitiveTypeValue".equals(op.getName())) {
- multiPrimitiveTypeValueOperation = op;
- break;
- }
- }
+ query.setOperation(facetOperationCalled);
+ } else {
+ //TODO?
}
- return multiPrimitiveTypeValueOperation;
+ facetReference.setEType(eType);
+ facetReference.setLowerBound(attribute2.getLower());
+ facetReference.setUpperBound(attribute2.getUpper());
+ return facetReference;
}
- private static FacetOperation getSinglePrimitiveTypeValueOperation(final ResourceSet resourceSet) {
- if(singleStringValueOperation == null) {
- final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
- if(stereotypedElementFacet != null)
- for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
- if("getSinglePrimitiveTypeValue".equals(op.getName())) {
- singlePrimitiveTypeValueOperation = op;
- break;
- }
- }
- }
- return singlePrimitiveTypeValueOperation;
- }
- private static FacetOperation getSingleStringValueOperation(final ResourceSet resourceSet) {
- if(singleStringValueOperation == null) {
- final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
- if(stereotypedElementFacet != null)
- for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
- if("getSingleStringValue".equals(op.getName())) {
- singleStringValueOperation = op;
- break;
- }
- }
- }
- return singleStringValueOperation;
- }
-
- private static FacetOperation getSingleStringValueOperation2(final ResourceSet resourceSet) {
- if(singleStringValueOperation2 == null) {
- final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
- if(stereotypedElementFacet != null)
- for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
- if("getSingleStringValue2".equals(op.getName())) {
- singleStringValueOperation2 = op;
- break;
- }
- }
- }
- return singleStringValueOperation2;
- }
//the first version with the qualifiedName
- public static final FacetAttribute createFacetAttribute(Property attribute2, final Stereotype ste) {
- FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
+ public static final StereotypePropertyFacetAttribute createFacetAttribute(final Property attribute2, final Stereotype ste) {
+ final ResourceSet set = attribute2.eResource().getResourceSet();
+ // final FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
+
+ final StereotypePropertyFacetAttribute facetAttribute = UmlEFacetFactory.eINSTANCE.createStereotypePropertyFacetAttribute();
+ facetAttribute.setIsDerived(attribute2.isDerived());
+ facetAttribute.setPropertyName(attribute2.getName());
+
+
facetAttribute.setName(attribute2.getName());
facetAttribute.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
facetAttribute.setChangeable(!attribute2.isDerived());
facetAttribute.setDerived(true);
- Type type = attribute2.getType();
+ final Type type = attribute2.getType();
EClassifier eType = null;
OperationCallQuery query;
FacetOperation facetOperationCalled = null;
- int upperBound = facetAttribute.getUpperBound();
+ final int upperBound = attribute2.upperBound();
+
+ //UML primitive type
if(type instanceof PrimitiveType) {
- PrimitiveType pType = (PrimitiveType)type;
+ final PrimitiveType pType = (PrimitiveType)type;
final String name = pType.getName();
- if("EString".equals(name)) {
- eType = EcorePackage.eINSTANCE.getEString();
- if(upperBound > 1) {
- //TODO
+ if(UML_BOOLEAN.equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEBoolean();
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getBooleanMultiValueOperation(set);
} else {
- facetOperationCalled = getSingleStringValueOperation(attribute2.eResource().getResourceSet());
+ facetOperationCalled = FacetOperationUtils.getBooleanSingleValueOperation(set);
}
- } else if("EBoolean".equals(name)) {
- eType = EcorePackage.eINSTANCE.getEBoolean();
- } else if("EInt".equals(name)) {
+ } else if(UML_INTEGER.equals(name)) {
eType = EcorePackage.eINSTANCE.getEInt();
- }
- //else TODO to finish
-
-
-
-
-
- //we prepare the arguments
- query = QueryFactory.eINSTANCE.createOperationCallQuery();
- query.setCanHaveSideEffects(false);
-
- StringLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
- qualifiedNameQuery.setValue(ste.getQualifiedName());
- query.getArguments().add(qualifiedNameQuery);
-
- StringLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
- propertyNameQuery.setValue(attribute2.getName());
- query.getArguments().add(propertyNameQuery);
- facetAttribute.setQuery(query);
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getIntegerMultiValueOperation(set);
+ } else {
+ facetOperationCalled = FacetOperationUtils.getIntegerSingleValueOperation(set);
+ }
- query.setOperation(facetOperationCalled);
+ } else if(UML_REAL.equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEDouble();
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getRealMultiValueOperation(set);
+ } else {
+ facetOperationCalled = FacetOperationUtils.getRealSingleValueOperation(set);
+ }
- }
- facetAttribute.setEType(eType);//TODO
- // attribute.setQuery(query);////TODO
- facetAttribute.setLowerBound(attribute2.getLower());
- facetAttribute.setUpperBound(attribute2.getUpper());
- return facetAttribute;
- }
-
- //the second version with references to property and stereitype
- public static final FacetAttribute createFacetAttribute2(Property attribute2, final Stereotype ste) {
- FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
- facetAttribute.setName(attribute2.getName());
- facetAttribute.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
- facetAttribute.setChangeable(!attribute2.isDerived());
- facetAttribute.setDerived(true);
- Type type = attribute2.getType();
- EClassifier eType = null;
- OperationCallQuery query;
- FacetOperation facetOperationCalled = null;
- int upperBound = facetAttribute.getUpperBound();
- if(type instanceof PrimitiveType) {
- PrimitiveType pType = (PrimitiveType)type;
- final String name = pType.getName();
- if("EString".equals(name) || "String".equals(name)) {
+ } else if(UML_STRING.equals(name)) {
eType = EcorePackage.eINSTANCE.getEString();
- if(upperBound > 1) {
- //TODO
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getStringMultiValueOperation(set);
} else {
- facetOperationCalled = getSingleStringValueOperation2(attribute2.eResource().getResourceSet());
+ facetOperationCalled = FacetOperationUtils.getStringSingleValueOperation(set);
}
- } else if("EBoolean".equals(name)) {
- eType = EcorePackage.eINSTANCE.getEBoolean();
- } else if("EInt".equals(name)) {
- eType = EcorePackage.eINSTANCE.getEInt();
- }
- //else TODO to finish
-
+ } else if(UML_UNLIMITED_NATURAL.equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEInt();
+ if(upperBound == -1 || upperBound > 1) {
+ facetOperationCalled = FacetOperationUtils.getUnlimitedNaturalMultiValueOperation(set);
+ } else {
+ facetOperationCalled = FacetOperationUtils.getUnlimitedNaturalSingleValueOperation(attribute2.eResource().getResourceSet());
+ }
+ }
//we prepare the arguments
query = QueryFactory.eINSTANCE.createOperationCallQuery();
query.setCanHaveSideEffects(false);
- EObjectLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
- qualifiedNameQuery.setElement(ste);
- query.getArguments().add(qualifiedNameQuery);
-
- EObjectLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
- propertyNameQuery.setElement(attribute2);
- query.getArguments().add(propertyNameQuery);
+ final EObjectLiteralQuery featureQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ featureQuery.setElement(facetAttribute);
+ query.getArguments().add(featureQuery);
+
+// final StringLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+// qualifiedNameQuery.setValue(ste.getQualifiedName());
+// query.getArguments().add(qualifiedNameQuery);
+//
+// final StringLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+// propertyNameQuery.setValue(attribute2.getName());
+// query.getArguments().add(propertyNameQuery);
facetAttribute.setQuery(query);
query.setOperation(facetOperationCalled);
+ } else if(type instanceof DataType) {
+ //TODO
}
+
facetAttribute.setEType(eType);//TODO
// attribute.setQuery(query);////TODO
facetAttribute.setLowerBound(attribute2.getLower());
@@ -264,8 +289,64 @@ public class FacetFactory {
return facetAttribute;
}
+ // //the second version with references to property and stereitype
+ // public static final FacetAttribute createFacetAttribute2(Property attribute2, final Stereotype ste) {
+ // FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
+ // facetAttribute.setName(attribute2.getName());
+ // facetAttribute.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
+ // facetAttribute.setChangeable(!attribute2.isDerived());
+ // facetAttribute.setDerived(true);
+ // Type type = attribute2.getType();
+ // EClassifier eType = null;
+ // OperationCallQuery query;
+ // FacetOperation facetOperationCalled = null;
+ // int upperBound = facetAttribute.getUpperBound();
+ // if(type instanceof PrimitiveType) {
+ // PrimitiveType pType = (PrimitiveType)type;
+ // final String name = pType.getName();
+ // if("EString".equals(name) || "String".equals(name)) {
+ // eType = EcorePackage.eINSTANCE.getEString();
+ // if(upperBound > 1) {
+ // //TODO
+ // } else {
+ // facetOperationCalled = getSingleStringValueOperation2(attribute2.eResource().getResourceSet());
+ // }
+ // } else if("EBoolean".equals(name)) {
+ // eType = EcorePackage.eINSTANCE.getEBoolean();
+ // } else if("EInt".equals(name)) {
+ // eType = EcorePackage.eINSTANCE.getEInt();
+ // }
+ // //else TODO to finish
+ //
+ //
+ //
+ //
+ //
+ // //we prepare the arguments
+ // query = QueryFactory.eINSTANCE.createOperationCallQuery();
+ // query.setCanHaveSideEffects(false);
+ //
+ // EObjectLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ // qualifiedNameQuery.setElement(ste);
+ // query.getArguments().add(qualifiedNameQuery);
+ //
+ // EObjectLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ // propertyNameQuery.setElement(attribute2);
+ // query.getArguments().add(propertyNameQuery);
+ // facetAttribute.setQuery(query);
+ //
+ // query.setOperation(facetOperationCalled);
+ //
+ // }
+ // facetAttribute.setEType(eType);//TODO
+ // // attribute.setQuery(query);////TODO
+ // facetAttribute.setLowerBound(attribute2.getLower());
+ // facetAttribute.setUpperBound(attribute2.getUpper());
+ // return facetAttribute;
+ // }
+
public static final FacetReference createFacetReference() {
- FacetReference reference = EFacetFactory.eINSTANCE.createFacetReference();
+ final FacetReference reference = EFacetFactory.eINSTANCE.createFacetReference();
return reference;
}
}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetOperationUtils.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetOperationUtils.java
new file mode 100644
index 00000000000..c6030c134d4
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetOperationUtils.java
@@ -0,0 +1,230 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManager;
+import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+
+
+public class FacetOperationUtils {
+
+ /** the facet providing the operation to edit stereotype properties */
+ private static Facet stereotypedElementFacet;
+
+ private static FacetOperation stringSingleValueOperation;
+
+ private static FacetOperation stringMultiValueOperation;
+
+
+ private static FacetOperation eobjectMultiReferenceOperation;
+
+ private static FacetOperation eobejctMonoReferenceOperation;
+
+ private static FacetOperation booleanSingleValueOperation;
+
+ private static FacetOperation booleanMultiValueOperation;
+
+ private static FacetOperation integerMultiValueOperation;
+
+ private static FacetOperation integerSingleValueOperation;
+
+ private static FacetOperation realSingleValueOperation;
+
+ private static FacetOperation realMultiValueOperation;
+
+ private static FacetOperation unlimitedNaturalSingleValueOperation;
+
+ private static FacetOperation unlimitedNaturalMultiValueOperation;
+
+ private FacetOperationUtils() {
+ //to prevent instanciation
+ }
+
+ public static final Facet getStereotypedElementFacet(final ResourceSet resourceSet) {
+ if(stereotypedElementFacet == null) {
+ IFacetSetCatalogManager manager = IFacetSetCatalogManagerFactory.DEFAULT.getOrCreateFacetSetCatalogManager(resourceSet);
+ for(FacetSet set : manager.getRegisteredFacetSets()) {
+ if("org.eclipse.papyrus.uml.efacet/0.9/UML_stereotype".equals(set.getNsURI())) {
+ stereotypedElementFacet = (Facet)set.getEClassifier("stereotyped_element");
+ break;
+ }
+ }
+ }
+ return stereotypedElementFacet;
+ }
+
+ public static FacetOperation getBooleanMultiValueOperation(final ResourceSet resourceSet) {
+ if(booleanMultiValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getBooleanMultiValue".equals(op.getName())) {
+ booleanMultiValueOperation = op;
+ break;
+ }
+ }
+ }
+ return booleanMultiValueOperation;
+ }
+
+
+
+ public static FacetOperation getBooleanSingleValueOperation(final ResourceSet resourceSet) {
+ if(booleanSingleValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getBooleanSingleValue".equals(op.getName())) {
+ booleanSingleValueOperation = op;
+ break;
+ }
+ }
+ }
+ return booleanSingleValueOperation;
+ }
+
+
+ public static FacetOperation getEObjectMultiReferenceOperation(final ResourceSet resourceSet) {
+ if(eobjectMultiReferenceOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getEObjectMultiReference".equals(op.getName())) {
+ eobjectMultiReferenceOperation = op;
+ break;
+ }
+ }
+ }
+ return eobjectMultiReferenceOperation;
+ }
+
+ public static FacetOperation getEObjectSingleReferenceOperation(final ResourceSet resourceSet) {
+ if(eobejctMonoReferenceOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getEObjectSingleReference".equals(op.getName())) {
+ eobejctMonoReferenceOperation = op;
+ break;
+ }
+ }
+ }
+ return eobejctMonoReferenceOperation;
+ }
+
+ public static FacetOperation getIntegerMultiValueOperation(final ResourceSet resourceSet) {
+ if(integerMultiValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getIntegerMultiValue".equals(op.getName())) {
+ integerMultiValueOperation = op;
+ break;
+ }
+ }
+ }
+ return integerMultiValueOperation;
+ }
+
+ public static FacetOperation getIntegerSingleValueOperation(final ResourceSet resourceSet) {
+ if(integerSingleValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getIntegerSingleValue".equals(op.getName())) {
+ integerSingleValueOperation = op;
+ break;
+ }
+ }
+ }
+ return integerSingleValueOperation;
+ }
+
+
+ public static FacetOperation getRealMultiValueOperation(final ResourceSet resourceSet) {
+ if(realMultiValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getRealMultiValue".equals(op.getName())) {
+ realMultiValueOperation = op;
+ break;
+ }
+ }
+ }
+ return realMultiValueOperation;
+ }
+
+ public static FacetOperation getRealSingleValueOperation(final ResourceSet resourceSet) {
+ if(realSingleValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getRealSingleValue".equals(op.getName())) {
+ realSingleValueOperation = op;
+ break;
+ }
+ }
+ }
+ return realSingleValueOperation;
+ }
+
+ public static FacetOperation getStringMultiValueOperation(final ResourceSet resourceSet) {
+ if(stringMultiValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getStringMultiValue".equals(op.getName())) {
+ stringMultiValueOperation = op;
+ break;
+ }
+ }
+ }
+ return stringMultiValueOperation;
+ }
+
+ public static FacetOperation getStringSingleValueOperation(final ResourceSet resourceSet) {
+ if(stringSingleValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getStringSingleValue".equals(op.getName())) {
+ stringSingleValueOperation = op;
+ break;
+ }
+ }
+ }
+ return stringSingleValueOperation;
+ }
+
+ public static FacetOperation getUnlimitedNaturalMultiValueOperation(final ResourceSet resourceSet) {
+ if(unlimitedNaturalMultiValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getUnlimitedNaturalMultiValue".equals(op.getName())) {
+ unlimitedNaturalMultiValueOperation = op;
+ break;
+ }
+ }
+ }
+ return unlimitedNaturalMultiValueOperation;
+ }
+
+
+ public static FacetOperation getUnlimitedNaturalSingleValueOperation(final ResourceSet resourceSet) {
+ if(unlimitedNaturalSingleValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getUnlimitedNaturalSingleValue".equals(op.getName())) {
+ unlimitedNaturalSingleValueOperation = op;
+ break;
+ }
+ }
+ }
+ return unlimitedNaturalSingleValueOperation;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FilteredCheckboxTree.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FilteredCheckboxTree.java
new file mode 100644
index 00000000000..a5838624ed4
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FilteredCheckboxTree.java
@@ -0,0 +1,456 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Duplicated and adapted code from org.eclipse.pde.internal.ui.launcher.FilteredCheckboxTree
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.*;
+import java.util.List;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.ui.progress.WorkbenchJob;
+
+/**
+ * A FilteredChecboxTree. This tree stores all the tree elements internally, and keeps the
+ * check state in sync. This way, even if an element is filtered, the caller can get and set the
+ * checked state.
+ *
+ * The internal representation is additive. That is, elements are never removed from the internal
+ * representation. This is OK since the PDE launch Dialog never changes the elements once
+ * the view is opened. If any other tree is based on this code, they may want to address this issue.
+ *
+ * This is not public because it was customized for the Launch Dialog.
+ *
+ */
+public class FilteredCheckboxTree extends FilteredTree {
+
+ private WorkbenchJob refreshJob;
+
+ /**
+ * The FilteredCheckboxTree Constructor.
+ *
+ * @param parent
+ * The parent composite where this Tree will be placed.
+ * @param treeStyle
+ * Tree styles
+ * @param filter
+ * The pattern filter that will be used to filter elements
+ */
+ public FilteredCheckboxTree(Composite parent, int treeStyle, PatternFilter filter) {
+ super(parent, treeStyle, filter, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.dialogs.FilteredTree#doCreateTreeViewer(org.eclipse.swt.widgets.Composite, int)
+ */
+ protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
+ return new FilterableCheckboxTreeViewer(parent, style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.dialogs.FilteredTree#doCreateRefreshJob()
+ */
+ protected WorkbenchJob doCreateRefreshJob() {
+ // Since refresh job is private, we have to get a handle to it
+ // when it is created, and store it locally.
+ //
+ // See: 218903: [Viewers] support extensibility of the refresh job in FilteredTree
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=218903
+ WorkbenchJob job = super.doCreateRefreshJob();
+ refreshJob = job;
+ return job;
+ }
+
+ /**
+ * Resets the filter and returns when the refresh is complete
+ */
+ public void resetFilter() {
+ // Set the next to the initial Text, stop any outstanding jobs
+ // and call the refresh job to run synchronously.
+ getFilterControl().setText(this.initialText);
+ refreshJob.cancel();
+ refreshJob.runInUIThread(new NullProgressMonitor());
+ }
+
+ /**
+ * Get the number of pixels the tree viewer is from the top of the filtered
+ * checkbox tree viewer. This is useful if you wish to align buttons with the
+ * tree.
+ *
+ * @return the offset of the Tree from the top of the container
+ */
+ int getTreeLocationOffset() {
+ GridLayout layout = (GridLayout)getLayout();
+ return layout.horizontalSpacing + layout.marginTop + ((GridData)getLayoutData()).verticalIndent + getFilterControl().getSize().y + 1;
+ }
+
+ /**
+ * Classes which implement this interface deal with notifications from the
+ * filtered checkbox tree viewer. The notifications are fired before a refresh
+ * happens.
+ */
+ interface PreRefreshNotifier {
+
+ public void preRefresh(FilterableCheckboxTreeViewer viewer, boolean filtered);
+ }
+
+ /**
+ * A CheckboxTreeViewer that maintains an internal representation of all the nodes.
+ *
+ */
+ public class FilterableCheckboxTreeViewer extends ContainerCheckedTreeViewer {
+
+ static final String NONE = "none"; //$NON-NLS-1$
+
+ static final String CHECKED = "checked"; //$NON-NLS-1$
+
+ static final String GREYED = "greyed"; //$NON-NLS-1$
+
+ static final String CHECKED_GREYED = "checked_greyed"; //$NON-NLS-1$
+
+ /**
+ * The internal node for the FilterableCheckboxTreeViewer
+ */
+ class FilteredCheckboxTreeItem {
+
+ Object data; // Data element
+
+ String state; // Checked State
+
+ List children = new ArrayList();
+
+ public FilteredCheckboxTreeItem(Object data, String state, Map itemCache, FilteredCheckboxTreeItem parent) {
+ this.data = data;
+ this.state = state;
+ itemCache.put(data, this);
+ if(parent != null) {
+ parent.children.add(this);
+ }
+ }
+ }
+
+ /* A cache of all the nodes */
+ Map itemCache = new HashMap();
+
+ /* The preRefresh Listeners */
+ List refreshingListeners = new ArrayList();
+
+ protected void unmapAllElements() {
+ itemCache = new HashMap();
+ super.unmapAllElements();
+ }
+
+ /**
+ * FilterableCheckboxTreeViewer constructor. This creates the tree part of the filtered tree.
+ */
+ public FilterableCheckboxTreeViewer(Composite parent, int style) {
+ super(parent, style);
+ addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(event.getElement());
+ if(item != null) {
+ item.state = event.getChecked() ? CHECKED : NONE;
+ }
+ }
+ });
+ }
+
+ /**
+ * Allows clients to listen to the tree refresh.
+ */
+ public void addPreRefreshNotifier(PreRefreshNotifier notifier) {
+ if(refreshingListeners.contains(notifier))
+ return;
+ refreshingListeners.add(notifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#getChecked(java.lang.Object)
+ */
+ public boolean getChecked(Object element) {
+ Widget testFindItem = getViewer().testFindItem(element);
+ testFindItem = null;
+ if(testFindItem == null) {
+ if(itemCache.containsKey(element)) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(element);
+ if(item.state.equals(CHECKED))
+ return true;
+ if(item.state.equals(CHECKED_GREYED))
+ return true;
+ if(item.state.equals(GREYED))
+ return true;
+ else if(item.state.equals(NONE))
+ return false;
+ }
+ }
+ return super.getChecked(element);
+ }
+
+ public Object[] getCheckedChildren(Object element) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(element);
+ List checkedChildren = new ArrayList();
+ if(item != null) {
+ List children = item.children;
+ Iterator iterator = children.iterator();
+ while(iterator.hasNext()) {
+ FilteredCheckboxTreeItem child = (FilteredCheckboxTreeItem)iterator.next();
+ if(child.state == CHECKED) {
+ checkedChildren.add(child.data);
+ }
+ }
+ }
+ return checkedChildren.toArray();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#getCheckedElements()
+ */
+ public Object[] getCheckedElements() {
+ Iterator iterator = itemCache.values().iterator();
+ List checkedElements = new LinkedList();
+ while(iterator.hasNext()) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)iterator.next();
+ Widget testFindItem = getViewer().testFindItem(item.data);
+ testFindItem = null;
+ if(testFindItem == null) {
+ if(item.state.equals(CHECKED) || item.state.equals(CHECKED_GREYED) || item.state.equals(GREYED)) {
+ checkedElements.add(item.data);
+ }
+ } else {
+ if(((TreeItem)testFindItem).getChecked()) {
+ checkedElements.add(testFindItem.getData());
+ }
+ }
+ }
+ return checkedElements.toArray();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#setChecked(java.lang.Object, boolean)
+ */
+ public boolean setChecked(Object element, boolean state) {
+ if(itemCache.containsKey(element)) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(element);
+ item.state = state ? CHECKED : NONE;
+ }
+ return super.setChecked(element, state);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#setCheckedElements(java.lang.Object[])
+ */
+ public void setCheckedElements(Object[] elements) {
+ Set s = new HashSet(itemCache.keySet());
+ s.removeAll(new HashSet(Arrays.asList(elements)));
+ for(int i = 0; i < elements.length; i++) {
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(elements[i]);
+ if(item != null) {
+ item.state = CHECKED;
+ }
+ }
+ for(Iterator iterator = s.iterator(); iterator.hasNext();) {
+ Object object = iterator.next();
+ FilteredCheckboxTreeItem item = (FilteredCheckboxTreeItem)itemCache.get(object);
+ if(item != null) {
+ item.state = NONE;
+ }
+ }
+ super.setCheckedElements(elements);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#setSubtreeChecked(java.lang.Object, boolean)
+ */
+ public boolean setSubtreeChecked(Object element, boolean state) {
+ String newState = state ? CHECKED : NONE;
+ TreeItem item = (TreeItem)testFindItem(element);
+ FilteredCheckboxTreeItem filteredCheckboxTreeItem = (FilteredCheckboxTreeItem)itemCache.get(element);
+ if(item != null && filteredCheckboxTreeItem != null) {
+ filteredCheckboxTreeItem.state = newState;
+ TreeItem[] items = item.getItems();
+ for(int i = 0; i < items.length; i++) {
+ item = items[i];
+ if(item != null) {
+ filteredCheckboxTreeItem = (FilteredCheckboxTreeItem)itemCache.get(item.getData());
+ if(filteredCheckboxTreeItem != null) {
+ filteredCheckboxTreeItem.state = newState;
+ }
+ }
+ }
+ }
+ return super.setSubtreeChecked(element, state);
+ }
+
+ /*
+ * public boolean setSubtreeChecked(Object element, boolean state) {
+ * String newState = state ? CHECKED : NONE;
+ * FilteredCheckboxTreeItem filteredCheckboxTreeItem = (FilteredCheckboxTreeItem) itemCache.get(element);
+ * if (filteredCheckboxTreeItem != null) {
+ * filteredCheckboxTreeItem.state = newState;
+ * List children = filteredCheckboxTreeItem.children;
+ * for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ * FilteredCheckboxTreeItem child = (FilteredCheckboxTreeItem) iterator.next();
+ * child.state = newState;
+ * }
+ * }
+ * return super.setSubtreeChecked(element, state);
+ * }
+ */
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.CheckboxTreeViewer#preservingSelection(java.lang.Runnable)
+ */
+ protected void preservingSelection(Runnable updateCode) {
+ super.preservingSelection(updateCode);
+
+ // Re-apply the checked state
+ ArrayList allTreeItems = getAllTreeItems(treeViewer.getTree().getItems());
+ for(Iterator iterator = allTreeItems.iterator(); iterator.hasNext();) {
+ TreeItem item = (TreeItem)iterator.next();
+ doApplyCheckedState(item, item.getData());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefresh(java.lang.Object, boolean)
+ */
+ protected void internalRefresh(Object element, boolean updateLabels) {
+ String text = FilteredCheckboxTree.this.getFilterString();
+ boolean initial = initialText != null && initialText.equals(text);
+ boolean filtered = (text.length() > 0 && !initial);
+
+ // Notify anybody who is listening for the refresh
+ for(Iterator iterator = refreshingListeners.iterator(); iterator.hasNext();) {
+ PreRefreshNotifier notifier = (PreRefreshNotifier)iterator.next();
+ notifier.preRefresh(FilterableCheckboxTreeViewer.this, filtered);
+ }
+ saveCheckedState();
+ super.internalRefresh(element, updateLabels);
+ treeViewer.expandAll();
+ }
+
+ /*
+ * Set the checked state
+ */
+ private void doApplyCheckedState(Item item, Object element) {
+ // update the item first
+ super.doUpdateItem(item, element);
+
+ // Update the checked state
+ TreeItem treeItem = (TreeItem)item;
+ if(itemCache.containsKey(element)) {
+ String state = ((FilteredCheckboxTreeItem)itemCache.get(element)).state;
+ if(state.equals(CHECKED_GREYED)) {
+ treeItem.setGrayed(true);
+ treeItem.setChecked(true);
+ } else if(state.equals(CHECKED)) {
+ treeItem.setChecked(true);
+ treeItem.setGrayed(false);
+ } else if(state.equals(GREYED)) {
+ treeItem.setGrayed(true);
+ treeItem.setChecked(false);
+ } else {
+ treeItem.setGrayed(false);
+ treeItem.setChecked(false);
+ }
+ }
+ }
+
+ /*
+ * A helper method to get all the items in the tree
+ */
+ private ArrayList getAllTreeItems(TreeItem[] roots) {
+ ArrayList list = new ArrayList();
+ for(int i = 0; i < roots.length; i++) {
+ TreeItem item = roots[i];
+ list.add(item);
+ list.addAll(getAllTreeItems(item.getItems()));
+ }
+ return list;
+ }
+
+ /**
+ * Saves the checked state of all the elements in the tree
+ */
+ private void saveCheckedState() {
+ TreeItem[] items = treeViewer.getTree().getItems();
+ for(int i = 0; i < items.length; i++) {
+ TreeItem item = items[i];
+ if(!itemCache.containsKey(item.getData())) {
+ new FilteredCheckboxTreeItem(item.getData(), getItemState(item), itemCache, null);
+ }
+ FilteredCheckboxTreeItem filteredCheckboxTreeItem = (FilteredCheckboxTreeItem)itemCache.get(item.getData());
+ filteredCheckboxTreeItem.state = getItemState(item);
+ saveCheckedState(filteredCheckboxTreeItem, item);
+ }
+ }
+
+ /**
+ * Saves the checked state of an item and all its children
+ */
+ private void saveCheckedState(FilteredCheckboxTreeItem parent, TreeItem parentItem) {
+ TreeItem[] items = parentItem.getItems();
+ for(int i = 0; i < items.length; i++) {
+ TreeItem item = items[i];
+ if(!itemCache.containsKey(item.getData())) {
+ new FilteredCheckboxTreeItem(item.getData(), getItemState(item), itemCache, parent);
+ }
+ FilteredCheckboxTreeItem filteredCheckboxTreeItem = (FilteredCheckboxTreeItem)itemCache.get(item.getData());
+ filteredCheckboxTreeItem.state = getItemState(item);
+ saveCheckedState(filteredCheckboxTreeItem, item);
+ }
+ }
+
+ /**
+ * Computes the checked state from a tree item
+ */
+ private String getItemState(TreeItem item) {
+ if(item.getChecked() && item.getGrayed()) {
+ return CHECKED_GREYED;
+ } else if(item.getChecked()) {
+ return CHECKED;
+ } else if(item.getGrayed()) {
+ return GREYED;
+ } else {
+ return NONE;
+ }
+ }
+
+ } // end of FilterableCheckboxTreeViewer
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java
index d394e4e4138..0f08fd3c287 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java
@@ -1,361 +1,485 @@
package org.eclipse.papyrus.infra.table.efacet.menu.handler;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
-import java.util.TreeMap;
import java.util.TreeSet;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.mapping.ModelStatus;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.ETypedElement;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.facet.efacet.core.IFacetManager;
import org.eclipse.emf.facet.efacet.core.IFacetManagerFactory;
-import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetFactory;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetAttribute;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetElement;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.EObjectLiteralQuery;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.OperationCallQuery;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryFactory;
-import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.StringLiteralQuery;
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
-import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactory;
-import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactoryFactory;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidget;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetInternal;
import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetProvider;
-import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractTableEditor;
import org.eclipse.papyrus.infra.table.efacet.menu.Activator;
+import org.eclipse.papyrus.infra.table.efacet.menu.factory.ITableCommandFactory;
+import org.eclipse.papyrus.infra.table.efacet.menu.factory.TableCommandFactory;
import org.eclipse.papyrus.infra.table.efacet.menu.factory.TableInstanceCommandFactory;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.TableContentsUtils;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.EditorPart;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.util.UMLUtil;
//FIXME : uml dependency
public class SelectColumnsHandler extends AbstractHandler {
+ private final String ADDITIONAL_CONTENTS_FACET_SET_NAME = "AdditionalContentsForTable";
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final CompoundCommand compoundCmd = new CompoundCommand("Papyrus Show/Hide columns");
- final PapyrusTable papyrusTable = getPapyrusTable();
- final ITableWidget widget = getTableWidget();
- TransactionalEditingDomain domain = getEditingDomain();
- ICommand addFacetSetToResourceCommand = null;
- if(papyrusTable != null && widget != null) {
- //the contents of the table
- final List<EObject> contents = TableContentsUtils.getTableContents(papyrusTable, papyrusTable.getTable().getContext(), false);
+ private final String ADDITIONAL_CONTENTS_FACET_SET_NS_URI = "http://www.eclipse.org/papyrustableefacet/additionalcontentsfacetset";
- //all stereotypes used in the table
- final Set<Stereotype> stereotypes = new HashSet<Stereotype>();
+ private final String ADDITIONAL_CONTENTS_FACET_SET_PREFIX = "additionalcontentsfacetset";
- //all stereotypes identified by their qualified name
- final Map<String, Stereotype> mapName_stereotypes = new HashMap<String, Stereotype>();
+ private final String ADDITIONAL_CONTENTS_FACET_SET_DOCUMENTATION = "This FacetSet provides facets to edit easily additional contents (as Stereotype Properties). It had been generated by the Papyrus Show/Hide columns";
- //all facets applied on the table + all applicable facets representing stereotypes
- final Set<Facet> allFacets = new TreeSet<Facet>(new EcoreFeatureComparator());
+ /** all direct features available in the table */
+ final protected SortedSet<ETypedElement> allDirectFeatures = new TreeSet<ETypedElement>(new EcoreENamedElementComparator());
- final SortedSet<ETypedElement> allFeatures = new TreeSet<ETypedElement>(new EcoreFeatureComparator());
- final Map<ETypedElement, Column> columnsFeatureMap = new HashMap<ETypedElement, Column>();
- final Map<EClass, Stereotype> eClassSteMap = new TreeMap<EClass, Stereotype>(new EcoreFeatureComparator());
+ /** all additional possible contents */
+ final protected Collection<FacetSet> allAdditionalContents = new HashSet<FacetSet>();
+ /** the initial direct features visibles in the table */
+ final protected Collection<ETypedElement> initialDirectFeatureSelected = new HashSet<ETypedElement>();
- //1. Get all direct features and store all used stereotypes
- for(EObject current : contents) {
- allFeatures.addAll(current.eClass().getEAllStructuralFeatures());
- if(current instanceof Element) {
- stereotypes.addAll(((Element)current).getAppliedStereotypes());
- }
- }
+ /** the initial additional features visibles in the table */
+ final protected Collection<ETypedElement> initialAdditionalFeatureSelected = new HashSet<ETypedElement>();
- //1. bis
- // - complete the list of features with the features of the columns
- // - map the columns with the features
- for(final Column current : papyrusTable.getTable().getColumns()) {
- if(current instanceof FeatureColumn) {
- final FeatureColumn col = (FeatureColumn)current;
- final ETypedElement feature = col.getFeature();
- columnsFeatureMap.put(feature, col);
- if(feature instanceof FacetElement) {
- allFacets.add((Facet)feature.eContainer());
- }
- }
- }
+ /** the list of the facetSet used in the current table */
+ final protected Collection<FacetSet> facetSetsUsedInTheTable = new HashSet<FacetSet>();
- //2. look for an existing facetSet representing the stereotype
- final String facetSetName = "localFacetSet";
- final String facetSetURI = "http://www.eclipse.org/papyrustableefacet/localfacetset";
- FacetSet localSet = null;
- EcoreUtil.resolveAll(papyrusTable);
- Resource res = papyrusTable.eResource();
- if(res == null) {
- if(domain == null) {
- domain = TransactionUtil.getEditingDomain(contents.get(0));
- }
- try {
- ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
- domain = serviceRegistry.getService(TransactionalEditingDomain.class);
- } catch (ServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ /** the map between existing columns (visible or not) and the feature */
+ final protected Map<ETypedElement, Column> columnsFeatureMap = new HashMap<ETypedElement, Column>();
- EList<Resource> resources = domain.getResourceSet().getResources();
- for(Resource tmpRes : resources) {
- URI uri = tmpRes.getURI();
- if(uri.fileExtension().equals("notation")) {
- int i = 0;
- i++;
- EList<EObject> allContents = res.getContents();
- i++;
- }
- }
- }
- for(final EObject current : res.getContents()) {
- if(current instanceof FacetSet && facetSetName.equals(((FacetSet)current).getName())) {
- localSet = (FacetSet)current;
- break;
- }
- }
+ //TODO remove it
+ final StereotypeManagement management = new StereotypeManagement();
- //2. bis if the facetSet doesn't exist, we create it
- if(localSet == null) {
- final String documentation = "This FacetSet provides facet to edit easily the properties of the stereotypes. It had been generated by the Papyrus Show/Hide columns";
- localSet = FacetFactory.createFacetSet("localfacetset", "localfacetset", "http://www.eclipse.org/papyrustableefacet/localfacetset", documentation);
- final FacetSet set = localSet;
- addFacetSetToResourceCommand = new AbstractTransactionalCommand(getEditingDomain(), "Attach local facetSet to the resource", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- papyrusTable.eResource().getContents().add(set);
- return CommandResult.newOKCommandResult();
- }
- };
- }
+ /**
+ * clear the fields
+ */
+ protected void clearFields() {
+ this.allDirectFeatures.clear();
+ this.initialDirectFeatureSelected.clear();
+ this.initialAdditionalFeatureSelected.clear();
+ this.facetSetsUsedInTheTable.clear();
+ this.columnsFeatureMap.clear();
+ this.allAdditionalContents.clear();
+ }
- //3. we associate each stereotype to its qualified name
- for(final Stereotype ste : stereotypes) {
- mapName_stereotypes.put(ste.getQualifiedName(), ste);
- }
+ //TODO look for an existing method in EMF for EPackage
+ private FacetSet getRootFacetSet(final FacetElement facetElement) {
+ EObject container = facetElement;
+ while(container.eContainer() != null) {
+ container = container.eContainer();
+ }
+ if(container instanceof FacetSet) {
+ return (FacetSet)container;
+ }
+ return null;
+ }
- //4. we map the stereotype with the existing Facet //TODO currently, we assume that the stereotype has not changed
- List<Stereotype> unmappedStereotype = new ArrayList<Stereotype>(stereotypes);
- for(final EClassifier currentFacet : localSet.getEClassifiers()) {
- if(currentFacet instanceof Facet) {
- for(final FacetOperation op : ((Facet)currentFacet).getFacetOperations()) {
- if("getStereotypeQualifiedName".equals(op.getName())) {
- final String qName = ((StringLiteralQuery)op.getQuery()).getValue();
- unmappedStereotype.remove(mapName_stereotypes.get(qName));
- break;
- }
- }
+ /**
+ * Inits the fields of this class
+ *
+ * @param widget
+ * the table widget
+ * @param papyrusTable
+ * the papyrus table
+ */
+ protected void initField(final ITableWidget widget, final PapyrusTable papyrusTable) {
+ clearFields();
+ //the contents of the table
+ final List<EObject> contents = TableContentsUtils.getTableContents(papyrusTable, papyrusTable.getTable().getContext(), false);
+
+ //1. Get all direct features
+ for(final EObject current : contents) {
+ this.allDirectFeatures.addAll(current.eClass().getEAllStructuralFeatures());
+ }
+
+ //2. we build the list of the initialSelection
+ final List<Column> visibleColumns = widget.getVisibleColumns(false);
+ final Set<ETypedElement> visibleFeatures = new HashSet<ETypedElement>();
+ for(final Column current : visibleColumns) {
+ if(current instanceof FeatureColumn) {
+ final ETypedElement feature = ((FeatureColumn)current).getFeature();
+ if(feature instanceof FacetElement) {
+ this.initialAdditionalFeatureSelected.add(feature);
+ } else {
+ this.initialDirectFeatureSelected.add(feature);
}
}
+ }
- final List<Facet> createdEFacet = new ArrayList<Facet>();
-
- //5. we create the Facet for the unmapped stereotypes
- for(final Stereotype ste : unmappedStereotype) {
- Facet facet = FacetFactory.createFacet(ste);
- createdEFacet.add(facet);
+ for(final Column current : papyrusTable.getTable().getColumns()) {
+ if(current instanceof FeatureColumn) {
+ final FeatureColumn col = (FeatureColumn)current;
+ final ETypedElement feature = col.getFeature();
+ //3. we associate each features to each columns
+ this.columnsFeatureMap.put(feature, col);
+
+ //3 bis. we build the list of the initialSelection
+ if(feature instanceof FacetElement) {
+ final FacetSet set = getRootFacetSet((FacetElement)feature);
+ this.facetSetsUsedInTheTable.add(set);
+ }
}
- allFacets.addAll(createdEFacet);
+ }
- //6. we create the input
- final Collection<EObject> dialogInput = new ArrayList<EObject>();
- dialogInput.addAll(allFeatures);
- dialogInput.addAll(allFacets);
+ //4. get the additional features
+ final FacetSet additionFeatureRootFacetSet = getAdditionalContentsFacetSet(papyrusTable);
+ if(additionFeatureRootFacetSet != null) {
+ //TODO ask for that to Grégoire Dupé!
+ //TODO before update the source code of EMF-Facet
+ final List<EPackage> sets = additionFeatureRootFacetSet.getESubpackages();
+ for(final EPackage ePackage : sets) {
+ if(ePackage instanceof FacetSet) {
+ this.allAdditionalContents.add((FacetSet)ePackage);
+ }
+ }
+ }
+ this.allAdditionalContents.addAll(this.facetSetsUsedInTheTable);
+ this.allAdditionalContents.addAll(this.management.getAdditionalFeatures(papyrusTable, contents, this.facetSetsUsedInTheTable));
- //7. we build the initial selection
- final Collection<ETypedElement> initialSelection = new ArrayList<ETypedElement>(columnsFeatureMap.keySet());
+ }
- ColumnsToHideDialog dialog = new ColumnsToHideDialog(Display.getCurrent().getActiveShell(), dialogInput, initialSelection, getLabelProvider());
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+
+ final CompoundCommand compoundCmd = new CompoundCommand("Papyrus Show/Hide columns command");
+ final PapyrusTable papyrusTable = getPapyrusTable();
+ final ITableWidget widget = getTableWidget();
+ final TransactionalEditingDomain domain = getEditingDomain();
+ FacetSet additionFeatureRootFacetSet = getAdditionalContentsFacetSet(papyrusTable);
+ if(papyrusTable != null && widget != null) {
+ initField(widget, papyrusTable);
+ final Collection<ETypedElement> initialSelection = new ArrayList<ETypedElement>();
+ initialSelection.addAll(this.initialDirectFeatureSelected);
+ initialSelection.addAll(this.initialAdditionalFeatureSelected);
+ final Collection<ENamedElement> allFacetSets = new TreeSet<ENamedElement>(new EcoreENamedElementComparator());
+ allFacetSets.addAll(this.facetSetsUsedInTheTable);
+ allFacetSets.addAll(this.allAdditionalContents);
+ final ColumnsToShowDialog dialog = new ColumnsToShowDialog(Display.getCurrent().getActiveShell(), this.allDirectFeatures, allFacetSets, initialSelection, getLabelProvider(), new SortedColumnContentProvider());
if(dialog.open() == Window.OK) {
final Object[] result = dialog.getResult();
- final List<Object> resultAsList = Arrays.asList(result);
-
- final List<Object> columnsToAdd = new ArrayList<Object>(resultAsList);
- columnsToAdd.removeAll(initialSelection);
- //these columns should be set To Visible OR created
-
- List<Column> columnsToShow = new ArrayList<Column>();
- List<ETypedElement> columnsToCreate = new ArrayList<ETypedElement>();
- for(final Object currentColumn : columnsToAdd) {
- if(columnsFeatureMap.containsKey(currentColumn)) {
- columnsToShow.add(columnsFeatureMap.get(currentColumn));
- } else {
- columnsToCreate.add((ETypedElement)currentColumn);
+ final Set<ETypedElement> directFeatures = (Set<ETypedElement>)result[0];
+ final Set<ETypedElement> additionalFeatures = (Set<ETypedElement>)result[1];
+ if(!directFeatures.equals(this.initialDirectFeatureSelected)) {
+ //1. get command to show/hide direct features
+ final Command cmd = getShowHideDirectFeatureColumnsCommand(papyrusTable, (ITableWidgetInternal)widget, directFeatures);
+ if(cmd != null) {
+ compoundCmd.append(cmd);
}
}
- List<Object> featureToHide = new ArrayList<Object>(initialSelection);
- featureToHide.removeAll(resultAsList);
+ if(!additionalFeatures.equals(initialAdditionalFeatureSelected)) {
+ // 2. get the command to show/hide additional contents
+ final Command cmd2 = getCreateDestroyAdditonalFeatureColumnsCommand(papyrusTable, (ITableWidgetInternal)widget, additionalFeatures);
+ if(cmd2 != null) {
+ compoundCmd.append(cmd2);
+ }
+ //3. get command to store/unstore facets
+ final Set<FacetSet> requiredFacetSets = new HashSet<FacetSet>();
+ final Set<FacetSet> toAddToResource = new HashSet<FacetSet>();
+ final Set<FacetSet> uselessFacetSets = new HashSet<FacetSet>();
+ for(final ETypedElement current : additionalFeatures) {
+ assert (current instanceof FacetElement);
+ final FacetSet root = getRootFacetSet((FacetElement)current);
+ assert root != null;
+ requiredFacetSets.add(root);
+ if(root.eResource() == null) {
+ toAddToResource.add(root);
+ }
+ }
- //these columns should be hidden
- List<Column> columnsToHide = new ArrayList<Column>();
- for(final Object current : featureToHide) {
- Column toHide = columnsFeatureMap.get(current);
- if(toHide != null) {
- columnsToHide.add(toHide);
+ if(additionFeatureRootFacetSet != null) {
+ for(final EPackage set : additionFeatureRootFacetSet.getESubpackages()) {
+ if(set instanceof FacetSet && !requiredFacetSets.contains(set)) {
+ uselessFacetSets.add((FacetSet)set);//TODO and if this facetSet is required by another table
+ }
+ }
}
- }
- ITableWidgetInternal widgetController = (ITableWidgetInternal)widget;
- ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(domain);
- boolean putOnTheTop = false;
+ //4. add required facetSet to the resource
+ if(additionFeatureRootFacetSet == null) {
+ //we create the facetset
+ additionFeatureRootFacetSet = EFacetFactory.eINSTANCE.createFacetSet();
+ additionFeatureRootFacetSet.setName(this.ADDITIONAL_CONTENTS_FACET_SET_NAME);
+ additionFeatureRootFacetSet.setNsPrefix(this.ADDITIONAL_CONTENTS_FACET_SET_PREFIX);
+ additionFeatureRootFacetSet.setNsURI(this.ADDITIONAL_CONTENTS_FACET_SET_NS_URI);
+ additionFeatureRootFacetSet.setDocumentation(this.ADDITIONAL_CONTENTS_FACET_SET_DOCUMENTATION);
+ additionFeatureRootFacetSet.getESubpackages().addAll(toAddToResource);
+ final FacetSet createdFacetSet = additionFeatureRootFacetSet;
+ final ICommand addLocalFacetSetToResource = new AbstractTransactionalCommand(domain, "Add Additional Contents FacetSet to the resource", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ papyrusTable.eResource().getContents().add(createdFacetSet);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ compoundCmd.append(new GMFtoEMFCommandWrapper(addLocalFacetSetToResource));
+ } else if(toAddToResource != null) {
+ final FacetSet localSet = additionFeatureRootFacetSet;
+ final ICommand addNewFacetSetToResource = new AbstractTransactionalCommand(domain, "Add Additional Contents FacetSet to the resource", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ localSet.getESubpackages().addAll(toAddToResource);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ compoundCmd.append(new GMFtoEMFCommandWrapper(addNewFacetSetToResource));
+ }
- final Command showHideCommand = TableInstanceCommandFactory.createShowHideColumnCommand(widgetController, domain, commandFactory, papyrusTable.getTable(), columnsToShow, columnsToHide, putOnTheTop);
- if(showHideCommand != null && showHideCommand.canExecute()) {
- compoundCmd.append(showHideCommand);
+ //5. remove useless facets set
+ //TODO
}
- if(addFacetSetToResourceCommand != null) { //TODO : test if the current selection need to it!
- compoundCmd.append(new GMFtoEMFCommandWrapper(addFacetSetToResourceCommand));
+ if(!compoundCmd.isEmpty()) {
+ domain.getCommandStack().execute(compoundCmd);
}
- //TODO : complete with the removeFacetSetFromResource command or remove Facet from facetSet command
-
- if(!createdEFacet.isEmpty()) {
- final FacetSet set = localSet;
- ICommand cmd = new AbstractTransactionalCommand(getEditingDomain(), "Add Facet to the local facetSet", null) {
+ }
+ }
+ //we clear the fields
+ clearFields();
+ return null;
+ }
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- set.getEClassifiers().addAll(createdEFacet);
- return CommandResult.newOKCommandResult();
- }
- };
- compoundCmd.append(new GMFtoEMFCommandWrapper(cmd));
+ //TODO should be moved in another classes to be used by the stereotypemanager?
+ protected FacetSet getAdditionalContentsFacetSet(final PapyrusTable table) {
+ FacetSet set = null;
+ final Resource resource = table.eResource();
+ final Iterator<EObject> iter = resource.getContents().iterator();
+ while(iter.hasNext() && set == null) {
+ final EObject current = iter.next();
+ if(current instanceof FacetSet) {
+ final FacetSet tmp = (FacetSet)current;
+ if(this.ADDITIONAL_CONTENTS_FACET_SET_NS_URI.equals(tmp.getNsURI())) {
+ set = tmp;
}
+ }
+ }
+
+ return set;
+ }
+
+ /**
+ *
+ * @param papyrusTable
+ * the papyrus table
+ * @param widget
+ * the widget
+ * @param selectedFeatures
+ * the direct features selected
+ * @return
+ * the command to show/hide the required columns (we doesn't destroy columns, because EMF-Facet will cerate it, if they are required, for
+ * the next added element in the table)
+ */
+ protected Command getShowHideDirectFeatureColumnsCommand(final PapyrusTable papyrusTable, final ITableWidgetInternal widget, final Collection<ETypedElement> selectedFeatures) {
+ final CompoundCommand compoundCmd = new CompoundCommand("Show/Hide direct features command");
+
+ //1. calculus of the columns to show/add
+ final List<ETypedElement> featuresToAdd = new ArrayList<ETypedElement>(selectedFeatures);
+ featuresToAdd.removeAll(this.initialDirectFeatureSelected);
+ //these columns should be set To Visible OR created
+
+ //2. calculus of the columns to hide
+ final List<Object> directFeaturesToHide = new ArrayList<Object>(this.initialDirectFeatureSelected);
+ directFeaturesToHide.removeAll(selectedFeatures);
+
+ //these columns should be hidden
+ final List<Column> columnsToHide = new ArrayList<Column>();
+ for(final Object current : directFeaturesToHide) {
+ final Column toHide = this.columnsFeatureMap.get(current);
+ if(toHide != null) {
+ columnsToHide.add(toHide);
+ }
+ }
+ final List<Column> columnsToShow = new ArrayList<Column>();
- domain.getCommandStack().execute(compoundCmd);
- IFacetSetCatalogManagerFactory.DEFAULT.getOrCreateFacetSetCatalogManager(res.getResourceSet()).registerFacetSet(localSet);
- List<FacetSet> facetSetToAdd = new ArrayList<FacetSet>();
- facetSetToAdd.add(localSet);
+ //not useful for direct features
+ final List<ETypedElement> columnsToCreate = new ArrayList<ETypedElement>();
- widget.addColumns(columnsToCreate, facetSetToAdd);//TODO should be chained with the previous command
+ for(final Object currentColumn : featuresToAdd) {
+ if(this.columnsFeatureMap.containsKey(currentColumn)) {
+ columnsToShow.add(this.columnsFeatureMap.get(currentColumn));
+ } else {
+ columnsToCreate.add((ETypedElement)currentColumn);
}
}
- return null;
- }
+ final TransactionalEditingDomain domain = getEditingDomain();
+ final ITableWidgetInternal widgetController = widget;
+ final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(domain);
+ final boolean putOnTheTop = false;
- protected Command getBuildedCommand() {
- CompoundCommand compoundCommand = new CompoundCommand();
+ final Command showHideCommand = TableInstanceCommandFactory.createShowHideColumnCommand(widgetController, domain, commandFactory, papyrusTable.getTable(), columnsToShow, columnsToHide, putOnTheTop);
- return compoundCommand;
- }
+ if(showHideCommand != null && showHideCommand.canExecute()) {
+ compoundCmd.append(showHideCommand);
+ }
- protected Command getShowHideExistingColumnCommand() {
- CompoundCommand compoundCommand = new CompoundCommand();
+ //columns to create should always be null with direct features!
+ assert columnsToCreate.isEmpty();
+ if(!compoundCmd.isEmpty() && compoundCmd.canExecute()) {
+ return compoundCmd;
+ }
+ return null;
- return compoundCommand;
}
- protected Command getAddAndCreateNewColumnsCommand() {
- CompoundCommand compoundCommand = new CompoundCommand();
+ /**
+ *
+ * @param papyrusTable
+ * the papyrus table
+ * @param widget
+ * the widget
+ * @param selectedAdditionalFeatures
+ * the addtional features selected
+ * @return
+ * the command to create and destroy the required columns (can be <code>null</code>)
+ * /!\ EMF-Facet allows to hide EMF-Facet columns, so if such column already exists but are not visible, we show them
+ */
+ private Command getCreateDestroyAdditonalFeatureColumnsCommand(final PapyrusTable papyrusTable, final ITableWidgetInternal widget, final Collection<ETypedElement> selectedAdditionalFeatures) {
+ final CompoundCommand compoundCmd = new CompoundCommand("Show/Hide additional features command");
+
+ //1. calculus of the columns to show/add
+ //these columns should be set to visible or created
+ final List<ETypedElement> featuresToAdd = new ArrayList<ETypedElement>(selectedAdditionalFeatures);
+ featuresToAdd.removeAll(this.initialAdditionalFeatureSelected);
+
+ //we should take into account that EMF-Facet allows to destroy AND hide columns, so some columns can already exists but are currently not visible
+ final List<ETypedElement> columnsToCreate = new ArrayList<ETypedElement>();
+ columnsToCreate.addAll(featuresToAdd);
+ final List<Column> existingColumnsToShow = new ArrayList<Column>();
+
+ final ListIterator<ETypedElement> iter = columnsToCreate.listIterator();
+ while(iter.hasNext()) {
+ final ETypedElement current = iter.next();
+ if(this.columnsFeatureMap.containsKey(current)) {
+ existingColumnsToShow.add(this.columnsFeatureMap.get(current));
+ iter.remove();
+ }
+ }
- return compoundCommand;
- }
+ //2. calculus of the columns to hide/destroy
+ final List<ETypedElement> additionalFeaturesToHide = new ArrayList<ETypedElement>(this.initialAdditionalFeatureSelected);
+ additionalFeaturesToHide.removeAll(selectedAdditionalFeatures);
+ final TransactionalEditingDomain domain = getEditingDomain();
+ final ITableWidgetInternal widgetController = widget;
- public class EcoreFeatureComparator implements Comparator<ENamedElement> {
+ final boolean putOnTheTop = false;
- public int compare(ENamedElement o1, ENamedElement o2) {
- return o1.getName().compareToIgnoreCase(o2.getName());
+ final Set<FacetSet> facetSets = new HashSet<FacetSet>();
+ for(final ETypedElement current : selectedAdditionalFeatures) {
+ if(current instanceof FacetElement) {
+ final FacetSet set = getRootFacetSet((FacetElement)current);
+ if(set != null) {
+ facetSets.add(set);
+ }
+ }
+ }
+
+ facetSets.addAll(papyrusTable.getTable().getFacetSets());
+
+
+ final ITableCommandFactory tableCommandFactory = getTableCmdFactory(domain, papyrusTable.eResource().getResourceSet(), papyrusTable.getTable());
+ final Command createColumns = tableCommandFactory.createAddColumnCommand(columnsToCreate, new ArrayList<FacetSet>(facetSets));
+ if(createColumns != null && createColumns.canExecute()) {
+ compoundCmd.append(createColumns);
}
- }
- public class StereotypeNameComparator implements Comparator<Stereotype> {//TODO rename into NamedElement Comparator
- public int compare(Stereotype o1, Stereotype o2) {
- return o1.getName().compareToIgnoreCase(o2.getName());
+ final Command removeColumns = tableCommandFactory.createRemoveColumnsCommand(additionalFeaturesToHide);
+ if(removeColumns != null && removeColumns.canExecute()) {
+ compoundCmd.append(removeColumns);
+ }
+
+ final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(domain);
+ if(existingColumnsToShow.size() != 0) {
+ final Command showHideCommand = TableInstanceCommandFactory.createShowHideColumnCommand(widgetController, domain, commandFactory, papyrusTable.getTable(), existingColumnsToShow, new ArrayList<Column>(), putOnTheTop);
+ if(showHideCommand != null && showHideCommand.canExecute()) {
+ compoundCmd.append(showHideCommand);
+ }
}
+ if(!compoundCmd.isEmpty()) {
+ return compoundCmd;
+ }
+ return null;
}
+ /**
+ *
+ * @return
+ * the editing domain used by this handler or <code>null</code> if not found
+ */
private TransactionalEditingDomain getEditingDomain() {
TransactionalEditingDomain domain = null;
domain = TransactionUtil.getEditingDomain(getPapyrusTable());
return domain;
}
+ /**
+ *
+ * @return
+ * the current table editor, or <code>null</code> if not found
+ */
private AbstractTableEditor getCurrentTableEditor() {
-
final IStructuredSelection selection = (IStructuredSelection)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
final Object current = selection.getFirstElement();
if(current instanceof EObject) {
@@ -363,7 +487,7 @@ public class SelectColumnsHandler extends AbstractHandler {
IEditorPart part = null;
try {
part = ServiceUtilsForResource.getInstance().getNestedActiveIEditorPart(((EObject)current).eResource());
- } catch (ServiceException e) {
+ } catch (final ServiceException e) {
Activator.log.error(e);
}
if(part instanceof AbstractTableEditor) {
@@ -374,16 +498,26 @@ public class SelectColumnsHandler extends AbstractHandler {
return null;
}
+ /**
+ *
+ * @return
+ * the papyrus table
+ */
private PapyrusTable getPapyrusTable() {
- IEditorPart part = getCurrentTableEditor();
+ final IEditorPart part = getCurrentTableEditor();
if(part != null) {
return (PapyrusTable)part.getAdapter(PapyrusTable.class);
}
return null;
}
+ /**
+ *
+ * @return
+ * the table widget
+ */
private ITableWidget getTableWidget() {
- IAdaptable editor = getCurrentTableEditor();
+ final IAdaptable editor = getCurrentTableEditor();
final ITableWidgetProvider provider = (ITableWidgetProvider)editor.getAdapter(ITableWidgetProvider.class);
if(provider != null) {
return provider.getTableWidget();
@@ -391,9 +525,32 @@ public class SelectColumnsHandler extends AbstractHandler {
return null;
}
+ /**
+ *
+ * @return
+ * the label provider by for the dialog
+ */
private ILabelProvider getLabelProvider() {
- AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ final AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
final ILabelProvider labelProvider = new AdapterFactoryLabelProvider(factory);
return labelProvider;
}
+
+ /**
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param resourceSet
+ * the resource set
+ * @param table
+ * the table
+ * @return
+ * the command factory for these parameters
+ */
+ //TODO duplicated code from the AbstractTriggerListener
+ private static ITableCommandFactory getTableCmdFactory(final TransactionalEditingDomain editingDomain, final ResourceSet resourceSet, final Table table) {
+ final IFacetManager facetManager = IFacetManagerFactory.DEFAULT.getOrCreateFacetManager(resourceSet);
+ final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(editingDomain);
+ return new TableCommandFactory(table, editingDomain, commandFactory, facetManager);
+ }
}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java
index 35b8bf75ddc..1130f7b705d 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2011 CEA LIST.
*
- *
+ *
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,26 +21,28 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Feature;
import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.internal.impl.StereotypeImpl;
/**
* A Content Provider which allows to sort the provided elements
- *
- *
- *
+ *
+ *
+ *
*/
public class SortedColumnContentProvider implements ITreeContentProvider {
@@ -48,16 +50,16 @@ public class SortedColumnContentProvider implements ITreeContentProvider {
private boolean isSorted = true;
/** the initial content */
- private List<Column> initialList = new ArrayList<Column>();
+ private final List<Column> initialList = new ArrayList<Column>();
/** the comparator used to sort the element */
private Comparator<Column> comparator = null;
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
if(newInput instanceof List) {
- for(Object object : (List<?>)newInput) {
+ for(final Object object : (List<?>)newInput) {
if(object instanceof Column) {
- Column column = (Column)object;
+ final Column column = (Column)object;
this.initialList.add(column);
}
}
@@ -79,7 +81,7 @@ public class SortedColumnContentProvider implements ITreeContentProvider {
/**
* Setter for {@link #comparator}
- *
+ *
* @param comparator
* the comparator used to sort the element
*/
@@ -89,15 +91,15 @@ public class SortedColumnContentProvider implements ITreeContentProvider {
/**
* Setter for {@link #isSorted}
- *
+ *
* @param newValue
- *
+ *
*/
public void setIsSorted(final boolean newValue) {
this.isSorted = newValue;
}
- public Object[] getChildren(Object parentElement) {
+ public Object[] getChildren(final Object parentElement) {
if(parentElement instanceof EClass) {
return ((EClass)parentElement).getEAllStructuralFeatures().toArray();
}
@@ -107,33 +109,56 @@ public class SortedColumnContentProvider implements ITreeContentProvider {
if(parentElement instanceof EStructuralFeature) {
return new Object[0];
} else if(parentElement instanceof Stereotype) {
- EList<EStructuralFeature> allRef = ((Stereotype)parentElement).eClass().getEAllStructuralFeatures();
- List<Feature> features = new ArrayList(((Stereotype)parentElement).allFeatures());
+ final EList<EStructuralFeature> allRef = ((Stereotype)parentElement).eClass().getEAllStructuralFeatures();
+ final List<Feature> features = new ArrayList(((Stereotype)parentElement).allFeatures());
Collections.sort(features, new UMLFeatureComparator());
return features.toArray();
}
- if(parentElement instanceof Facet){
+ if(parentElement instanceof Facet) {
return ((Facet)parentElement).getFacetElements().toArray();
}
+ if(parentElement instanceof FacetSet) {
+ final FacetSet facetSet = (FacetSet)parentElement;
+ //TODO sort them
+
+ final Set<ENamedElement> subFacetSet = new TreeSet<ENamedElement>(new EcoreENamedElementComparator());
+
+ try {
+ final EList<EPackage> subPackages = facetSet.getESubpackages();
+ subFacetSet.addAll(subPackages);
+
+ } catch (final Exception e) {
+ final EList<EPackage> subPackages = facetSet.getESubpackages();
+ subFacetSet.addAll(subPackages);
+ }
+ final Set<ENamedElement> subFacets = new TreeSet<ENamedElement>(new EcoreENamedElementComparator());
+ subFacets.addAll(((FacetSet)parentElement).getEClassifiers());
+ //
+ final List<ENamedElement> contents = new ArrayList<ENamedElement>();
+ contents.addAll(subFacetSet);
+ contents.addAll(subFacets);
+ return contents.toArray();
+ }
return new Object[0];
}
- public Object getParent(Object element) {
- if(element instanceof Element){
+ public Object getParent(final Object element) {
+ if(element instanceof Element) {
return ((Element)element).eContainer();
- }else if(element instanceof FacetElement){
+ } else if(element instanceof FacetElement) {
return ((FacetElement)element).eContainer();
}
return null;
}
- public boolean hasChildren(Object element) {
+ public boolean hasChildren(final Object element) {
+ // return true;
return getChildren(element).length != 0;
}
public class EcoreFeatureComparator implements Comparator<EStructuralFeature> {
- public int compare(EStructuralFeature o1, EStructuralFeature o2) {
+ public int compare(final EStructuralFeature o1, final EStructuralFeature o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
@@ -141,7 +166,7 @@ public class SortedColumnContentProvider implements ITreeContentProvider {
public class UMLFeatureComparator implements Comparator<Feature> {
- public int compare(Feature o1, Feature o2) {
+ public int compare(final Feature o1, final Feature o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/StereotypeManagement.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/StereotypeManagement.java
new file mode 100644
index 00000000000..b391744b596
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/StereotypeManagement.java
@@ -0,0 +1,51 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+import org.eclipse.papyrus.uml.efacet.metamodel.umlefacet.ProfileFacetSet;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class StereotypeManagement {
+
+ public StereotypeManagement() {
+
+ }
+
+
+ public List<FacetSet> getAdditionalFeatures(final PapyrusTable papyrusTable, final Collection<EObject> tableContents, final Collection<FacetSet> existingFacetSets) {
+ final Set<Stereotype> appliedStereotypes = new HashSet<Stereotype>();
+ for(final EObject current : tableContents) {
+ if(current instanceof Element) {
+ appliedStereotypes.addAll(((Element)current).getAppliedStereotypes());
+ }
+ }
+
+ final Set<Profile> usedProfile = new HashSet<Profile>();
+ for(final Stereotype current : appliedStereotypes) {
+ usedProfile.add((Profile)PackageUtil.getRootPackage(current));
+ }
+
+ //TODO provides a way to register facetset representing static profile
+
+ //TODO verify that an existing FacetSet doesn't exist for it
+ final List<FacetSet> addtionalFacetSet = new ArrayList<FacetSet>();
+ for(final Profile current : usedProfile) {
+ ProfileFacetSet set = FacetFactory.createProfileFacetSet(current);
+ if(set != null) {
+ addtionalFacetSet.add(set);
+ }
+ }
+
+ return addtionalFacetSet;
+ }
+}

Back to the top