Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d7c87426b56423ebfaab810aaa3617a3109077e2 (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
/*****************************************************************************
 * Copyright (c) 2009 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *
 *****************************************************************************/

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

import org.eclipse.gef.ui.palette.PaletteCustomizer;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.diagram.common.part.PapyrusPalettePreferences;
import org.eclipse.papyrus.diagram.common.service.PapyrusPaletteService;
import org.eclipse.ui.IEditorPart;

/**
 * Wizard to update an existing Extended Palette Definition
 */
public class UpdateExtendedPaletteWizard extends Wizard {

	/** Editor part in which the palette is displayed */
	protected IEditorPart editorPart;

	/** content page */
	protected ExtendedPaletteContentPage contentPage;

	/** info page */
	protected ExtendedPaletteInformationPage infoPage;

	/** palette configuration to update */
	protected PapyrusPaletteService.ExtendedProviderDescriptor descriptor;

	/** customizer used by the palette viewer */
	private PaletteCustomizer customizer;

	/**
	 * Creates a NewLocalPaletteWizard.
	 * 
	 * @param part
	 *        the editor part where the palette is available
	 * @param descriptor
	 *        the descriptor to edit
	 */
	public UpdateExtendedPaletteWizard(IEditorPart part, PapyrusPaletteService.ExtendedProviderDescriptor descriptor, PaletteCustomizer customizer) {
		this.editorPart = part;
		this.descriptor = descriptor;
		this.customizer = customizer;
	}

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

		// first paeg: name, id, etc.
		infoPage = new ExtendedPaletteInformationPage(editorPart);
		infoPage.intializeValues(descriptor);

		// second page: describe the paletteContent
		contentPage = new ExtendedPaletteContentPage(editorPart, customizer);
		contentPage.initializeContent(descriptor);

		addPage(infoPage);
		addPage(contentPage);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean performFinish() {
		// contentPage.restorePreferences();
		// file has been created or updated
		contentPage.performFinish(PapyrusPalettePreferences.getPalettePathFromID(infoPage.getPaletteID()));

		//PapyrusPalettePreferences.unregisterLocalRedefinition(infoPage.getPaletteID());
		// generate the preference for local palette
		String path = PapyrusPalettePreferences.getPaletteRedefinition(infoPage.getPaletteID());
		PapyrusPalettePreferences.registerLocalRedefinition(infoPage.getPaletteID(), path); // if already exists: removes, then add 

		// toggle visiblity to refresh the content
		if(editorPart instanceof DiagramEditorWithFlyOutPalette) {
			PapyrusPalettePreferences.changePaletteVisibility(infoPage.getPaletteID(), editorPart, false);
			PapyrusPalettePreferences.changePaletteVisibility(infoPage.getPaletteID(), editorPart, true);
		}
		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean performCancel() {
		// contentPage.restorePreferences();
		return super.performCancel();
	}

}

Back to the top