Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse')
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/Activator.java121
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/AbstractTableModelExplorerHandler.java61
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DeleteTableHandler.java71
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DuplicateTableHandler.java82
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/RenameTableHandler.java84
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/Messages.java34
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/messages.properties3
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/providers/TablePropertyTester.java85
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java65
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableIcon.java33
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableName.java31
-rw-r--r--extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java63
12 files changed, 733 insertions, 0 deletions
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/Activator.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/Activator.java
new file mode 100644
index 00000000000..e7433ff7ace
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/Activator.java
@@ -0,0 +1,121 @@
+/*****************************************************************************
+ * 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.modelexplorer;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.edit.EMFEditPlugin;
+import org.eclipse.emf.facet.infra.browser.custom.MetamodelView;
+import org.eclipse.emf.facet.infra.browser.custom.core.CustomizationsCatalog;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizationManager;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.table.modelexplorer"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /** the customization manager */
+ private CustomizationManager fCustomizationManager;
+
+ public static LogHelper log;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ log = new LogHelper(this);
+ EMFEditPlugin.getComposedAdapterFactoryDescriptorRegistry();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ *
+ * @return the customization manager in charge to adapt element in modisco
+ */
+ public CustomizationManager getCustomizationManager() {
+ if(this.fCustomizationManager == null) {
+ this.fCustomizationManager = new CustomizationManager();
+ init(this.fCustomizationManager);
+ }
+ return this.fCustomizationManager;
+ }
+
+ /**
+ *
+ * @param customizationManager
+ * the customization manager to init
+ */
+ private void init(final CustomizationManager customizationManager) {
+ // the appearance can be customized here:
+
+ customizationManager.setShowDerivedLinks(true);
+
+ try {
+
+ // load customizations defined as default through the customization
+ // extension
+ List<MetamodelView> registryDefaultCustomizations = CustomizationsCatalog.getInstance().getRegistryDefaultCustomizations();
+ for(MetamodelView metamodelView : registryDefaultCustomizations) {
+ customizationManager.registerCustomization(metamodelView);
+ }
+ customizationManager.loadCustomizations();
+
+ } catch (Throwable e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error initializing customizations", e)); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/AbstractTableModelExplorerHandler.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/AbstractTableModelExplorerHandler.java
new file mode 100644
index 00000000000..9ff84a43227
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/AbstractTableModelExplorerHandler.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * 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.modelexplorer.handlers;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler;
+import org.eclipse.ui.PlatformUI;
+
+
+public abstract class AbstractTableModelExplorerHandler extends AbstractCommandHandler {
+
+ /**
+ * Returns the list of selected tables
+ *
+ * @return
+ * the list of selected tables
+ */
+ protected List<PapyrusTableInstance> getSelectedTables() {
+ List<PapyrusTableInstance> tables = new ArrayList<PapyrusTableInstance>();
+ ISelection selection = null;
+
+ // Get current selection
+ selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+
+ // Get first element if the selection is an IStructuredSelection
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ Iterator<?> iter = structuredSelection.iterator();
+ while(iter.hasNext()) {
+ Object current = iter.next();
+ if(current instanceof IAdaptable){
+ EObject table = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(table instanceof PapyrusTableInstance){
+ tables.add((PapyrusTableInstance)table);
+ }
+ }
+ }
+ }
+ return tables;
+ }
+
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DeleteTableHandler.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DeleteTableHandler.java
new file mode 100644
index 00000000000..6c9a9372551
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DeleteTableHandler.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * 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.modelexplorer.handlers;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.commands.DestroyElementPapyrusCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+
+/**
+ * Handler for the delete Table action
+ *
+ *
+ *
+ */
+public class DeleteTableHandler extends AbstractTableModelExplorerHandler {
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ final IPageManager pageMngr = getPageManager();
+
+ List<PapyrusTableInstance> tables = getSelectedTables();
+
+ if(editingDomain != null && pageMngr != null && !tables.isEmpty()) {
+ CompoundCommand command = new CompoundCommand();
+
+ for(final PapyrusTableInstance table : tables) {
+ Command sashRemoveComd = new RecordingCommand(editingDomain) {
+
+ @Override
+ protected void doExecute() {
+ pageMngr.removePage(table);
+ }
+ };
+ // the destroy element command is a good way to destroy the cross reference
+ command.append(sashRemoveComd);
+ command.append(new GMFtoEMFCommandWrapper(new DestroyElementPapyrusCommand(new DestroyElementRequest(table.getTable(), false))));
+ command.append(new GMFtoEMFCommandWrapper(new DestroyElementPapyrusCommand(new DestroyElementRequest(table, false))));
+ }
+ return command.isEmpty() ? UnexecutableCommand.INSTANCE : command;
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DuplicateTableHandler.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DuplicateTableHandler.java
new file mode 100644
index 00000000000..2c1d11697b0
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/DuplicateTableHandler.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * 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.modelexplorer.handlers;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.infra.table.modelexplorer.messages.Messages;
+
+/**
+ * This handler provides the duplicate action for the tables
+ *
+ *
+ *
+ */
+public class DuplicateTableHandler extends AbstractTableModelExplorerHandler {
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ final IPageManager pageManager = getPageManager();
+ List<PapyrusTableInstance> tables = getSelectedTables();
+
+ if(editingDomain != null && pageManager != null && !tables.isEmpty()) {
+ CompoundCommand command = new CompoundCommand();
+ for(PapyrusTableInstance table : tables) {
+
+ // Clone the current table
+ final PapyrusTableInstance newTable = EcoreUtil.copy(table);
+
+ // Give a new name
+ newTable.setName(Messages.DuplicateTableHandler_CopyOf + newTable.getName());
+
+ //we duplicate parameters and rename the new table!
+
+
+ Command addGmfDiagramCmd = new AddCommand(editingDomain, table.eResource().getContents(), newTable);
+ // EMFCommandOperation operation = new EMFCommandOperation(editingDomain, addGmfDiagramCmd);
+
+ Command sashOpenCmd = new RecordingCommand(editingDomain, "Open duplicated table") {
+
+ @Override
+ protected void doExecute() {
+ pageManager.openPage(newTable);
+ }
+ };
+ //
+ // // TODO : synchronize with Cedric
+ // command.append(operation.getCommand());
+ command.append(addGmfDiagramCmd);
+ command.append(sashOpenCmd);
+ }
+ return command.isEmpty() ? UnexecutableCommand.INSTANCE : command;
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/RenameTableHandler.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/RenameTableHandler.java
new file mode 100644
index 00000000000..3c007165413
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/handlers/RenameTableHandler.java
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * 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.modelexplorer.handlers;
+
+import java.util.List;
+
+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.UnexecutableCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.infra.table.modelexplorer.messages.Messages;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * This handler provides the method to rename a Table
+ *
+ *
+ *
+ */
+public class RenameTableHandler extends AbstractTableModelExplorerHandler {
+
+
+ /**
+ *
+ * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#getCommand()
+ *
+ * @return
+ */
+ @Override
+ protected Command getCommand() {
+ TransactionalEditingDomain editingDomain = getEditingDomain();
+ List<PapyrusTableInstance> tables = getSelectedTables();
+ if(editingDomain != null && tables.size() == 1) {
+
+ final PapyrusTableInstance table = tables.get(0);
+ final String currentName = table.getName();
+
+ if(currentName != null) {
+
+ AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameTableCommand", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) {
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameTableHandler_RenameAnExistingTable_Title, Messages.RenameTableHandler_NewNameMessage, currentName, null);
+ if(dialog.open() == Window.OK) {
+ final String name = dialog.getValue();
+ if(name != null && name.length() > 0) {
+ table.setName(name);
+ }
+ return CommandResult.newOKCommandResult();
+ } else {
+ return CommandResult.newCancelledCommandResult();
+ }
+ }
+ };
+ return new GMFtoEMFCommandWrapper(cmd);
+ }
+
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+
+
+
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/Messages.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/Messages.java
new file mode 100644
index 00000000000..7fe4c99c629
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/Messages.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * 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.modelexplorer.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.table.modelexplorer.messages.messages"; //$NON-NLS-1$
+
+ public static String DuplicateTableHandler_CopyOf;
+
+ public static String RenameTableHandler_NewNameMessage;
+
+ public static String RenameTableHandler_RenameAnExistingTable_Title;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/messages.properties b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/messages.properties
new file mode 100644
index 00000000000..c5ff485ad7f
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/messages/messages.properties
@@ -0,0 +1,3 @@
+DuplicateTableHandler_CopyOf=Copy of
+RenameTableHandler_NewNameMessage=New name
+RenameTableHandler_RenameAnExistingTable_Title=Rename an existing table
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/providers/TablePropertyTester.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/providers/TablePropertyTester.java
new file mode 100644
index 00000000000..495e63ae231
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/providers/TablePropertyTester.java
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * 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.modelexplorer.providers;
+
+import java.util.Iterator;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+
+/**
+ * This class provides test called by the plugin.xml in order to know if handlers should be active or not.
+ *
+ * Sometimes these test can be done directly in the plugin.xml in the activeWhen (with instanceof, adapt, ...),
+ * but in this case, Eclipse doesn't refresh correctly the status of the command in the menu Edit or in other menu.
+ *
+ *
+ * FIXME : i think this class is not yet used
+ */
+public class TablePropertyTester extends PropertyTester {
+
+
+ /** property to test if the selected elements is a table */
+ public static final String IS_TABLE = "isTable"; //$NON-NLS-1$
+
+
+ /**
+ *
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ *
+ * @param receiver
+ * @param property
+ * @param args
+ * @param expectedValue
+ * @return
+ */
+ public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
+ if(IS_TABLE.equals(property) && receiver instanceof IStructuredSelection) {
+ boolean answer = isTable((IStructuredSelection)receiver);
+ return new Boolean(answer).equals(expectedValue);
+ }
+ return false;
+ }
+
+
+
+ /**
+ * Tests the selection in order to know if it contains only {@link TableInstance}
+ *
+ * @param selection
+ * @return
+ * <code>true</code> if the selection is composed by {@link TableInstance}
+ */
+ private boolean isTable(final IStructuredSelection selection) {
+ if(!selection.isEmpty()) {
+ Iterator<?> iter = selection.iterator();
+ while(iter.hasNext()) {
+ /**
+ * Set to use the IAdaptable mechanism
+ * Used for example for facet elements
+ */
+ final Object next = iter.next();
+ EObject table = EMFHelper.getEObject(next);
+ if(!(table instanceof PapyrusTableInstance)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java
new file mode 100644
index 00000000000..3a902c9dd57
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetContainedTables.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * 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.modelexplorer.queries;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
+import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
+import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
+import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
+
+/** Get the collection of all contained tables */
+//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
+public class GetContainedTables extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Collection<PapyrusTableInstance>> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<PapyrusTableInstance> evaluate(final EObject context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
+ List<PapyrusTableInstance> result = new ArrayList<PapyrusTableInstance>();
+ Iterator<EObject> diRoots = NavigatorUtils.getDiRoots(context);
+ Iterator<EObject> notationRoots = NavigatorUtils.getNotationRoots(context);
+ if(diRoots == null && notationRoots == null) {
+ return result;
+ }
+
+ findTablesInIterator(diRoots, result, context);
+ findTablesInIterator(notationRoots, result, context);
+
+ return result;
+ }
+
+ private void findTablesInIterator(Iterator<EObject> iterator, Collection<PapyrusTableInstance> result, EObject context) {
+ while(iterator.hasNext()) {
+ EObject root = iterator.next();
+ if(root instanceof PapyrusTableInstance) {
+ PapyrusTableInstance tableInstance = (PapyrusTableInstance)root;
+ if(tableInstance.getTable() != null) {
+ if(EcoreUtil.equals(tableInstance.getTable().getContext(), context)) {
+ result.add(tableInstance);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableIcon.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableIcon.java
new file mode 100644
index 00000000000..241afbf5cad
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableIcon.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * 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.modelexplorer.queries;
+
+import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
+import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
+import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.views.modelexplorer.queries.AbstractGetEditorIconQuery;
+
+/** Return the path to the icon of the corresponding table */
+public class GetTableIcon extends AbstractGetEditorIconQuery implements IJavaModelQuery<PapyrusTableInstance, String> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String evaluate(final PapyrusTableInstance context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
+
+ System.out.println("/org.eclipse.papyrus.infra.table.modelexplorer/icons/table.png");
+ return "/org.eclipse.papyrus.infra.table.modelexplorer/icons/table.png";// + getEditorRegistry(context).getEditorURLIcon(context); //$NON-NLS-1$
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableName.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableName.java
new file mode 100644
index 00000000000..a1da86b8526
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/GetTableName.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * 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.modelexplorer.queries;
+
+import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
+import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
+import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+
+/** Return the name for the table */
+public class GetTableName implements IJavaModelQuery<PapyrusTableInstance, String> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String evaluate(final PapyrusTableInstance context, final ParameterValueList parameterValues) throws ModelQueryExecutionException {
+ return context.getName();
+ }
+}
diff --git a/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java
new file mode 100644
index 00000000000..5c7883c5908
--- /dev/null
+++ b/extraplugins/tablemigration/org.eclipse.papyrus.infra.table.modelexplorer/src/org/eclipse/papyrus/infra/table/modelexplorer/queries/IsTableContainer.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * 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.modelexplorer.queries;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.infra.query.core.exception.ModelQueryExecutionException;
+import org.eclipse.emf.facet.infra.query.core.java.IJavaModelQuery;
+import org.eclipse.emf.facet.infra.query.core.java.ParameterValueList;
+import org.eclipse.papyrus.infra.table.instance.papyrustableinstance.PapyrusTableInstance;
+import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
+import org.eclipse.papyrus.views.modelexplorer.queries.AbstractEditorContainerQuery;
+
+/** Returns true if the element contains a Table */
+//FIXME this query is declared using Element in the querySet -> change into EObject when the EMF-Facet bug will be corrected 365744
+public class IsTableContainer extends AbstractEditorContainerQuery implements IJavaModelQuery<EObject, Boolean> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean evaluate(final EObject context, ParameterValueList parameterValues) throws ModelQueryExecutionException {
+ Iterator<EObject> diRoots = NavigatorUtils.getDiRoots(context);
+ if(evaluate(context, diRoots)) {
+ return true;
+ }
+
+ Iterator<EObject> notationRoots = NavigatorUtils.getNotationRoots(context);
+ return evaluate(context, notationRoots);
+ }
+
+ private Boolean evaluate(EObject context, Iterator<EObject> searchIn) {
+ if(searchIn == null) {
+ return false;
+ }
+
+ while(searchIn.hasNext()) {
+ EObject root = searchIn.next();
+ if(root instanceof PapyrusTableInstance) {
+ PapyrusTableInstance tableInstance = (PapyrusTableInstance)root;
+ if(tableInstance.getTable() != null) {
+ if(EcoreUtil.equals(tableInstance.getTable().getContext(), context)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+}

Back to the top