diff options
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java')
-rw-r--r-- | plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java b/plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java index 0562c833474..69d44eb0671 100644 --- a/plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java +++ b/plugins/facet/org.eclipse.papyrus.emf.facet.util.emf.ui/src/org/eclipse/papyrus/emf/facet/util/emf/ui/internal/handler/SaveAsHandler.java @@ -1,100 +1,100 @@ -/**
- * Copyright (c) 2013 Mia-Software.
- *
- * 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:
- * Gregoire Dupe (Mia-Software) - Bug 406570 - Handlers to Save and SaveAs EMF resources
- */
-package org.eclipse.papyrus.emf.facet.util.emf.ui.internal.handler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.commands.IHandlerListener;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.papyrus.emf.facet.util.emf.ui.internal.ResourceUiUtils;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-public class SaveAsHandler implements IHandler {
-
- @Override
- public void addHandlerListener(final IHandlerListener handlerListener) {
- // Nothing to do
- }
-
- @Override
- public void dispose() {
- // Nothing to do
- }
-
- @Override
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- final Shell shell = HandlerUtil.getActiveShell(event);
- for (Object object : getSelection()) {
- if (object instanceof Resource) {
- final Resource resource = (Resource) object;
- ResourceUiUtils.openSaveAsDialog(resource, shell);
- } else if (object instanceof IAdaptable) {
- final IAdaptable adaptable = (IAdaptable) object;
- final Resource resource = (Resource) adaptable
- .getAdapter(Resource.class);
- if (resource != null) {
- ResourceUiUtils.openSaveAsDialog(resource, shell);
- }
- }
- }
- return null;
- }
-
- @Override
- public boolean isEnabled() {
- return true;
- }
-
- @Override
- public boolean isHandled() {
- return isEnabled();
- }
-
- @Override
- public void removeHandlerListener(final IHandlerListener handlerListener) {
- // Nothing to do
- }
-
- private static <E> List<E> getSelection() {
- final List<E> result = new ArrayList<E>();
- final IWorkbenchWindow wWindow = getActiveWindow();
- final ISelectionService selectService = wWindow.getSelectionService();
- final ISelection selection = selectService.getSelection();
- if (selection instanceof StructuredSelection) {
- final StructuredSelection structS = (StructuredSelection) selection;
- @SuppressWarnings("unchecked")
- // @SuppressWarnings This cast is unsafe but the framework does not
- // provide other way to do
- final List<E> list = structS.toList();
- result.addAll(list);
- }
- return result;
- }
-
- private static IWorkbenchWindow getActiveWindow() {
- final IWorkbench workbench = PlatformUI.getWorkbench();
- return workbench.getActiveWorkbenchWindow();
- }
-
-}
+/** + * Copyright (c) 2013 Mia-Software. + * + * 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: + * Gregoire Dupe (Mia-Software) - Bug 406570 - Handlers to Save and SaveAs EMF resources + */ +package org.eclipse.papyrus.emf.facet.util.emf.ui.internal.handler; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.emf.facet.util.emf.ui.internal.ResourceUiUtils; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +public class SaveAsHandler implements IHandler { + + @Override + public void addHandlerListener(final IHandlerListener handlerListener) { + // Nothing to do + } + + @Override + public void dispose() { + // Nothing to do + } + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + final Shell shell = HandlerUtil.getActiveShell(event); + for (Object object : getSelection()) { + if (object instanceof Resource) { + final Resource resource = (Resource) object; + ResourceUiUtils.openSaveAsDialog(resource, shell); + } else if (object instanceof IAdaptable) { + final IAdaptable adaptable = (IAdaptable) object; + final Resource resource = (Resource) adaptable + .getAdapter(Resource.class); + if (resource != null) { + ResourceUiUtils.openSaveAsDialog(resource, shell); + } + } + } + return null; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return isEnabled(); + } + + @Override + public void removeHandlerListener(final IHandlerListener handlerListener) { + // Nothing to do + } + + private static <E> List<E> getSelection() { + final List<E> result = new ArrayList<E>(); + final IWorkbenchWindow wWindow = getActiveWindow(); + final ISelectionService selectService = wWindow.getSelectionService(); + final ISelection selection = selectService.getSelection(); + if (selection instanceof StructuredSelection) { + final StructuredSelection structS = (StructuredSelection) selection; + @SuppressWarnings("unchecked") + // @SuppressWarnings This cast is unsafe but the framework does not + // provide other way to do + final List<E> list = structS.toList(); + result.addAll(list); + } + return result; + } + + private static IWorkbenchWindow getActiveWindow() { + final IWorkbench workbench = PlatformUI.getWorkbench(); + return workbench.getActiveWorkbenchWindow(); + } + +} |