Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 02f9db4f143860c7ca1f80c5e8cd540218d781a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*******************************************************************************
 * Copyright (c) 2011, 2014 AtoS, CEA LIST and other.
 * 
 * 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)
 *    Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 440754
 *******************************************************************************/

package org.eclipse.papyrus.infra.gmfdiag.export.wizard;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ResourceUtils;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForSelection;
import org.eclipse.papyrus.infra.gmfdiag.export.actions.ExportAllDiagramsParameter;
import org.eclipse.papyrus.infra.gmfdiag.export.actions.ExportComposite;
import org.eclipse.papyrus.infra.gmfdiag.export.engine.ExportAllDiagramsEngine;
import org.eclipse.papyrus.infra.gmfdiag.export.messages.Messages;
import org.eclipse.papyrus.infra.gmfdiag.export.utils.SelectionHelper;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;



/**
 * Export wizard for Export all diagrams feature.
 */
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;

	/** The export all diagrams. */
	private ExportAllDiagramsEngine exportAllDiagrams = null;

	/** The Export parameter. */
	private ExportAllDiagramsParameter parameter = null;

	/**
	 * Constructor.
	 *
	 */
	public ExportAllWizard() {
		super();
		setWindowTitle(Messages.ExportAllWizard_1);
		exportAllDiagrams = new ExportAllDiagramsEngine();
	}

	/**
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
	 *
	 * @param workbench
	 * @param selection
	 */
	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {


		// Initialise local field of handler
		ModelSet modelSetSelection = null;

		file = null;

		// Try to get model set with the services
		try {
			modelSetSelection = ServiceUtilsForSelection.getInstance().getModelSet(selection);
		} catch (ServiceException e) {
			// Ignore service exception
		}


		// No registered services with the selection
		if (modelSetSelection == null) {

			file = SelectionHelper.convertSelection2File(selection);
			if (file != null) {

				URI diFileUri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);

				// Initialise export parameter
				parameter = new ExportAllDiagramsParameter(diFileUri);
			}

		} else {

			// Get file di file
			IModel diModel = modelSetSelection.getModel(DiModel.DI_MODEL_ID);
			if (diModel instanceof DiModel) {
				file = ResourceUtils.getFile(((DiModel) diModel).getResource());
			}

			// Initialise export parameter
			parameter = new ExportAllDiagramsParameter(modelSetSelection);

		}

		// Ask to user the others export configuration parameters
		URI uriFile = null;
		if (file != null) {
			IContainer parentResource = file.getParent();
			parentResource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(parentResource.getLocation());
			uriFile = URI.createPlatformResourceURI(parentResource.getLocation().toString(), true);

		}

		if (parameter == null) {
			pageError = new ExportDiagramsErrorPage();
			addPage(pageError);
		} else {
			page = new ExportDiagramsPage(uriFile);
			addPage(page);
		}


	}

	/**
	 * @see org.eclipse.jface.wizard.Wizard#canFinish()
	 *
	 * @return
	 */
	@Override
	public boolean canFinish() {
		return file != null && super.canFinish();
	}

	/**
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 *
	 * @return
	 */
	@Override
	public boolean performFinish() {
		boolean performFinish = parameter != null;
		if (performFinish) {

			ExportComposite exportPage = page.getExport();
			performFinish = exportPage.getOutputDirectory().isAccessible();
			if (performFinish) {
				page.setErrorMessage(null);

				parameter.setOutputDirectory(exportPage.getOutputDirectory());
				parameter.setExportFormat(exportPage.getExporter());
				parameter.setQualifiedName(exportPage.getQualifiedName());

				exportAllDiagrams.initialise(parameter);
				exportAllDiagrams.exportDiagramsToImages();
			} else {
				page.setErrorMessage(Messages.ExportAllWizard_0);
			}

		}

		return performFinish;
	}

}

Back to the top