diff options
Diffstat (limited to 'plugins/infra')
2 files changed, 235 insertions, 225 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/AbstractTableCommandHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/AbstractTableCommandHandler.java index 62f0c61e6ef..f94401bb303 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/AbstractTableCommandHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.modelexplorer/src/org/eclipse/papyrus/infra/nattable/modelexplorer/handlers/AbstractTableCommandHandler.java @@ -1,59 +1,62 @@ -/*****************************************************************************
- * Copyright (c) 2013 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:
- * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.nattable.modelexplorer.handlers;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
-import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler;
-import org.eclipse.ui.PlatformUI;
-
-public abstract class AbstractTableCommandHandler extends AbstractCommandHandler {
-
- /**
- * Returns the list of selected tables
- *
- * @return the list of selected tables
- */
- protected List<Table> getSelectedTables() {
- List<Table> tables = new ArrayList<Table>();
- 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();
- /**
- * Get the table object. This getElement is used in order to
- * use IAdaptable mechanisme For example for Facet Elements
- */
- EObject table = NavigatorUtils.getElement(current, EObject.class);
- if(table instanceof Table) {
- tables.add((Table)table);
- }
- }
- }
-
- return tables;
- }
-}
+/***************************************************************************** + * Copyright (c) 2013 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: + * Juan Cadavid (CEA LIST) juan.cadavid@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.infra.nattable.modelexplorer.handlers; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils; +import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +public abstract class AbstractTableCommandHandler extends AbstractCommandHandler { + + /** + * Returns the list of selected tables + * + * @return the list of selected tables + */ + protected List<Table> getSelectedTables() { + List<Table> tables = new ArrayList<Table>(); + ISelection selection = null; + + // Get current selection + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (activeWorkbenchWindow != null) { + selection = activeWorkbenchWindow.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(); + /** + * Get the table object. This getElement is used in order to + * use IAdaptable mechanisme For example for Facet Elements + */ + EObject table = NavigatorUtils.getElement(current, EObject.class); + if(table instanceof Table) { + tables.add((Table)table); + } + } + } + } + return tables; + } +} diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/handler/AbstractCommandHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/handler/AbstractCommandHandler.java index 61a73d76cbf..1ba02c6757a 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/handler/AbstractCommandHandler.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.validation/src/org/eclipse/papyrus/infra/services/validation/handler/AbstractCommandHandler.java @@ -1,166 +1,173 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- *
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
- *****************************************************************************/
-package org.eclipse.papyrus.infra.services.validation.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <pre>
- *
- * This abstract command handler manages:
- * - current selection in order to build a list of the selected {@link EObject}
- * - execute the command (returned by children)
- * - calculate the command enablement and visibility regarding the command executability
- * (the command is now shown in menu if not executable).
- *
- * </pre>
- */
-public abstract class AbstractCommandHandler extends AbstractHandler {
-
- /**
- * <pre>
- *
- * Returns the command to execute (to be implemented
- * in children implementing this class)
- *
- * @return the command to execute
- *
- * </pre>
- */
- protected abstract Command getCommand();
-
- /**
- * <pre>
- * Get the selected element, the first selected element if several are selected or null
- * if no selection or the selection is not an {@link EObject}.
- *
- * @return selected {@link EObject} or null
- * </pre>
- *
- */
- protected EObject getSelectedElement() {
- EObject eObject = null;
- Object 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;
- selection = structuredSelection.getFirstElement();
- }
-
- // Treat non-null selected object (try to adapt and return EObject)
- if(selection != null) {
- if(selection instanceof IAdaptable) {
- selection = EMFHelper.getEObject(selection);
- }
-
- Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(selection);
- if(businessObject instanceof EObject) {
- eObject = (EObject)businessObject;
- }
- }
- return eObject;
- }
-
- /**
- * <pre>
- * Parse current selection and extract the list of {@link EObject} from
- * this selection.
- *
- * This also tries to adapt selected element into {@link EObject}
- * (for example to get the {@link EObject} from a selection in the ModelExplorer).
- *
- * @return a list of currently selected {@link EObject}
- * </pre>
- *
- */
- protected List<EObject> getSelectedElements() {
-
- List<EObject> selectedEObjects = new ArrayList<EObject>();
-
- // Parse current selection
- ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- for(Object current : structuredSelection.toArray()) {
- // Adapt current selection to EObject
- if(current instanceof IAdaptable) {
- selectedEObjects.add(EMFHelper.getEObject(current));
- }
- }
- } else { // Not a IStructuredSelection
- if(selection != null) {
- // Adapt current selection to EObject
- if(selection instanceof IAdaptable) {
- selectedEObjects.add(EMFHelper.getEObject(selection));
- }
- }
- }
-
- return selectedEObjects;
- }
-
- /**
- *
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- *
- * @param event
- * @return null
- * @throws ExecutionException
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- // try {
- // ServiceUtilsForActionHandlers util = new ServiceUtilsForActionHandlers();
- // util.getTransactionalEditingDomain().getCommandStack().execute(getCommand());
- //
- // } catch (ServiceException e) {
- // Activator.log.error("Unexpected error while executing command.", e); //$NON-NLS-1$
- // }
-
- getCommand().execute(); //Validation commands should not be executed in the stack trace
-
- return null;
- }
- @Override
- public void setEnabled(Object evaluationContext) {
- setBaseEnabled(getCommand().canExecute());
- }
-
- /**
- *
- * @return true (visible) when the command can be executed.
- */
- public boolean isVisible() {
- return getCommand().canExecute();
- }
-
-
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * + * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation + * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.infra.services.validation.handler; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * <pre> + * + * This abstract command handler manages: + * - current selection in order to build a list of the selected {@link EObject} + * - execute the command (returned by children) + * - calculate the command enablement and visibility regarding the command executability + * (the command is now shown in menu if not executable). + * + * </pre> + */ +public abstract class AbstractCommandHandler extends AbstractHandler { + + /** + * <pre> + * + * Returns the command to execute (to be implemented + * in children implementing this class) + * + * @return the command to execute + * + * </pre> + */ + protected abstract Command getCommand(); + + /** + * <pre> + * Get the selected element, the first selected element if several are selected or null + * if no selection or the selection is not an {@link EObject}. + * + * @return selected {@link EObject} or null + * </pre> + * + */ + protected EObject getSelectedElement() { + EObject eObject = null; + Object selection = null; + + + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (activeWorkbenchWindow != null){ + // Get current selection + selection = activeWorkbenchWindow.getSelectionService().getSelection(); + + // Get first element if the selection is an IStructuredSelection + if(selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + selection = structuredSelection.getFirstElement(); + } + + // Treat non-null selected object (try to adapt and return EObject) + if(selection != null) { + if(selection instanceof IAdaptable) { + selection = EMFHelper.getEObject(selection); + } + + Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(selection); + if(businessObject instanceof EObject) { + eObject = (EObject)businessObject; + } + } + } + return eObject; + } + + /** + * <pre> + * Parse current selection and extract the list of {@link EObject} from + * this selection. + * + * This also tries to adapt selected element into {@link EObject} + * (for example to get the {@link EObject} from a selection in the ModelExplorer). + * + * @return a list of currently selected {@link EObject} + * </pre> + * + */ + protected List<EObject> getSelectedElements() { + + List<EObject> selectedEObjects = new ArrayList<EObject>(); + + // Parse current selection + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (activeWorkbenchWindow != null){ + ISelection selection = activeWorkbenchWindow.getSelectionService().getSelection(); + if(selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + for(Object current : structuredSelection.toArray()) { + // Adapt current selection to EObject + if(current instanceof IAdaptable) { + selectedEObjects.add(EMFHelper.getEObject(current)); + } + } + } else { // Not a IStructuredSelection + if(selection != null) { + // Adapt current selection to EObject + if(selection instanceof IAdaptable) { + selectedEObjects.add(EMFHelper.getEObject(selection)); + } + } + } + } + return selectedEObjects; + } + + /** + * + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + * + * @param event + * @return null + * @throws ExecutionException + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + // try { + // ServiceUtilsForActionHandlers util = new ServiceUtilsForActionHandlers(); + // util.getTransactionalEditingDomain().getCommandStack().execute(getCommand()); + // + // } catch (ServiceException e) { + // Activator.log.error("Unexpected error while executing command.", e); //$NON-NLS-1$ + // } + + getCommand().execute(); //Validation commands should not be executed in the stack trace + + return null; + } + @Override + public void setEnabled(Object evaluationContext) { + setBaseEnabled(getCommand().canExecute()); + } + + /** + * + * @return true (visible) when the command can be executed. + */ + public boolean isVisible() { + return getCommand().canExecute(); + } + + +} |