Skip to main content
summaryrefslogtreecommitdiffstats
blob: a3badfda5f51f276bff532ba75b5a07ba0fcf247 (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
177
178
179
180
181
182
/*******************************************************************************
 * Copyright (c) 2013 Remain BV, Industrial-TSI BV and others.
 * 
 * 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:
 *     Wim Jongmam <wim.jongman@remainsoftware.com> - initial API and implementation
 ******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.imp;

import java.util.ArrayList;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;

public class ModelImportPage1 extends WizardPage {

	private class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
		public Image getColumnImage(Object element, int columnIndex) {
			return null;
		}

		public String getColumnText(Object element, int columnIndex) {
			if (element instanceof IConfigurationElement) {
				IConfigurationElement config = (IConfigurationElement) element;
				return config.getAttribute(wizard.getMappingName());
			}
			return element.toString();
		}
	}

	private IExtensionRegistry registry;
	private ModelImportWizard wizard;
	protected Object[] checkedElements;

	private class TableContentProvider implements IStructuredContentProvider {
		public Object[] getElements(Object inputElement) {

			if (!(inputElement instanceof RegistryStruct)) {
				return new String[] { "Wrong input" };
			}

			RegistryStruct input = (RegistryStruct) inputElement;

			return RegistryUtil.getExtensions(registry, input, wizard.isLiveModel());
		}

		public void dispose() {
		}

		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		}
	}

	private class ComboContentProvider implements IStructuredContentProvider {
		public Object[] getElements(Object inputElement) {
			return RegistryUtil.getProvidingBundles(registry, wizard.getExtensionPoint(), wizard.isLiveModel());
		}

		public void dispose() {
		}

		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		}
	}

	/**
	 * Create the wizard.
	 */
	public ModelImportPage1() {
		super("wizardPage");
		setTitle("Import ");
		setDescription("Select plug-in and elements to import");
		wizard = (ModelImportWizard) getWizard();
		setPageComplete(false);
	}

	/**
	 * Create contents of the wizard.
	 * 
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		container.setLayout(new GridLayout(1, false));

		ComboViewer comboViewer = new ComboViewer(container, SWT.NONE);
		Combo combo = comboViewer.getCombo();
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Composite composite = new Composite(container, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		TableColumnLayout tcl_composite = new TableColumnLayout();
		composite.setLayout(tcl_composite);

		final CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);

		TableViewerColumn tableViewerColumn = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
		TableColumn column = tableViewerColumn.getColumn();
		column.setResizable(false);
		tcl_composite.setColumnData(column, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
		column.setText("Description");
		checkboxTableViewer.setLabelProvider(new TableLabelProvider());
		checkboxTableViewer.setContentProvider(new TableContentProvider());
		comboViewer.setContentProvider(new ComboContentProvider());

		comboViewer.setInput("go");

		comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

			public void selectionChanged(SelectionChangedEvent event) {
				String bundle = ((IStructuredSelection) event.getSelection()).getFirstElement().toString();
				RegistryStruct struct = RegistryUtil.getStruct(wizard.getApplicationElement(), wizard.getHint());
				struct.setBundle(bundle);
				checkboxTableViewer.setInput(struct);

			}
		});

		checkboxTableViewer.addCheckStateListener(new ICheckStateListener() {
			public void checkStateChanged(CheckStateChangedEvent event) {
				checkedElements = checkboxTableViewer.getCheckedElements();
				if (checkedElements.length > 0) {
					setPageComplete(true);
				} else {
					setPageComplete(false);
				}
			}
		});
	}

	@Override
	public void setWizard(IWizard newWizard) {
		this.wizard = (ModelImportWizard) newWizard;
		setTitle("Import " + wizard.getApplicationElement().getSimpleName());

		String hint = wizard.getHint();
		if (hint != null && hint.length() > 0) {
			setDescription("Select plug-in and elements (" + hint + ") to import");
			// else already set
		}

		super.setWizard(newWizard);
	}

	public IConfigurationElement[] getConfigurationElements() {
		ArrayList<IConfigurationElement> result = new ArrayList<IConfigurationElement>();
		for (Object element : checkedElements) {
			if (element instanceof IConfigurationElement) {
				result.add((IConfigurationElement) element);
			}
		}
		return result.toArray(new IConfigurationElement[0]);
	}
}

Back to the top