Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportAllDiagrams.java417
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportException.java61
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/Messages.java73
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/PropertyTester.java25
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsAction.java95
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsDialog.java68
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportComposite.java199
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/Messages.java36
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/messages.properties5
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/internal/Activator.java205
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/messages.properties24
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportAllWizard.java131
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsErrorPage.java44
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsPage.java54
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/Messages.java38
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/messages.properties6
16 files changed, 1481 insertions, 0 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportAllDiagrams.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportAllDiagrams.java
new file mode 100644
index 00000000000..ccd8fcddb60
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportAllDiagrams.java
@@ -0,0 +1,417 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Anyware Technologies. 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: Jacques Lescot (Anyware Technologies) - initial API and
+ * implementation
+ * Thibault Landre (Atos Origin) - refactor to extract the exportAllDiagram from ExportAllDiagramsAction
+ * Alexia Allanic (Atos Origin) - Add margin to not truncate images
+ * Anass Radouani (AtoS) - add use GMF exporting tool and remove manual extraction
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.export;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalCommandStack;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain.Factory;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.image.ImageFileFormat;
+import org.eclipse.gmf.runtime.diagram.ui.render.util.CopyToImageUtil;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.emf.common.ui.dialogs.DiagnosticDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.export.internal.Activator;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+public class ExportAllDiagrams {
+
+ private IFile file;
+
+ private String extension;
+
+ private String outputDirectoryPath;
+
+ private IWorkbenchWindow workbenchWindow;
+
+ private boolean displayRenamingInformation;
+
+ private static boolean useDisplayRunnable = true;
+
+ private boolean qualifiedName;
+
+ private BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.OK, "", 0, Messages.ExportAllDiagrams_18, null); //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param file
+ * the *.*di file where the diagrams are stored, can be null if
+ * you use export method with diagrams in parameter
+ * @param outputDirectoryPath
+ * the directory in which the images will be saved
+ * @param extension
+ * the image extension
+ * @param imageExporter
+ * the image exporter used. The image exporter should be coherent
+ * with the file extension
+ */
+ public ExportAllDiagrams(IFile file, String outputDirectoryPath, String extension, boolean qualifiedName) {
+ this.file = file;
+ this.extension = extension;
+ this.outputDirectoryPath = outputDirectoryPath;
+ try {
+ this.workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ } catch (IllegalStateException e) {
+ this.workbenchWindow = null;
+ // is normal in batch mode
+ }
+ this.displayRenamingInformation = true;
+ this.qualifiedName = qualifiedName;
+ }
+
+ /**
+ * Run the export of all diagrams of a *.*di file into images in the given
+ * format.
+ */
+ public void exportDiagramsToImages() {
+ final IRunnableWithProgress op = new WorkspaceModifyOperation() {
+
+ @Override
+ protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
+ if(monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ final IProgressMonitor newMonitor = monitor;
+ export(newMonitor);
+ }
+
+ };
+ Job job = new Job(Messages.ExportAllDiagrams_0) {
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ try {
+ op.run(monitor);
+ } catch (InvocationTargetException e) {
+ } catch (InterruptedException e) {
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+
+ }
+
+ /**
+ * Export all diagrams of the IFile
+ *
+ * @param newMonitor
+ */
+ private void export(IProgressMonitor newMonitor) {
+ // Then iterates on all the diagrams and export them one by one
+ newMonitor.beginTask(Messages.ExportAllDiagrams_1, 10);
+ newMonitor.subTask(Messages.ExportAllDiagrams_2);
+ if(file != null) {
+ final ResourceSetImpl resourceSet = new ResourceSetImpl();
+ resourceSet.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
+ resourceSet.getLoadOptions().put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
+ resourceSet.getResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true), true);
+
+ // create transactional editing domain
+
+ TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resourceSet);
+ if(editingDomain == null) {
+ Factory factory = TransactionalEditingDomain.Factory.INSTANCE;
+ editingDomain = factory.createEditingDomain(resourceSet);
+ }
+
+ AbstractTransactionalCommand com = new AbstractTransactionalCommand(editingDomain, "Resolve", Collections.emptyList()) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ EcoreUtil.resolveAll(resourceSet);
+ return null;
+ }
+ };
+
+ // bypass all the transaction/validate/notification mechanisms, it is a lot faster and it has no impact
+ // since we do not modify the model
+ CommandStack commandStack = editingDomain.getCommandStack();
+ if(commandStack instanceof TransactionalCommandStack) {
+ TransactionalCommandStack stack = (TransactionalCommandStack)commandStack;
+ Map<Object, Object> options = new HashMap<Object, Object>();
+ options.put(Transaction.OPTION_NO_NOTIFICATIONS, Boolean.TRUE);
+ options.put(Transaction.OPTION_NO_UNDO, Boolean.TRUE);
+ options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
+ options.put(Transaction.OPTION_IS_UNDO_REDO_TRANSACTION, Boolean.FALSE);
+ options.put(Transaction.OPTION_NO_TRIGGERS, Boolean.TRUE);
+ options.put(Transaction.OPTION_VALIDATE_EDIT, Boolean.FALSE);
+ options.put(Transaction.OPTION_VALIDATE_EDIT_CONTEXT, Boolean.FALSE);
+ try {
+ stack.execute(new GMFtoEMFCommandWrapper(com), options);
+ } catch (InterruptedException e) {
+ } catch (RollbackException e) {
+ }
+ } else {
+ Activator.log("no transactional editing domain found", Status.WARNING);
+ }
+
+ List<Diagram> diagrams = new ArrayList<Diagram>();
+ if(newMonitor.isCanceled()) {
+ return;
+ }
+ for(Iterator<Notifier> i = resourceSet.getAllContents(); i.hasNext();) {
+ Notifier n = i.next();
+ if(n instanceof Diagram) {
+ diagrams.add((Diagram)n);
+ }
+ }
+ if(newMonitor.isCanceled()) {
+ return;
+ }
+ newMonitor.worked(1);
+ export(new SubProgressMonitor(newMonitor, 9), diagrams);
+ } else {
+ Activator.log(new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.ExportAllDiagrams_3));
+ }
+
+ }
+
+ /**
+ * export all the diagrams in image
+ *
+ * @param newMonitor
+ * , the monitor
+ * @param diagrams
+ * , the emf element diagrams
+ */
+ public void export(IProgressMonitor newMonitor, List<Diagram> diagrams) {
+ boolean duplicates;
+ newMonitor.beginTask(Messages.ExportAllDiagrams_4, 10);
+ duplicates = createDiagramFiles(new SubProgressMonitor(newMonitor, 9), diagrams);
+ unloadResources(new SubProgressMonitor(newMonitor, 1), diagrams);
+
+ // Alert the user that file names have been changed to avoid duplicates
+ if(duplicates && displayRenamingInformation) {
+
+ final String message = Messages.ExportAllDiagrams_5;
+ if(workbenchWindow != null && workbenchWindow.getShell() != null) {
+
+ BasicDiagnostic newDiagnostic = new BasicDiagnostic(Diagnostic.WARNING, "", 0, message, null); //$NON-NLS-1$
+ diagnostic.add(newDiagnostic);
+
+ } else {
+ Activator.log(new Status(Status.INFO, Activator.PLUGIN_ID, message));
+ }
+
+ }
+ int severity = diagnostic.recomputeSeverity();
+ if(severity == Diagnostic.ERROR) {
+ BasicDiagnostic oldDiagnostic = diagnostic;
+ diagnostic = new BasicDiagnostic(Diagnostic.ERROR, "", 0, Messages.ExportAllDiagrams_22, null); //$NON-NLS-1$
+ diagnostic.addAll(oldDiagnostic);
+ } else if(severity == Diagnostic.WARNING) {
+ BasicDiagnostic oldDiagnostic = diagnostic;
+ diagnostic = new BasicDiagnostic(Diagnostic.WARNING, "", 0, Messages.ExportAllDiagrams_24, null); //$NON-NLS-1$
+ diagnostic.addAll(oldDiagnostic);
+ } else if(severity == Diagnostic.OK) {
+ if(workbenchWindow != null && workbenchWindow.getShell() != null) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openInformation(Activator.getActiveWorkbenchShell(), Messages.ExportAllDiagrams_25, Messages.ExportAllDiagrams_26 + outputDirectoryPath);
+ }
+ });
+ }
+ }
+
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ DiagnosticDialog.open(Activator.getActiveWorkbenchShell(), Messages.ExportAllDiagrams_27, "", diagnostic); //$NON-NLS-2$
+ }
+ });
+
+ }
+
+ /**
+ * Browse all the diagrams and export them
+ *
+ * @param newMonitor
+ * @param findAllDiagrams
+ * @return
+ */
+ private boolean createDiagramFiles(final IProgressMonitor newMonitor, List<Diagram> diagrams) {
+ boolean duplicates = false;
+ boolean nameCut = false;
+ try {
+ List<String> diagramNames = new ArrayList<String>();
+ try {
+ newMonitor.beginTask(Messages.ExportAllDiagrams_7, diagrams.size());
+ for(final Diagram diagram : diagrams) {
+ if(newMonitor.isCanceled()) {
+ break;
+ }
+ String label = ""; //$NON-NLS-1$
+ if(qualifiedName) {
+ ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ composedAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
+ IItemLabelProvider itemLabelFactory = (IItemLabelProvider)composedAdapterFactory.adapt(diagram.getElement(), IItemLabelProvider.class);
+ label = itemLabelFactory.getText(diagram.getElement()).replace(Messages.ExportAllDiagrams_16, "") + "_"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+ String uniqueFileName = encodeFileName(label + diagram.getName());
+ if(uniqueFileName.length() > 150) {
+ nameCut = true;
+ uniqueFileName = uniqueFileName.substring(0, 150);
+ }
+ if(diagramNames.contains(uniqueFileName)) {
+ duplicates = true;
+ uniqueFileName = getFirstAvailableName(uniqueFileName, diagramNames, 1);
+ }
+
+ if(nameCut) {
+
+ BasicDiagnostic newDiagnostic = new BasicDiagnostic(Diagnostic.WARNING, "", 0, Messages.ExportAllDiagrams_10 + uniqueFileName, null); //$NON-NLS-1$
+ diagnostic.add(newDiagnostic);
+
+ nameCut = false;
+ }
+
+ final String finalUniqueFileName = uniqueFileName;
+ diagramNames.add(uniqueFileName);
+ newMonitor.subTask(Messages.ExportAllDiagrams_8 + uniqueFileName);
+ if(useDisplayRunnable) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ exportDiagram(finalUniqueFileName, diagram, newMonitor);
+ }
+ });
+ } else {
+ exportDiagram(uniqueFileName, diagram, newMonitor);
+ }
+ newMonitor.worked(1);
+ }
+ } catch (SWTError e) {
+ String message = Messages.ExportAllDiagrams_9;
+ Activator.log(new Exception(message, e));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return duplicates;
+ }
+
+ private void exportDiagram(String uniqueFileName, Diagram diagram, IProgressMonitor newMonitor) {
+ CopyToImageUtil copyImageUtil = new CopyToImageUtil();
+ try {
+ copyImageUtil.copyToImage(diagram, new Path(outputDirectoryPath + File.separator + uniqueFileName + "." //$NON-NLS-1$
+ + ImageFileFormat.resolveImageFormat(extension)), ImageFileFormat.resolveImageFormat(extension), new SubProgressMonitor(newMonitor, 1), PreferencesHint.USE_DEFAULTS);
+ } catch (Throwable e) {
+ BasicDiagnostic newDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, "", 0, String.format(Messages.ExportAllDiagrams_11, uniqueFileName, diagram.eResource().getURI().toString()), null); //$NON-NLS-1$
+ diagnostic.add(newDiagnostic);
+ Activator.log(String.format(Messages.ExportAllDiagrams_11, uniqueFileName, diagram.eResource().getURI().toString()), IStatus.ERROR, e);
+ }
+ }
+
+ public void unloadResources(IProgressMonitor newMonitor, List<Diagram> diagrams) {
+ if(newMonitor == null) {
+ newMonitor = new NullProgressMonitor();
+ }
+ newMonitor.subTask(Messages.ExportAllDiagrams_12);
+ if(diagrams != null && !diagrams.isEmpty()) {
+ ResourceSet resourceSet2 = diagrams.get(0).eResource().getResourceSet();
+ newMonitor.beginTask(Messages.ExportAllDiagrams_13, resourceSet2.getResources().size());
+ for(int i = resourceSet2.getResources().size() - 1; i >= 0; i--) {
+ try {
+ Resource r = resourceSet2.getResources().get(i);
+ if(r.isLoaded()) {
+ r.unload();
+ }
+ } catch (Exception e) {
+ // not very clean but it sometimes occurs
+ }
+ newMonitor.worked(1);
+ }
+ }
+
+ }
+
+ /**
+ * Escape all characters that may result in a wrong file name
+ *
+ * @param pathName
+ * a file name to encode
+ * @return The encoded file name
+ */
+ private String encodeFileName(String pathName) {
+ pathName = pathName.trim();
+ pathName = pathName.replaceAll(Messages.ExportAllDiagrams_14, Messages.ExportAllDiagrams_15);
+ pathName = pathName.replaceAll("_-_", "-"); //$NON-NLS-1$ //$NON-NLS-2$
+ while(pathName.contains("__")) { //$NON-NLS-1$
+ pathName = pathName.replaceAll("__", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if(pathName.startsWith("_")) { //$NON-NLS-1$
+ pathName = pathName.replaceFirst("_", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if(pathName.endsWith("_")) { //$NON-NLS-1$
+ pathName = pathName.substring(0, pathName.length() - 1);
+ }
+
+ return pathName;
+ // return URLEncoder.encode(pathName, "UTF-8").replaceAll("[*]", "_");
+ }
+
+ private String getFirstAvailableName(String commonBasis, List<String> existingNames, int cpt) {
+ if(existingNames.contains(commonBasis + cpt)) {
+ return getFirstAvailableName(commonBasis, existingNames, cpt + 1);
+ }
+ return commonBasis + cpt;
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportException.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportException.java
new file mode 100644
index 00000000000..d61d51ef6f7
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/ExportException.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Anyware Technologies
+ * 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:
+ * David Sciamma (Anyware Technologies) - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export;
+
+/**
+ * Exception raised during an image export
+ *
+ * @author <a href="david.sciamma@anyware-tech.com">David Sciamma</a>
+ */
+public class ExportException extends Exception {
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 5787608979737224951L;
+
+ /**
+ * Constructor
+ */
+ public ExportException() {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message
+ */
+ public ExportException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param cause
+ */
+ public ExportException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message
+ * @param cause
+ */
+ public ExportException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/Messages.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/Messages.java
new file mode 100644
index 00000000000..b6d0f1eeb8a
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/Messages.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.export;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.export.messages"; //$NON-NLS-1$
+
+ public static String ExportAllDiagrams_0;
+
+ public static String ExportAllDiagrams_1;
+
+ public static String ExportAllDiagrams_10;
+
+ public static String ExportAllDiagrams_11;
+
+ public static String ExportAllDiagrams_12;
+
+ public static String ExportAllDiagrams_13;
+
+ public static String ExportAllDiagrams_14;
+
+ public static String ExportAllDiagrams_15;
+
+ public static String ExportAllDiagrams_16;
+
+ public static String ExportAllDiagrams_18;
+
+ public static String ExportAllDiagrams_2;
+
+ public static String ExportAllDiagrams_20;
+
+ public static String ExportAllDiagrams_22;
+
+ public static String ExportAllDiagrams_24;
+
+ public static String ExportAllDiagrams_25;
+
+ public static String ExportAllDiagrams_26;
+
+ public static String ExportAllDiagrams_27;
+
+ public static String ExportAllDiagrams_3;
+
+ public static String ExportAllDiagrams_4;
+
+ public static String ExportAllDiagrams_5;
+
+ public static String ExportAllDiagrams_6;
+
+ public static String ExportAllDiagrams_7;
+
+ public static String ExportAllDiagrams_8;
+
+ public static String ExportAllDiagrams_9;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/PropertyTester.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/PropertyTester.java
new file mode 100644
index 00000000000..da6e700a53b
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/PropertyTester.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS) - test property to enable or disable Export All menu item
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export;
+
+import org.eclipse.papyrus.infra.export.actions.ExportAllDiagramsAction;
+
+public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if("isFileExportable".equals(property) || "isCollectionExportable".equals(property)) {
+ return ExportAllDiagramsAction.getIFile(receiver) != null;
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsAction.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsAction.java
new file mode 100644
index 00000000000..5b864bb6795
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsAction.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Anyware Technologies. 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: Jacques Lescot (Anyware Technologies) - initial API and
+ * implementation
+ * Anass RADOUANI (AtoS) - add verification of the selection if it is
+ * a papyrus file or not
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.export.actions;
+
+import java.util.Collection;
+
+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.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.export.ExportAllDiagrams;
+import org.eclipse.papyrus.infra.export.internal.Activator;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class ExportAllDiagramsAction extends AbstractHandler {
+
+ /**
+ * Try to retrieve the selected file from the given selection
+ *
+ * @param sel
+ * the selection
+ * @return the selected file
+ */
+ private IFile convertSelection2File(ISelection sel) {
+ // get the selected diagrams file
+ if(sel instanceof IStructuredSelection) {
+ IStructuredSelection ssel = (IStructuredSelection)sel;
+ // Only one file should be selected
+ if(!ssel.isEmpty() && ssel.size() == 1) {
+ Object selectedObj = ssel.getFirstElement();
+ return getIFile(selectedObj);
+ }
+ }
+ return null;
+ }
+
+ public static IFile getIFile(Object selectedObj) {
+ IFile result = null;
+ if(selectedObj instanceof IFile) {
+ result = (IFile)selectedObj;
+ }
+ // Try to adapt
+ if(result == null && selectedObj instanceof IAdaptable) {
+ result = (IFile)((IAdaptable)selectedObj).getAdapter(IFile.class);
+ }
+ // adapt in ifile
+ if(result == null) {
+ result = (IFile)Platform.getAdapterManager().getAdapter(selectedObj, IFile.class);
+ }
+ if(result == null) {
+ // try to check if it is a collection
+ Collection<?> collec = (Collection<?>)Platform.getAdapterManager().getAdapter(selectedObj, Collection.class);
+ if(collec != null) {
+ for(Object o : collec) {
+ if(o instanceof IFile) {
+ IFile f = (IFile)o;
+ if("di".equals(f.getFileExtension())) {
+ result = f;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return result != null && "di".equals(result.getFileExtension()) ? result : null;
+ }
+
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getActiveMenuSelection(event);
+ ExportAllDiagramsDialog exportPopup = new ExportAllDiagramsDialog(Activator.getActiveWorkbenchShell(), convertSelection2File(selection));
+ if(exportPopup.open() == Window.OK) {
+ final IFile file = convertSelection2File(selection);
+ ExportAllDiagrams exportAllDiagrams;
+ exportAllDiagrams = new ExportAllDiagrams(file, exportPopup.getOutputDirectory().getLocation().toString(), exportPopup.getExporter(), exportPopup.getQualifiedName());
+ exportAllDiagrams.exportDiagramsToImages();
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsDialog.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsDialog.java
new file mode 100644
index 00000000000..20c8960f7a0
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportAllDiagramsDialog.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Anyware Technologies. 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: Jacques Lescot (Anyware Technologies) - initial API and
+ * implementation
+ * Anass Radouani (AtoS) - use of ExporterManager removed
+ ******************************************************************************/
+package org.eclipse.papyrus.infra.export.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ *
+ * Creation 24 sept. 07
+ *
+ * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
+ */
+public class ExportAllDiagramsDialog extends Dialog {
+
+ private ExportComposite dialogComposite;
+
+ private IFile selectedDiagramFile;
+
+
+ /**
+ * @param parentShell
+ * @param selectedFile
+ */
+ public ExportAllDiagramsDialog(Shell parentShell, IFile selectedFile) {
+ super(parentShell);
+ selectedDiagramFile = selectedFile;
+ setBlockOnOpen(true);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite)super.createDialogArea(parent);
+ dialogComposite = new ExportComposite(composite, SWT.NONE);
+ dialogComposite.setSelectedDiagramFile(selectedDiagramFile);
+ return composite;
+ }
+
+ public IResource getOutputDirectory() {
+ return dialogComposite.getOutputDirectory();
+ }
+
+ public String getExporter() {
+ return dialogComposite.getExporter();
+ }
+
+ public boolean getQualifiedName() {
+ return dialogComposite.getQualifiedName();
+ }
+
+
+
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportComposite.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportComposite.java
new file mode 100644
index 00000000000..ee3eafb5d29
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/ExportComposite.java
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.gmf.runtime.diagram.ui.image.ImageFileFormat;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.export.internal.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * ExportAll configuration windows
+ */
+public class ExportComposite extends Composite {
+
+ // SWT Objects
+ private Text outputPathTxt;
+
+ private Button outputDirectoryBtn;
+
+ private Combo outputFormatCb;
+
+ private Button btnCheckButton;
+
+ // Configured items
+ protected IResource outputDirectory;
+
+ protected String exporter;
+
+ protected boolean qualifiedName;
+
+ private IFile selectedDiagramFile;
+
+ /**
+ * Constructor
+ *
+ * @param parent
+ * @param style
+ */
+ public ExportComposite(Composite parent, int style) {
+ super(parent, style);
+ createDialogComposite();
+ createDialogContents();
+ hookListeners();
+ }
+
+ /**
+ * Create the view of the list of interaction operators
+ *
+ * @param parent
+ * the parent composite to contain this group
+ */
+ protected void createDialogContents() {
+ Composite composite = new Composite(this, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ composite.setLayout(layout);
+ composite.setFont(this.getFont());
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Label editorConfLbl = new Label(composite, SWT.NONE);
+ editorConfLbl.setText(Messages.ExportAllDiagramsDialog_0);
+ outputPathTxt = new Text(composite, SWT.BORDER);
+ outputPathTxt.setEnabled(false);
+ outputPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ outputDirectoryBtn = new Button(composite, SWT.NONE);
+ outputDirectoryBtn.setText(Messages.ExportAllDiagramsDialog_1);
+
+ Label outputFormatLbl = new Label(composite, SWT.NONE);
+ outputFormatLbl.setText(Messages.ExportAllDiagramsDialog_2);
+
+ outputFormatCb = new Combo(composite, SWT.NONE);
+ GridData gridData2 = new GridData(GridData.FILL_HORIZONTAL);
+ gridData2.horizontalSpan = 2;
+ outputFormatCb.setLayoutData(gridData2);
+
+ btnCheckButton = new Button(this, SWT.CHECK);
+ btnCheckButton.setText(Messages.ExportAllDiagramsDialog_btnCheckButton_text);
+
+ }
+
+ /**
+ * Create the Dialog Contents
+ */
+ private void createDialogComposite() {
+ GridLayout dialogLayout = new GridLayout();
+ GridData dialogLayoutData = new GridData(GridData.FILL_BOTH);
+ this.setLayout(dialogLayout);
+ this.setLayoutData(dialogLayoutData);
+ }
+
+ private void hookListeners() {
+ btnCheckButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ qualifiedName = btnCheckButton.getSelection();
+ }
+ });
+
+ outputDirectoryBtn.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ ContainerSelectionDialog csDialog = new ContainerSelectionDialog(Activator.getActiveWorkbenchShell(), ResourcesPlugin.getWorkspace().getRoot(), true, Messages.ExportAllDiagramsDialog_3);
+
+
+ if(csDialog.open() == Window.OK) {
+ Object[] results = csDialog.getResult();
+ if(results.length == 1 && results[0] instanceof IPath) {
+ URI uri = URI.createPlatformResourceURI(((IPath)results[0]).toString(), true);
+ outputDirectory = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(uri.toPlatformString(true)));
+ outputPathTxt.setText(outputDirectory.getLocation().toString());
+ }
+ }
+ }
+ });
+
+ outputFormatCb.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ exporter = outputFormatCb.getText();
+ }
+ });
+ }
+
+ /**
+ * set the file from which diagrams will be exported
+ *
+ * @param file
+ */
+ public void setSelectedDiagramFile(IFile file) {
+ selectedDiagramFile = file;
+ loadData();
+ }
+
+ private void loadData() {
+ outputDirectory = selectedDiagramFile.getParent();
+ outputPathTxt.setText(outputDirectory.getLocation().toString());
+ for(ImageFileFormat imageFileFormat : ImageFileFormat.VALUES) {
+ outputFormatCb.add(imageFileFormat.toString());
+ }
+
+ outputFormatCb.setText(ImageFileFormat.getDefaultImageFormat().toString());
+
+ exporter = outputFormatCb.getText();
+ }
+
+ /**
+ * return the output directory where exported diagrams will be saved
+ *
+ * @return
+ */
+ public IResource getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ /**
+ * return the path to the output directory
+ *
+ * @return
+ */
+ public String getExporter() {
+ return exporter;
+ }
+
+ /**
+ * return the qualified name of the diagram
+ *
+ * @return
+ */
+ public boolean getQualifiedName() {
+ return qualifiedName;
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/Messages.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/Messages.java
new file mode 100644
index 00000000000..5f143b02aa6
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/Messages.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.export.actions;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.export.actions.messages"; //$NON-NLS-1$
+
+ public static String ExportAllDiagramsDialog_0;
+
+ public static String ExportAllDiagramsDialog_1;
+
+ public static String ExportAllDiagramsDialog_2;
+
+ public static String ExportAllDiagramsDialog_3;
+
+ public static String ExportAllDiagramsDialog_btnCheckButton_text;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/messages.properties b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/messages.properties
new file mode 100644
index 00000000000..f289fe21a82
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/actions/messages.properties
@@ -0,0 +1,5 @@
+ExportAllDiagramsDialog_0=Select the output directory :
+ExportAllDiagramsDialog_1=Browse...
+ExportAllDiagramsDialog_2=Select the output format :
+ExportAllDiagramsDialog_3=Please select the output directory
+ExportAllDiagramsDialog_btnCheckButton_text=Prefix with qualified name\u00A0
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/internal/Activator.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/internal/Activator.java
new file mode 100644
index 00000000000..0931cbbf080
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/internal/Activator.java
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Anyware Technologies
+ * 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:
+ * David Sciamma (Anyware Technologies) - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.internal;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+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.export"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ plugin = this;
+ }
+
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ 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;
+ }
+
+ /**
+ * Log an IStatus
+ *
+ * @param status
+ * Status of an operation
+ */
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ /**
+ * Log a message with given level into the Eclipse log file
+ *
+ * @param message
+ * the message to log
+ * @param level
+ * the message priority
+ */
+ public static void log(String message, int level) {
+ IStatus status = null;
+ status = new Status(level, PLUGIN_ID, IStatus.OK, message, null);
+ log(status);
+ }
+
+ /**
+ * Log a message with given level into the Eclipse log file
+ *
+ * @param message
+ * the message to log
+ * @param level
+ * the message priority
+ */
+ public static void log(String message, int level, Throwable t) {
+ IStatus status = null;
+ status = new Status(level, PLUGIN_ID, IStatus.OK, message, t);
+ log(status);
+ }
+
+ /**
+ * Log an exception into the Eclipse log file
+ *
+ * @param e
+ * the exception to log
+ */
+ public static void log(Throwable e) {
+ Throwable loggedThrowable = e;
+ if(loggedThrowable instanceof InvocationTargetException) {
+ loggedThrowable = ((InvocationTargetException)loggedThrowable).getTargetException();
+ }
+
+ IStatus status = null;
+ if(loggedThrowable instanceof CoreException) {
+ status = ((CoreException)loggedThrowable).getStatus();
+ } else {
+ status = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, "Error", loggedThrowable);
+ }
+ log(status);
+ }
+
+ /**
+ * Returns the active workbench shell
+ *
+ * @return the active workbench shell
+ */
+ public static Shell getActiveWorkbenchShell() {
+ IWorkbenchWindow workBenchWindow = getActiveWorkbenchWindow();
+ if(workBenchWindow == null) {
+ return null;
+ }
+ return workBenchWindow.getShell();
+ }
+
+ /**
+ * Returns the active workbench page or <code>null</code> if none.
+ *
+ * @return the active workbench page
+ */
+ public static IWorkbenchPage getActivePage() {
+ IWorkbenchWindow window = getActiveWorkbenchWindow();
+ if(window != null) {
+ return window.getActivePage();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the active workbench window
+ *
+ * @return the active workbench window
+ */
+ public static IWorkbenchWindow getActiveWorkbenchWindow() {
+ if(getDefault() == null) {
+ return null;
+ }
+ IWorkbench workBench = getDefault().getWorkbench();
+ if(workBench == null) {
+ return null;
+ }
+ return workBench.getActiveWorkbenchWindow();
+ }
+
+ /**
+ * Display a dialog box with the specified level
+ *
+ * @param title
+ * title dialog box
+ * @param message
+ * message displayed
+ * @param level
+ * message level
+ */
+ public static void displayDialog(final String title, final String message, final int level) {
+ if(level == IStatus.INFO) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openInformation(getActiveWorkbenchShell(), (title == null) ? "Information" : title, (message == null) ? "" : message);
+ }
+ });
+ } else if(level == IStatus.WARNING) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openWarning(getActiveWorkbenchShell(), (title == null) ? "Warning" : title, (message == null) ? "" : message);
+ }
+ });
+ } else if(level == IStatus.ERROR) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openError(getActiveWorkbenchShell(), (title == null) ? "Error" : title, (message == null) ? "" : message);
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/messages.properties b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/messages.properties
new file mode 100644
index 00000000000..814adafda6f
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/messages.properties
@@ -0,0 +1,24 @@
+ExportAllDiagrams_0=Generate
+ExportAllDiagrams_1=Diagram generation
+ExportAllDiagrams_10=Too long file name has been reduced to :
+ExportAllDiagrams_11=error during generation of diagram %s in resource %s
+ExportAllDiagrams_12=\ : unload resources
+ExportAllDiagrams_13=unload
+ExportAllDiagrams_14=[^a-zA-Z0-9ùéèêà&ô_\\-ï]
+ExportAllDiagrams_15=_
+ExportAllDiagrams_16=[<].*[>]
+ExportAllDiagrams_18=Generation successful \!
+ExportAllDiagrams_2=Load ...
+ExportAllDiagrams_20=Name cut performed
+ExportAllDiagrams_22=Generation failed for some tests
+ExportAllDiagrams_24=Generation successful with some warnings
+ExportAllDiagrams_25=Generation successful \!
+ExportAllDiagrams_26=Generation successful at :
+ExportAllDiagrams_27=ExportAll report
+ExportAllDiagrams_3=please provide a file in constructor
+ExportAllDiagrams_4=Diagram generation
+ExportAllDiagrams_5=During export, at least two diagrams had the same name, created files have been renamed to avoid confusion.
+ExportAllDiagrams_6=Renaming Issue
+ExportAllDiagrams_7=Diagram Generation
+ExportAllDiagrams_8=\ :
+ExportAllDiagrams_9=An error occurred while trying to create the output file for diagram
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportAllWizard.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportAllWizard.java
new file mode 100644
index 00000000000..72e0e46060b
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportAllWizard.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.wizard;
+
+import java.util.Collection;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.papyrus.infra.export.ExportAllDiagrams;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class ExportAllWizard extends Wizard implements IExportWizard {
+
+ /** wizard page to export all diagram from a Papyrus model */
+ private ExportDiagramsPage page;
+
+ /** error wizard page shown when the selected file is incorrect */
+ private ExportDiagramsErrorPage pageError;
+
+ /** Selected file */
+ private IFile file;
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ file = convertSelection2File(selection);
+ if(file != null) {
+ page = new ExportDiagramsPage(file);
+ addPage(page);
+ } else {
+ pageError = new ExportDiagramsErrorPage();
+ addPage(pageError);
+ }
+
+ }
+
+ @Override
+ public boolean canFinish() {
+ if(file == null) {
+ return false;
+ }
+ return super.canFinish();
+ }
+
+ @Override
+ public boolean performFinish() {
+ if(file == null) {
+ return false;
+ } else {
+ if(!page.getExport().getOutputDirectory().isAccessible()) {
+ page.setErrorMessage(Messages.ExportAllWizard_0);
+ return false;
+ }
+ page.setErrorMessage(null);
+ new ExportAllDiagrams(file, page.getExport().getOutputDirectory().getLocation().toString(), page.getExport().getExporter(), page.getExport().getQualifiedName()).exportDiagramsToImages();
+ return true;
+ }
+ }
+
+ /**
+ * Try to retrieve the selected file from the given selection
+ *
+ * @param sel
+ * the selection
+ * @return the selected file
+ */
+ private IFile convertSelection2File(ISelection sel) {
+ // get the selected diagrams file
+ if(sel instanceof IStructuredSelection) {
+ IStructuredSelection ssel = (IStructuredSelection)sel;
+ // Only one file should be selected
+ if(!ssel.isEmpty() && ssel.size() == 1) {
+ Object selectedObj = ssel.getFirstElement();
+ return getIFile(selectedObj);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * return the IFile corresponding to the selection
+ *
+ * @param selectedObj
+ * selected file
+ * @return
+ */
+ public static IFile getIFile(Object selectedObj) {
+ IFile result = null;
+ if(selectedObj instanceof IFile) {
+ result = (IFile)selectedObj;
+ }
+ // Try to adapt
+ if(result == null && selectedObj instanceof IAdaptable) {
+ result = (IFile)((IAdaptable)selectedObj).getAdapter(IFile.class);
+ }
+ // adapt in ifile
+ if(result == null) {
+ result = (IFile)Platform.getAdapterManager().getAdapter(selectedObj, IFile.class);
+ }
+ if(result == null) {
+ // try to check if it is a collection
+ Collection<?> collec = (Collection<?>)Platform.getAdapterManager().getAdapter(selectedObj, Collection.class);
+ if(collec != null) {
+ for(Object o : collec) {
+ if(o instanceof IFile) {
+ IFile f = (IFile)o;
+ if("di".equals(f.getFileExtension())) { //$NON-NLS-1$
+ result = f;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return result != null && "di".equals(result.getFileExtension()) ? result //$NON-NLS-1$
+ : null;
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsErrorPage.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsErrorPage.java
new file mode 100644
index 00000000000..65e8096edab
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsErrorPage.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.wizard;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * error wizard page shown when the selected file is incorrect
+ */
+public class ExportDiagramsErrorPage extends WizardPage {
+
+ /**
+ * Create the wizard.
+ */
+ public ExportDiagramsErrorPage() {
+ super(Messages.ExportDiagramsErrorPage_0);
+ setTitle(Messages.ExportDiagramsErrorPage_0);
+ setDescription(Messages.ExportDiagramsErrorPage_2);
+ }
+
+ /**
+ * Create contents of the wizard.
+ *
+ * @param parent
+ */
+ public void createControl(Composite parent) {
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(Messages.ExportDiagramsErrorPage_3);
+ setControl(label);
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsPage.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsPage.java
new file mode 100644
index 00000000000..42b7fbeca5b
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/ExportDiagramsPage.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.wizard;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.papyrus.infra.export.actions.ExportComposite;
+
+/**
+ * wizard page to export all diagram from a Papyrus model
+ */
+public class ExportDiagramsPage extends WizardPage {
+
+ private ExportComposite export;
+
+ public ExportComposite getExport() {
+ return export;
+ }
+
+ private final IFile file;
+
+ /**
+ * Create the wizard.
+ */
+ public ExportDiagramsPage(IFile file) {
+ super(Messages.ExportDiagramsPage_0);
+ this.file = file;
+ setTitle(Messages.ExportDiagramsPage_0);
+ setDescription(Messages.ExportDiagramsPage_2);
+ }
+
+ /**
+ * Create contents of the wizard.
+ *
+ * @param parent
+ */
+ public void createControl(Composite parent) {
+ export = new ExportComposite(parent, SWT.NONE);
+ export.setSelectedDiagramFile(file);
+ setControl(export);
+ }
+
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/Messages.java b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/Messages.java
new file mode 100644
index 00000000000..058f14a2e38
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/Messages.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 AtoS
+ * 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:
+ * Anass RADOUANI (AtoS)
+ *******************************************************************************/
+
+package org.eclipse.papyrus.infra.export.wizard;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.export.wizard.messages"; //$NON-NLS-1$
+
+ public static String ExportAllWizard_0;
+
+ public static String ExportDiagramsErrorPage_0;
+
+ public static String ExportDiagramsErrorPage_2;
+
+ public static String ExportDiagramsErrorPage_3;
+
+ public static String ExportDiagramsPage_0;
+
+ public static String ExportDiagramsPage_2;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/messages.properties b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/messages.properties
new file mode 100644
index 00000000000..67798f4c499
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.export/src/org/eclipse/papyrus/infra/export/wizard/messages.properties
@@ -0,0 +1,6 @@
+ExportAllWizard_0=Please fixe output directory
+ExportDiagramsErrorPage_0=Export all diagrams
+ExportDiagramsErrorPage_2=Export all diagrams of a model created with papyrus
+ExportDiagramsErrorPage_3=Please select a Papyrus model before trying to export all diagrams
+ExportDiagramsPage_0=Export All diagrams
+ExportDiagramsPage_2=Export all diagrams of a model created with papyrus

Back to the top