Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 85dce028af4f7608bc57eb4a9ff51cdf17fe4f9e (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
/*****************************************************************************
 * Copyright (c) 2016 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:
 * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.customization.palette.dialog;

import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.customization.palette.Messages;
import org.eclipse.papyrus.customization.palette.PaletteConstants;
import org.eclipse.papyrus.customization.palette.utils.PaletteUtils;
import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;

/**
 * Wizard to export an existing Palette Definition and its associated models files.
 */
public class ExportPaletteConfigurationWizard extends AbstractPaletteConfigurationWizard {

	/** content page */
	protected PaletteConfigurationContentPage contentPage;

	/** the new file creation page of the wizard */
	private WizardNewFileCreationPage newFileCreationPage;

	/**
	 * Creates a new local Palette Wizard.
	 *
	 * @param part
	 *            the editor part where the palette is available
	 * @param descriptor
	 *            the descriptor to edit
	 */
	public ExportPaletteConfigurationWizard(final IEditorPart part, final ProviderDescriptor descriptor) {
		super(part, descriptor);
		setWindowTitle(Messages.ExportPaletteConfigurationWizard_ExportWiazrdLabel);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void addPages() {
		super.addPages();

		newFileCreationPage = new WizardNewFileCreationPage("", new StructuredSelection());//$NON-NLS-1$

		newFileCreationPage.setTitle(Messages.ExportPaletteConfigurationWizard_export_palette);
		newFileCreationPage.setDescription(Messages.ExportPaletteConfigurationWizard_Export_description);

		addPage(newFileCreationPage);
	}


	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void saveResources() {

		// Get the wanted location
		String selectedPath = newFileCreationPage.getContainerFullPath().append(newFileCreationPage.getFileName()).toString();

		clearStringBuilder();
		stringBuilder.append(selectedPath);
		stringBuilder.append(STR_DOT);
		stringBuilder.append(PaletteConstants.PALETTECONFIGURATION_EXTENSION);
		// Set new path
		paletteResource.setURI(URI.createFileURI(stringBuilder.toString()));

		clearStringBuilder();
		stringBuilder.append(selectedPath);
		stringBuilder.append(PaletteConstants.ELEMENTTYPE_UI_IDENTIFIER_POSTFIX);
		stringBuilder.append(STR_DOT);
		stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION);

		elementTypeUIResource.setURI(URI.createFileURI(stringBuilder.toString()));

		clearStringBuilder();
		stringBuilder.append(selectedPath);
		stringBuilder.append(PaletteConstants.ELEMENTTYPE_SEMENTIC_IDENTIFIER_POSTFIX);
		stringBuilder.append(STR_DOT);
		stringBuilder.append(PaletteConstants.ELEMENTTYPE_EXTENSION);
		elementTypeSemResource.setURI(URI.createFileURI(stringBuilder.toString()));

		// Save
		try {
			paletteResource.save(PaletteUtils.saveOptions);
			// Checks if model are not void and are useful
			if (!((ElementTypeSetConfiguration) elementTypeUIResource.getContents().get(0)).getElementTypeConfigurations().isEmpty()) {
				elementTypeUIResource.save(PaletteUtils.saveOptions);
				elementTypeSemResource.save(PaletteUtils.saveOptions);
			}
		} catch (IOException e) {
			Activator.log.error(e);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void deployModels() {
		// Nothings to loads
	}
}

Back to the top