Skip to main content
summaryrefslogtreecommitdiffstats
blob: d5b536c16522c20788756cff8aaa988f9b0bd924 (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
/**
 * Copyright (c) 2011 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:
 * 	Nicolas Guyomar (Mia-Software) - Bug 349546 - EMF Facet facetSet editor
 */
package org.eclipse.papyrus.emf.facet.efacet.ui.internal.wizards.pages;

import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.emf.facet.efacet.Facet;
import org.eclipse.papyrus.emf.facet.efacet.FacetSet;
import org.eclipse.papyrus.emf.facet.efacet.ui.internal.Messages;
import org.eclipse.papyrus.emf.facet.efacet.ui.internal.composites.BrowseComposite;
import org.eclipse.papyrus.emf.facet.efacet.ui.internal.composites.SelectETypeComposite.ETypeSelectionOptions;
import org.eclipse.papyrus.emf.facet.efacet.ui.internal.exported.wizard.IQueryCreationPagePart;
import org.eclipse.papyrus.emf.facet.efacet.ui.internal.wizards.SelectETypeWizardImpl;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

@Deprecated
//TODO @Deprecated must be removed after a refactoring planed by https://bugs.eclipse.org/bugs/show_bug.cgi?id=364601
public class CreateFacetInFacetSetWizardPage extends AbstractFacetWizardPage {

	private boolean canChangeExtendedMetaClass;
	private final Facet facet;

	public CreateFacetInFacetSetWizardPage(final Facet facet, final ISelection selection, final EditingDomain editingDomain2,
			final Map<String, IQueryCreationPagePart> queryTypeNameToWizardPage) {
		super(selection, editingDomain2, queryTypeNameToWizardPage, ETypeSelectionOptions.ECLASS);
		this.facet = facet;
		setTitle(Messages.Create_facet_in_facetSet);
		setDescription(Messages.CreateFacetInFacetSetWizardPage_wizard_description);
	}

	@Override
	public boolean canFlipToNextPage() {
		return isPageComplete() && isSubTypingFacet();
	}

	@Override
	public boolean isPageComplete() {
		if (super.isPageComplete()) {
			if (getExtendedMetaclass() == null) {
				setErrorMessage(Messages.CreateFacetInFacetSetWizardPage_Please_fill_extendedMetaClass);
				return false;
			}
			return true;
		}
		return false;
	}

	@Override
	protected void initializeWithSelection() {
		if (getSelection() != null && !getSelection().isEmpty() && getSelection() instanceof IStructuredSelection) {
			IStructuredSelection ssel = (IStructuredSelection) getSelection();
			if (ssel.size() > 1) {
				return;
			}
			Object obj = ssel.getFirstElement();
			if (obj instanceof FacetSet) {
				FacetSet facetSet = (FacetSet) obj;
				setFacetSet(facetSet);
				if (facetSet.getName() != null) {
					setParentName(facetSet.getName(), true);
				}
			}
		}
	}

	public void createControl(final Composite parent) {
		final Composite container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 1;
		layout.verticalSpacing = AbstractFacetWizardPage.VERTICAL_SPACING;
		showLowerBound(false);
		showUpperBound(false);
		showEType(false);
		showVolatile(false);
		showOrdered(false);
		showChangeable(false);
		showUnique(false);
		showTransient(false);
		showDerived(false);

		Composite container2 = createControlParts(container);

		Label label = new Label(container2, SWT.NONE);
		label.setText(Messages.ExtendedMetaClass);
		@SuppressWarnings("unused")
		// this composite is never read because it only takes care of the UI
		BrowseComposite browseComposite = new BrowseComposite(container2, SWT.BORDER, null, this.canChangeExtendedMetaClass) {
			@Override
			protected void handleBrowse() {
				SelectETypeWizardImpl dialog = new SelectETypeWizardImpl(getEditingDomain(), ETypeSelectionOptions.ECLASS, false, getFacetSet()
						.getExtendedEPackage());
				if (dialog.open() != Window.CANCEL) {
					EClass eClass = (EClass) dialog.getSelectedEType();
					setExtendedMetaClass(eClass);
					if (eClass.getInstanceClassName() != null) {
						updateTextFieldContent(eClass.getInstanceClassName());
					} else {
						updateTextFieldContent(eClass.getName());
					}
					updatePageButtons();
				}
			}
		};

		initializeTextContent(Messages.FacetSet, Messages.Facet);

		setControl(container);
	}

	public void setExtendedMetaClass(final EClass extendedMetaClass) {
		this.facet.setExtendedMetaclass(extendedMetaClass);
	}

	public void canChangeExtendedMetaClass(final boolean canChange2) {
		this.canChangeExtendedMetaClass = canChange2;
	}

	public EClass getExtendedMetaclass() {
		return this.facet.getExtendedMetaclass();
	}
}

Back to the top