Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 267493
Collapse All | Expand All

(-)plugin.properties (-1 / +4 lines)
Lines 24-27 Link Here
24
24
25
RunMenu.label=&Run
25
RunMenu.label=&Run
26
runTransformationShow=Transformation...
26
runTransformationShow=Transformation...
27
runTransformationTooltip=Run QVT Transformation
27
runTransformationTooltip=Run QVT Transformation
28
29
transformationSetWizardName = Operational QVT Transformation Sequence
30
transformationSetWizardName.description = Create a new Ant-based QVTO Transformation Sequence
(-)plugin.xml (+13 lines)
Lines 106-109 Link Here
106
106
107
    </extension>    
107
    </extension>    
108
108
109
   <extension point="org.eclipse.ui.newWizards">
110
      <wizard
111
            category="org.eclipse.m2m.qvt.oml.wizardCategory"
112
            class="org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant.NewCompositeTransformationWizard"
113
            icon="icons/anttasks.gif"
114
            id="com.borland.m2m.qvt.common.wizards.NewCompositeTransformationWizard"
115
            name="%transformationSetWizardName">
116
         <description>
117
         	%transformationSetWizardName.description
118
         </description>
119
      </wizard>
120
   </extension>
121
109
</plugin>
122
</plugin>
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 10-15 Link Here
10
 org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
10
 org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
11
 org.eclipse.debug.ui;bundle-version="[3.4.0,4.0.0)",
11
 org.eclipse.debug.ui;bundle-version="[3.4.0,4.0.0)",
12
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
12
 org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
13
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.5.0,4.0.0)",
14
 org.eclipse.jface.text;bundle-version="[3.4.0,4.0.0)",
13
 org.eclipse.m2m.qvt.oml;bundle-version="[2.0.0,3.0.0)",
15
 org.eclipse.m2m.qvt.oml;bundle-version="[2.0.0,3.0.0)",
14
 org.eclipse.m2m.qvt.oml.common;bundle-version="[1.0.0,2.0.0)",
16
 org.eclipse.m2m.qvt.oml.common;bundle-version="[1.0.0,2.0.0)",
15
 org.eclipse.m2m.qvt.oml.common.ui;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
17
 org.eclipse.m2m.qvt.oml.common.ui;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/NewCompositeTransformationWizard.java (+181 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.io.ByteArrayInputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.UnsupportedEncodingException;
18
import java.lang.reflect.InvocationTargetException;
19
import java.util.List;
20
21
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.core.runtime.Status;
31
import org.eclipse.jface.dialogs.MessageDialog;
32
import org.eclipse.jface.operation.IRunnableWithProgress;
33
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.wizard.Wizard;
35
import org.eclipse.m2m.internal.qvt.oml.runtime.ui.QvtRuntimeUIPlugin;
36
import org.eclipse.ui.INewWizard;
37
import org.eclipse.ui.IWorkbench;
38
import org.eclipse.ui.IWorkbenchPage;
39
import org.eclipse.ui.PartInitException;
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
42
import org.eclipse.ui.ide.IDE;
43
44
public class NewCompositeTransformationWizard extends Wizard implements INewWizard {
45
	public NewCompositeTransformationWizard() {
46
		setNeedsProgressMonitor(true);
47
	}
48
49
	public void init(IWorkbench workbench, IStructuredSelection selection) {
50
		mySelection = selection;
51
		setWindowTitle(Messages.TransformWizard_windowTitle);
52
	}
53
54
	@Override
55
	public void addPages() {
56
		myNewFilePage = new WizardNewFileCreationPage("newTransformFilePage", mySelection); //$NON-NLS-1$
57
		myNewFilePage.setTitle(Messages.TransformFilePage_title);
58
		
59
		String defaultFileName = "composite.xml"; //$NON-NLS-1$
60
		if (mySelection.getFirstElement() instanceof IFile) {
61
			final IFile file = (IFile) mySelection.getFirstElement();
62
			if (!"xml".equals(file.getFileExtension())) { //$NON-NLS-1$
63
				defaultFileName = file.getProjectRelativePath().removeFileExtension().addFileExtension("xml").lastSegment(); //$NON-NLS-1$
64
			} else {
65
				defaultFileName = file.getProjectRelativePath().lastSegment();
66
			}
67
		}
68
		myNewFilePage.setFileName(defaultFileName);
69
		addPage(myNewFilePage);
70
71
		myContentsPage = new CompositeTransformationContentPage(myModel);
72
73
		addPage(myContentsPage);
74
	}
75
76
	@Override
77
	public boolean performFinish() {
78
		final String containerName = myNewFilePage.getContainerFullPath().toPortableString();
79
		final String fileName = myNewFilePage.getFileName();
80
		IRunnableWithProgress op = new IRunnableWithProgress() {
81
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
82
				try {
83
					doFinish(containerName, fileName, monitor);
84
				} catch (CoreException e) {
85
					throw new InvocationTargetException(e);
86
				} finally {
87
					monitor.done();
88
				}
89
			}
90
		};
91
		try {
92
			getContainer().run(true, false, op);
93
		} catch (InterruptedException e) {
94
			return false;
95
		} catch (InvocationTargetException e) {
96
			Throwable realException = e.getTargetException();
97
			MessageDialog.openError(getShell(), "Error", realException.getMessage()); //$NON-NLS-1$
98
			return false;
99
		}
100
		return true;
101
	}
102
103
	private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException {
104
		// create a sample file
105
		monitor.beginTask("Creating " + fileName, 2); //$NON-NLS-1$
106
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
107
		IResource resource = root.findMember(new Path(containerName));
108
		if (!resource.exists() || !(resource instanceof IContainer)) {
109
			throwCoreException("Container \"" + containerName + "\" does not exist.", null); //$NON-NLS-1$ //$NON-NLS-2$
110
		}
111
		IContainer container = (IContainer) resource;
112
		final IFile file = container.getFile(new Path(fileName));
113
		try {
114
			InputStream stream = openContentStream();
115
			if (file.exists()) {
116
				file.setContents(stream, true, true, monitor);
117
			} else {
118
				file.create(stream, true, monitor);
119
			}
120
			stream.close();
121
		} catch (IOException e) {
122
			throwCoreException("Error creating file [" + fileName + "]", e); //$NON-NLS-1$ //$NON-NLS-2$
123
		}
124
		monitor.worked(1);
125
		monitor.setTaskName("Opening file for editing..."); //$NON-NLS-1$
126
		getShell().getDisplay().asyncExec(new Runnable() {
127
			public void run() {
128
				IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
129
				try {
130
					IDE.openEditor(page, file, true);
131
				} catch (PartInitException e) {
132
				}
133
			}
134
		});
135
		monitor.worked(1);
136
	}
137
138
	private InputStream openContentStream() throws UnsupportedEncodingException, CoreException {
139
		String encoding = getCharset();
140
		String result = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n" + //$NON-NLS-1$//$NON-NLS-2$
141
				"<project name=\"" + myModel.getProjectName() + "\" " + //$NON-NLS-1$//$NON-NLS-2$
142
				"default=\"" + myModel.getTargetName() + "\" xmlns:qvto=\"http://www.eclipse.org/qvt/1.0.0/Operational\">\n"; //$NON-NLS-1$//$NON-NLS-2$
143
		result += "    <target name=\"" + myModel.getTargetName() + "\">\n"; //$NON-NLS-1$//$NON-NLS-2$
144
		List<TaskModel> value = myModel.getTaskModels();
145
		for (TaskModel model : value) {
146
			result += TaskModel.indentString(model.toString(), "        ", "\n") + "\n"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
147
		}
148
		result += "    </target>\n"; //$NON-NLS-1$
149
		result += "</project>"; //$NON-NLS-1$
150
		return new ByteArrayInputStream(result.getBytes(encoding));
151
	}
152
153
	private String getCharset() throws CoreException {
154
//		if (mySelection != null) {
155
//			Object firstElement = mySelection.getFirstElement();
156
//			if (firstElement instanceof IResource) {
157
//				IResource resource = (IResource) firstElement;
158
//				String charset = resource.getProject().getDefaultCharset();
159
//				if ((charset != null) && Charset.isSupported(charset)) {
160
//					return charset;
161
//				}
162
//			}
163
//		}
164
//		String charset = ResourcesPlugin.getEncoding();
165
//		if (Charset.isSupported(charset)) {
166
//			return charset;
167
//		}
168
		return "UTF-8"; //$NON-NLS-1$
169
	}
170
171
	private static void throwCoreException(String message, Throwable exception) throws CoreException {
172
		IStatus status = new Status(IStatus.ERROR, QvtRuntimeUIPlugin.PLUGIN_ID, IStatus.OK, message, exception);
173
		throw new CoreException(status);
174
	}
175
176
	private WizardNewFileCreationPage myNewFilePage;
177
	private CompositeTransformationContentPage myContentsPage;
178
	private IStructuredSelection mySelection;
179
180
	private CompositeTransformationModel myModel = new CompositeTransformationModel();
181
}
(-)icons/anttasks.gif (+3 lines)
Added Link Here
1
GIF89aÕqqˆ¹¹¼óõûãêøæìøòõûõ÷ûùúüáé÷èîùìñúïóúßè÷éïùàé÷åíùãë÷ðôú÷ùüõøü÷ùûççÐÜÜÕôóí~vN}uNœ™‰?wM~uN…yLŠ{KŸ†CšƒE”€G?~I±?>ª‹A¤ˆBàÈ?´?=®??Ô²hÔ²iÚ½|Õ²iÐÐи¸¸ˆˆˆBBBÿÿÿ!ù1,?À˜0v*?ÃäéÀlT§¤ðòœ+ÖH€U`‰„bZ¥PÉ.lh·'$!,Ö²˜`_(Écv0ƒC`//]
2
?? I./0Ž	™™
3
!1k`vj0"IŽ©««C/U/.·Š.^`0ÁÁ¢01vÏRÓÔ1A;
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/Messages.java (+59 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import org.eclipse.osgi.util.NLS;
15
16
public class Messages extends NLS {
17
	private static final String BUNDLE_NAME = "org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant.messages"; //$NON-NLS-1$
18
19
	public static String AntTaskWizard_windowTitle;
20
21
	public static String LaunchConfigError_msg;
22
23
	public static String LaunchConfigError_title;
24
25
	public static String SourceTypePage_title;
26
	public static String SourceTypePage_descr;
27
	public static String SourceTypePage_opt1;
28
	public static String SourceTypePage_opt2;
29
30
	public static String SourcePage_title1;
31
	public static String SourcePage_descr1;
32
	public static String SourcePage_configBtn;
33
34
	public static String ResultPage_title;
35
	public static String ResultPage_descr;
36
37
	public static String TransformWizard_windowTitle;
38
	public static String TransformFilePage_title;
39
40
	public static String TransformPage_title;
41
	public static String TransformPage_descr;
42
	public static String TransformPage_task;
43
	public static String TransformPage_project;
44
45
	public static String Name;
46
	public static String Value;
47
	public static String Add;
48
	public static String Delete;
49
	public static String Up;
50
	public static String Down;
51
52
	static {
53
		// initialize resource bundle
54
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
55
	}
56
57
	private Messages() {
58
	}
59
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/CompositeTransformationContentPage.java (+308 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.Map.Entry;
18
19
import org.eclipse.jface.viewers.ColumnWeightData;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.ISelectionChangedListener;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.ITableLabelProvider;
24
import org.eclipse.jface.viewers.ITreeContentProvider;
25
import org.eclipse.jface.viewers.LabelProvider;
26
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
import org.eclipse.jface.viewers.StructuredSelection;
28
import org.eclipse.jface.viewers.TableLayout;
29
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.jface.wizard.WizardDialog;
33
import org.eclipse.jface.wizard.WizardPage;
34
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.events.ModifyEvent;
36
import org.eclipse.swt.events.ModifyListener;
37
import org.eclipse.swt.events.SelectionAdapter;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.events.SelectionListener;
40
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Label;
46
import org.eclipse.swt.widgets.Text;
47
import org.eclipse.swt.widgets.Tree;
48
import org.eclipse.swt.widgets.TreeColumn;
49
50
public class CompositeTransformationContentPage extends WizardPage {
51
	private final CompositeTransformationModel myModel;
52
53
	private boolean myWasEverShown;
54
	private Text myProjectNameText;
55
	private Text myTargetNameText;
56
	private TreeViewer myTreeViewer;
57
	private Button myUp;
58
	private Button myDown;
59
	private Button myDelete;
60
61
	public CompositeTransformationContentPage(CompositeTransformationModel model) {
62
		super("transformationPage"); //$NON-NLS-1$
63
		myModel = model;
64
		setTitle(Messages.TransformPage_title);
65
		setDescription(Messages.TransformPage_descr);
66
	}
67
68
	@Override
69
	public boolean isPageComplete() {
70
		return myWasEverShown && super.isPageComplete();
71
	}
72
73
	public void createControl(Composite parent) {
74
		Composite container = new Composite(parent, SWT.NULL);
75
		GridLayout layout = new GridLayout();
76
		container.setLayout(layout);
77
		layout.numColumns = 2;
78
		layout.verticalSpacing = 9;
79
		Label label = new Label(container, SWT.NULL);
80
		label.setText(Messages.TransformPage_project);
81
82
		myProjectNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
83
		myProjectNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
84
		myProjectNameText.setText(myModel.getProjectName());
85
		myProjectNameText.addModifyListener(new ModifyListener() {
86
			public void modifyText(ModifyEvent e) {
87
				myModel.setProjectName(myProjectNameText.getText());
88
			}
89
		});
90
91
		label = new Label(container, SWT.NULL);
92
		label.setText(Messages.TransformPage_task);
93
94
		myTargetNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
95
		myTargetNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
96
		myTargetNameText.setText(myModel.getTargetName());
97
		myTargetNameText.addModifyListener(new ModifyListener() {
98
			public void modifyText(ModifyEvent e) {
99
				myModel.setTargetName(myTargetNameText.getText());
100
			}
101
		});
102
103
		Composite composite = new Composite(container, SWT.NONE);
104
		GridData data = new GridData(GridData.FILL_BOTH);
105
		data.horizontalSpan = 2;
106
		composite.setLayoutData(data);
107
		layout = new GridLayout();
108
		layout.numColumns = 2;
109
		layout.verticalSpacing = 9;
110
		layout.marginWidth = 0;
111
		layout.marginRight = 0;
112
		composite.setLayout(layout);
113
114
		int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
115
		myTreeViewer = new TreeViewer(composite, style);
116
		myTreeViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
117
		final DataProvider dp = new DataProvider();
118
		myTreeViewer.setContentProvider(dp);
119
		myTreeViewer.setLabelProvider(dp);
120
		myTreeViewer.setInput(myModel);
121
122
		myTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
123
			public void selectionChanged(SelectionChangedEvent event) {
124
				updateButtons(event.getSelection());
125
			}
126
		});
127
128
		Tree tree = myTreeViewer.getTree();
129
		TableLayout tableLayout = new TableLayout();
130
131
		TreeColumn col = new TreeColumn(tree, SWT.NONE);
132
		tableLayout.addColumnData(new ColumnWeightData(3, true));
133
		col.setText(Messages.Name);
134
135
		col = new TreeColumn(tree, SWT.NONE);
136
		tableLayout.addColumnData(new ColumnWeightData(3, true));
137
		col.setText(Messages.Value);
138
139
		tree.setLayout(tableLayout);
140
		tree.setLinesVisible(true);
141
		tree.setHeaderVisible(true);
142
143
		Composite buttons = new Composite(composite, SWT.NONE);
144
		buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
145
		layout = new GridLayout();
146
		layout.numColumns = 1;
147
		layout.verticalSpacing = 9;
148
		layout.marginTop = 0;
149
		layout.marginHeight = 0;
150
		layout.marginWidth = 0;
151
		layout.marginRight = 0;
152
		buttons.setLayout(layout);
153
154
		newButton(buttons, Messages.Add, new SelectionAdapter() {
155
			@Override
156
			public void widgetSelected(SelectionEvent e) {
157
				CreateQvtoAntTaskWizard taskWizard = new CreateQvtoAntTaskWizard();
158
				WizardDialog dialog = new WizardDialog(getContainer().getShell(), taskWizard);
159
				dialog.create();
160
				if (dialog.open() == Window.OK) {
161
					myModel.getTaskModels().add(taskWizard.getResult());
162
					myTreeViewer.refresh();
163
				}
164
			}
165
		});
166
167
		myDelete = newButton(buttons, Messages.Delete, new SelectionAdapter() {
168
			@Override
169
			public void widgetSelected(SelectionEvent e) {
170
				Object selectedElement = getSelectedElement();
171
				if (selectedElement instanceof TaskModel) {
172
					myModel.getTaskModels().remove(selectedElement);
173
					myTreeViewer.refresh();
174
				}
175
			}
176
		});
177
		myUp = newButton(buttons, Messages.Up, new SelectionAdapter() {
178
			@Override
179
			public void widgetSelected(SelectionEvent e) {
180
				Object selectedElement = getSelectedElement();
181
				if (selectedElement instanceof TaskModel) {
182
					int i = myModel.getTaskModels().indexOf(selectedElement);
183
					if (i > 0) {
184
						TaskModel p = myModel.getTaskModels().get(i - 1);
185
						myModel.getTaskModels().set(i - 1, (TaskModel) selectedElement);
186
						myModel.getTaskModels().set(i, p);
187
						myTreeViewer.refresh();
188
					}
189
				}
190
			}
191
		});
192
		myDown = newButton(buttons, Messages.Down, new SelectionAdapter() {
193
			@Override
194
			public void widgetSelected(SelectionEvent e) {
195
				Object selectedElement = getSelectedElement();
196
				if (selectedElement instanceof TaskModel) {
197
					int i = myModel.getTaskModels().indexOf(selectedElement);
198
					if (i < myModel.getTaskModels().size() - 1) {
199
						TaskModel n = myModel.getTaskModels().get(i + 1);
200
						myModel.getTaskModels().set(i + 1, (TaskModel) selectedElement);
201
						myModel.getTaskModels().set(i, n);
202
						myTreeViewer.refresh();
203
					}
204
				}
205
			}
206
		});
207
208
		setControl(container);
209
		updateButtons(StructuredSelection.EMPTY);
210
	}
211
212
	private Object getSelectedElement() {
213
		IStructuredSelection sel = (IStructuredSelection) myTreeViewer.getSelection();
214
		return sel.getFirstElement();
215
	}
216
217
	protected void updateButtons(ISelection selection) {
218
		IStructuredSelection sel = (IStructuredSelection) selection;
219
		Object firstElement = sel.getFirstElement();
220
		boolean up = false;
221
		boolean down = false;
222
		boolean del = false;
223
		if (firstElement instanceof TaskModel) {
224
			int i = myModel.getTaskModels().indexOf(firstElement);
225
			up = i > 0;
226
			down = i < myModel.getTaskModels().size() - 1;
227
			del = true;
228
		}
229
		myDelete.setEnabled(!selection.isEmpty() && del);
230
		myUp.setEnabled(!selection.isEmpty() && up);
231
		myDown.setEnabled(!selection.isEmpty() && down);
232
	}
233
234
	private static Button newButton(Composite buttons, String caption, SelectionListener listener) {
235
		Button button = new Button(buttons, SWT.PUSH);
236
		button.setText(caption);
237
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
238
		button.setLayoutData(gridData);
239
		button.addSelectionListener(listener);
240
		return button;
241
	}
242
243
	private static class DataProvider extends LabelProvider implements ITableLabelProvider, ITreeContentProvider {
244
245
		public String getColumnText(Object element, int columnIndex) {
246
			if (element instanceof TaskModel) {
247
				TaskModel value = (TaskModel) element;
248
				return columnIndex == 0 ? value.getTaskName() : " < " + value.getName() + " >"; //$NON-NLS-1$ //$NON-NLS-2$
249
			}
250
			if (element instanceof Map.Entry) {
251
				@SuppressWarnings("unchecked")
252
				Map.Entry<String, Object> value = (Entry<String, Object>) element;
253
				return columnIndex == 0 ? value.getKey() : String.valueOf(value.getValue());
254
			}
255
			return element.toString();
256
		}
257
258
		public Image getColumnImage(Object element, int columnIndex) {
259
			return null;
260
		}
261
262
		// ITreeContentProvider
263
		public Object[] getChildren(Object parentElement) {
264
			if (parentElement instanceof TaskModel) {
265
				TaskModel model = (TaskModel) parentElement;
266
				Set<Entry<String, Object>> entrySet = model.getAttributes().entrySet();
267
				for (Entry<String, Object> entry : entrySet) {
268
					myParentCache.put(entry, parentElement);
269
				}
270
				return entrySet.toArray();
271
			}
272
			return null;
273
		}
274
275
		public Object getParent(Object element) {
276
			return myParentCache.get(element);
277
		}
278
279
		public boolean hasChildren(Object element) {
280
			return element instanceof TaskModel;
281
		}
282
283
		public Object[] getElements(Object inputElement) {
284
			if (inputElement instanceof CompositeTransformationModel) {
285
				CompositeTransformationModel model = (CompositeTransformationModel) inputElement;
286
				return model.getTaskModels().toArray();
287
			}
288
			return null;
289
		}
290
291
		public void dispose() {
292
			myParentCache.clear();
293
		}
294
295
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
296
		}
297
298
		private final Map<Object, Object> myParentCache = new HashMap<Object, Object>();
299
	}
300
301
	@Override
302
	public void setVisible(boolean visible) {
303
		if (visible) {
304
			myWasEverShown = true;
305
		}
306
		super.setVisible(visible);
307
	}
308
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/CompositeTransformationModel.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.util.LinkedList;
15
import java.util.List;
16
17
class CompositeTransformationModel {
18
19
	private String myProjectName = "project"; //$NON-NLS-1$
20
21
	private String myTargetName = "default"; //$NON-NLS-1$
22
23
	private final List<TaskModel> myTaskModels = new LinkedList<TaskModel>();
24
25
	public String getProjectName() {
26
		return myProjectName;
27
	}
28
29
	public void setProjectName(String projectName) {
30
		myProjectName = projectName;
31
	}
32
33
	public String getTargetName() {
34
		return myTargetName;
35
	}
36
37
	public void setTargetName(String targetName) {
38
		myTargetName = targetName;
39
	}
40
41
	public List<TaskModel> getTaskModels() {
42
		return myTaskModels;
43
	}
44
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/AbstractCompositeWizardPage.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Composite;
19
20
abstract class AbstractCompositeWizardPage extends WizardPage {
21
22
	protected AbstractCompositeWizardPage(String pageName) {
23
		super(pageName);
24
	}
25
26
	public void createControl(Composite parent) {
27
		Composite composite = new Composite(parent, SWT.NULL);
28
		GridLayout layout = new GridLayout();
29
		setUpLayout(layout);
30
		composite.setLayout(layout);
31
32
		initializeDialogUnits(composite);
33
34
		doCreateControl(composite);
35
36
		setControl(composite);
37
		Dialog.applyDialogFont(parent);
38
	}
39
40
	protected abstract void doCreateControl(Composite parent);
41
42
	protected void setUpLayout(GridLayout layout) {
43
		layout.numColumns = 1;
44
	}
45
46
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/ResultPage.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Text;
18
19
public class ResultPage extends AbstractCompositeWizardPage {
20
21
	protected ResultPage() {
22
		super("ResultPage"); //$NON-NLS-1$
23
	}
24
25
	@Override
26
	public void doCreateControl(Composite parent) {
27
		setTitle(Messages.ResultPage_title);
28
		setDescription(Messages.ResultPage_descr);
29
30
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
31
32
		myTextField = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
33
		myTextField.setEditable(false);
34
		myTextField.setLayoutData(data);
35
	}
36
37
	public void setTextData(String textData) {
38
		myTextField.setText(textData);
39
	}
40
41
	private Text myTextField;
42
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/messages.properties (+32 lines)
Added Link Here
1
AntTaskWizard_windowTitle=New Operational QVT Ant Task
2
LaunchConfigError_title=Launch configuration error
3
LaunchConfigError_msg=An exception occurred while retrieving launch configurations
4
5
SourceTypePage_title=Choose data source type
6
SourceTypePage_descr=Decide where to get task data from
7
SourceTypePage_opt1=Enter data manually
8
SourceTypePage_opt2=Select existing launch configuration
9
10
SourcePage_title1=Select launch configuration
11
SourcePage_descr1=Here you need to select a launch configuration or create new launch configuration data
12
SourcePage_configBtn=New launch configuration data...
13
14
ResultPage_title=Preview
15
ResultPage_descr=Here you may preview the resulting XML before inserting it to your Ant code
16
17
TransformWizard_windowTitle=New Composite Transformation Wizard
18
19
TransformFilePage_title=Operational QVT Composite transformation
20
21
TransformPage_title=Composite transformation content
22
TransformPage_descr=Here you can specify transformation parameters and add transformation content
23
TransformPage_task=Default &task name:
24
TransformPage_project=&Project name:
25
26
Name=Name
27
Value=Value
28
29
Add=&Add
30
Delete=&Delete
31
Up=&Up
32
Down=&Down
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/CreateQvtoAntTaskWizard.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import org.eclipse.jface.wizard.IWizardPage;
15
import org.eclipse.jface.wizard.Wizard;
16
17
public class CreateQvtoAntTaskWizard extends Wizard {
18
19
	public CreateQvtoAntTaskWizard() {
20
		setWindowTitle(Messages.AntTaskWizard_windowTitle);
21
	}
22
23
	@Override
24
	public void addPages() {
25
		myChooseDataSourcePage = new ChooseDataSourcePage();
26
		addPage(myChooseDataSourcePage);
27
		myResultPage = new ResultPage();
28
		addPage(myResultPage);
29
		super.addPages();
30
	}
31
32
	@Override
33
	public IWizardPage getNextPage(IWizardPage page) {
34
		IWizardPage result = super.getNextPage(page);
35
		if (result == myResultPage) {
36
			myResultPage.setTextData(getResText());
37
		}
38
		return result;
39
	}
40
41
	private String getResText() {
42
		TaskModel taskModel = myChooseDataSourcePage.getTaskModel();
43
		return taskModel == null ? "" : taskModel.toString(); //$NON-NLS-1$
44
	}
45
46
	@Override
47
	public boolean canFinish() {
48
		if (getContainer().getCurrentPage() == myResultPage) {
49
			return true;
50
		}
51
		if (getContainer().getCurrentPage() == myChooseDataSourcePage) {
52
			return myChooseDataSourcePage.canFlipToNextPage();
53
		}
54
		return false;
55
	}
56
57
	@Override
58
	public boolean performFinish() {
59
		myResultText = getResText();
60
		myResult = myChooseDataSourcePage.getTaskModel();
61
		return true;
62
	}
63
64
	public String getResultText() {
65
		return myResultText;
66
	}
67
68
	public TaskModel getResult() {
69
		return myResult;
70
	}
71
72
	private ChooseDataSourcePage myChooseDataSourcePage;
73
	private ResultPage myResultPage;
74
	private String myResultText;
75
	private TaskModel myResult;
76
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/TaskModel.java (+194 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.util.Collections;
15
import java.util.Iterator;
16
import java.util.LinkedHashMap;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Map.Entry;
20
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.m2m.internal.qvt.oml.common.MdaException;
24
import org.eclipse.m2m.internal.qvt.oml.common.launch.IQvtLaunchConstants;
25
import org.eclipse.m2m.internal.qvt.oml.common.launch.TargetUriData;
26
import org.eclipse.m2m.internal.qvt.oml.runtime.launch.QvtLaunchConfigurationDelegateBase;
27
import org.eclipse.m2m.internal.qvt.oml.runtime.launch.QvtLaunchUtil;
28
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtInterpretedTransformation;
29
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation;
30
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter;
31
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter.DirectionKind;
32
33
/**
34
 * A model class for ant Task. toString renders task XML
35
 * 
36
 * @author abreslav
37
 * 
38
 */
39
public class TaskModel {
40
41
	public TaskModel(ILaunchConfiguration config, String name) throws CoreException {
42
		myTaskName = name;
43
44
        myModuleUri = config.getAttribute(IQvtLaunchConstants.MODULE, ""); //$NON-NLS-1$
45
        myTraceFile = config.getAttribute(IQvtLaunchConstants.TRACE_FILE, ""); //$NON-NLS-1$
46
        myIsUseTraceFile = config.getAttribute(IQvtLaunchConstants.USE_TRACE_FILE, false); 
47
    	myTargetUris = QvtLaunchUtil.getTargetUris(config);
48
    	myConfigProps = QvtLaunchUtil.getConfigurationProperty(config);
49
    	
50
    	myAttributes = new LinkedHashMap<String, Object>();
51
    	myAttributes.put(IQvtLaunchConstants.MODULE.substring(IQvtLaunchConstants.PREFIX.length()), myModuleUri);
52
    	myAttributes.put(IQvtLaunchConstants.TRACE_FILE.substring(IQvtLaunchConstants.PREFIX.length()), myTraceFile);
53
54
        myTransformation = new QvtInterpretedTransformation(QvtLaunchConfigurationDelegateBase.getQvtModule(config));
55
	}
56
	
57
	public String getTaskName() {
58
		return myTaskName;
59
	}
60
	
61
	public String getName() {
62
		try {
63
			return myTransformation.getModuleName();
64
		} catch (MdaException e) {
65
		}
66
		return ""; //$NON-NLS-1$
67
	}
68
69
	public Map<String, Object> getAttributes() {
70
		return Collections.unmodifiableMap(myAttributes);
71
	}
72
73
	@Override
74
	public String toString() {
75
		try {
76
			return toXMLString();
77
		} catch (MdaException e) {
78
		}
79
		return ""; //$NON-NLS-1$
80
	}
81
82
	/**
83
	 * @return Ant XML representation of the task
84
	 * @throws MdaException 
85
	 */
86
	public String toXMLString() throws MdaException {
87
		String result = ""; //$NON-NLS-1$
88
89
		result += "<" + myTaskName + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
90
		result += INDENT + "uri=\"" + myModuleUri + "\"\n";
91
		result += INDENT + ">\n";
92
		
93
		if (!myTargetUris.isEmpty()) {
94
			result += "\n";
95
		}
96
		Iterator<TargetUriData> itrTargetUri = myTargetUris.iterator();
97
		for (TransformationParameter transfParam : myTransformation.getParameters()) {
98
			if (!itrTargetUri.hasNext()) {
99
				break;
100
			}
101
			TargetUriData targetUri = itrTargetUri.next();
102
			
103
			if (transfParam.getDirectionKind() == DirectionKind.IN) {
104
				result += INDENT + "<in\n";
105
				result += INDENT + INDENT + "uri=\"" + targetUri.getUriString() + "\"\n";
106
				result += INDENT + "/>";
107
			}
108
			else if (transfParam.getDirectionKind() == DirectionKind.INOUT) {
109
				result += INDENT + "<inout\n";
110
				result += INDENT + INDENT + "uri=\"" + targetUri.getUriString() + "\"\n";
111
				result += INDENT + INDENT + "outuri=\"" + targetUri.getUriString() + "\"\n";
112
				result += INDENT + "/>";
113
			}
114
			else if (transfParam.getDirectionKind() == DirectionKind.OUT) {
115
				result += INDENT + "<out\n";
116
				result += INDENT + INDENT + "uri=\"" + targetUri.getUriString();
117
				String feature = targetUri.getFeature();
118
				if (feature != null && feature.trim().length() > 0) {
119
					result += "\">\n";
120
					result += INDENT + INDENT + "<feature\n";
121
					result += INDENT + INDENT + INDENT + "name=\"" + targetUri.getFeature() + "\"\n";
122
					result += INDENT + INDENT + INDENT + "clearcontents=\"" + Boolean.valueOf(targetUri.isClearContents()).toString() + "\"\n";
123
					result += INDENT + INDENT + "/>\n";
124
					result += INDENT + "</out>";
125
				}
126
				else {
127
					result += "\"\n";
128
					result += INDENT + "/>";
129
				}
130
			}
131
			result += "\n";
132
		}
133
		
134
		if (myIsUseTraceFile && myTraceFile != null && myTraceFile.trim().length() > 0) {
135
			result += "\n";
136
			result += INDENT + "<trace\n";
137
			result += INDENT + INDENT + "uri=\"" + myTraceFile + "\"\n";
138
			result += INDENT + "/>\n";
139
		}
140
		
141
		if (!myConfigProps.isEmpty()) {
142
			result += "\n";
143
			result += INDENT + "<configProperty\n";
144
		}
145
		for (Entry<String, Object> entry : myConfigProps.entrySet()) {
146
			Object value = entry.getValue();
147
			if (value != null && value.toString() != "") { //$NON-NLS-1$
148
				result += INDENT + INDENT + "name=\"" + entry.getKey() + "\"\n";
149
				result += INDENT + INDENT + "value=\"" + value + "\"\n"; //$NON-NLS-1$//$NON-NLS-2$
150
			}
151
		}
152
		if (!myConfigProps.isEmpty()) {
153
			result += INDENT + "/>\n";
154
		}
155
		
156
		result += "</" + myTaskName + ">\n"; //$NON-NLS-1$ //$NON-NLS-2$
157
		
158
		return result;
159
	}
160
161
	/**
162
	 * Indents a given string with given indent string. NOTE: The string must be
163
	 * separated with '\n' line delimiters
164
	 * 
165
	 * @param s -
166
	 *            a string to be indented
167
	 * @param indent -
168
	 *            an indent string to be added to the begining of the each line
169
	 *            in s
170
	 * @param delim -
171
	 *            line delimiter to separate resulting lines
172
	 * @return indented string
173
	 */
174
	public static String indentString(String s, String indent, String delim) {
175
		String result = ""; //$NON-NLS-1$
176
		String[] strings = s.split("\\n"); //$NON-NLS-1$
177
		for (int i = 0; i < strings.length; i++) {
178
			result += indent + strings[i] + ((i < strings.length - 1) ? delim : ""); //$NON-NLS-1$
179
		}
180
		return result;
181
	}
182
	
183
	private final String myTaskName;
184
	private final String myModuleUri;
185
	private final String myTraceFile;
186
	private final boolean myIsUseTraceFile;
187
	private final List<TargetUriData> myTargetUris;
188
	private final Map<String, Object> myConfigProps;
189
	private final QvtTransformation myTransformation;
190
	private final Map<String, Object> myAttributes;
191
	
192
	private static final String INDENT = "    "; //$NON-NLS-1$    
193
194
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/LaunchConfigurationTreeContentProvider.java (+222 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchConfigurationType;
23
import org.eclipse.debug.core.ILaunchManager;
24
import org.eclipse.jface.dialogs.ErrorDialog;
25
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.IPluginContribution;
29
import org.eclipse.ui.activities.WorkbenchActivityHelper;
30
31
/**
32
 * Content provider for representing launch configuration types & launch
33
 * configurations in a tree.
34
 */
35
class LaunchConfigurationTreeContentProvider implements ITreeContentProvider {
36
37
	/**
38
	 * Empty Object array
39
	 */
40
	private static final Object[] EMPTY_ARRAY = new Object[0];
41
42
	/**
43
	 * The mode in which the tree is being shown, one of <code>RUN_MODE</code>
44
	 * or <code>DEBUG_MODE</code> defined in <code>ILaunchManager</code>.
45
	 * If this is <code>null</code>, then it means both modes are being
46
	 * shown.
47
	 */
48
	private String fMode;
49
50
	/**
51
	 * The Shell context
52
	 */
53
	private Shell fShell;
54
55
	public LaunchConfigurationTreeContentProvider(String mode, Shell shell) {
56
		setMode(mode);
57
		setShell(shell);
58
	}
59
60
	/**
61
	 * Actual launch configurations have no children. Launch configuration types
62
	 * have all configurations of that type as children, minus any
63
	 * configurations that are marked as private.
64
	 * <p>
65
	 * In 2.1, the <code>category</code> attribute was added to launch config
66
	 * types. The debug UI only displays those configs that do not specify a
67
	 * category.
68
	 * </p>
69
	 * 
70
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
71
	 */
72
	public Object[] getChildren(Object parentElement) {
73
		if (parentElement instanceof ILaunchConfiguration) {
74
			return EMPTY_ARRAY;
75
		} else if (parentElement instanceof ILaunchConfigurationType) {
76
			try {
77
				ILaunchConfigurationType type = (ILaunchConfigurationType) parentElement;
78
				return getLaunchManager().getLaunchConfigurations(type);
79
			} catch (CoreException e) {
80
				errorDialog(getShell(), e.getStatus());
81
			}
82
		} else {
83
			return getLaunchManager().getLaunchConfigurationTypes();
84
		}
85
		return EMPTY_ARRAY;
86
	}
87
88
	public Object getParent(Object element) {
89
		if (element instanceof ILaunchConfiguration) {
90
			if (!((ILaunchConfiguration) element).exists()) {
91
				return null;
92
			}
93
			try {
94
				return ((ILaunchConfiguration) element).getType();
95
			} catch (CoreException e) {
96
				errorDialog(getShell(), e.getStatus());
97
			}
98
		} else if (element instanceof ILaunchConfigurationType) {
99
			return ResourcesPlugin.getWorkspace().getRoot();
100
		}
101
		return null;
102
	}
103
104
	public boolean hasChildren(Object element) {
105
		if (element instanceof ILaunchConfiguration) {
106
			return false;
107
		}
108
		return getChildren(element).length > 0;
109
	}
110
111
	/**
112
	 * Return only the launch configuration types that support the current mode
113
	 * AND are marked as 'public'.
114
	 * 
115
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
116
	 */
117
	public Object[] getElements(Object inputElement) {
118
		ILaunchConfigurationType[] allTypes = getLaunchManager().getLaunchConfigurationTypes();
119
		return filterTypes(allTypes).toArray();
120
	}
121
122
	/**
123
	 * Returns a list containing the given types minus any types that should not
124
	 * be visible. A type should not be visible if it doesn't match the current
125
	 * mode or if it matches a disabled activity.
126
	 * 
127
	 * @param allTypes
128
	 *            the types
129
	 * @return the given types minus any types that should not be visible.
130
	 */
131
	private List<ILaunchConfigurationType> filterTypes(ILaunchConfigurationType[] allTypes) {
132
		List<ILaunchConfigurationType> filteredTypes = new ArrayList<ILaunchConfigurationType>();
133
		String mode = getMode();
134
		LaunchConfigurationTypeContribution contribution;
135
		for (int i = 0; i < allTypes.length; i++) {
136
			ILaunchConfigurationType type = allTypes[i];
137
			contribution = new LaunchConfigurationTypeContribution(type);
138
			if (isVisible(type, mode) && !WorkbenchActivityHelper.filterItem(contribution)) {
139
				filteredTypes.add(type);
140
			}
141
		}
142
		return filteredTypes;
143
	}
144
145
	public void dispose() {
146
	}
147
148
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
149
	}
150
151
	/**
152
	 * Return <code>true</code> if the specified launch configuration type
153
	 * should be visible in the specified mode, <code>false</code> otherwise.
154
	 */
155
	private boolean isVisible(ILaunchConfigurationType configType, String mode) {
156
		if (!configType.isPublic()) {
157
			return false;
158
		}
159
		if (mode == null) {
160
			return true;
161
		}
162
		return configType.supportsMode(mode);
163
	}
164
165
	/**
166
	 * Convenience method to get the singleton launch manager.
167
	 */
168
	private ILaunchManager getLaunchManager() {
169
		return DebugPlugin.getDefault().getLaunchManager();
170
	}
171
172
	private void setMode(String mode) {
173
		fMode = mode;
174
	}
175
176
	private String getMode() {
177
		return fMode;
178
	}
179
180
	private void setShell(Shell shell) {
181
		fShell = shell;
182
	}
183
184
	private Shell getShell() {
185
		return fShell;
186
	}
187
188
	/**
189
	 * Utility method with conventions
190
	 */
191
	private static void errorDialog(Shell shell, IStatus s) {
192
		ErrorDialog.openError(shell, Messages.LaunchConfigError_title, Messages.LaunchConfigError_msg, s);
193
	}
194
195
	/**
196
	 * A plug-in contribution (UI element) which contains a launch configuration
197
	 * type (Core element). Plug-in contributions are passed to the workbench
198
	 * activity support to filter elements from the UI.
199
	 */
200
	private static class LaunchConfigurationTypeContribution implements IPluginContribution {
201
202
		protected ILaunchConfigurationType type;
203
204
		/**
205
		 * Creates a new plug-in contribution for the given type
206
		 * 
207
		 * @param type
208
		 *            the launch configuration type
209
		 */
210
		public LaunchConfigurationTypeContribution(ILaunchConfigurationType type) {
211
			this.type = type;
212
		}
213
214
		public String getLocalId() {
215
			return type.getIdentifier();
216
		}
217
218
		public String getPluginId() {
219
			return type.getPluginIdentifier();
220
		}
221
	}
222
}
(-)src/org/eclipse/m2m/internal/qvt/oml/runtime/ui/ant/ChooseDataSourcePage.java (+308 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Borland Software Corporation - initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.ant;
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationType;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.debug.core.ILaunchManager;
24
import org.eclipse.debug.ui.DebugUITools;
25
import org.eclipse.debug.ui.IDebugUIConstants;
26
import org.eclipse.debug.ui.ILaunchGroup;
27
import org.eclipse.jface.viewers.ILabelProvider;
28
import org.eclipse.jface.viewers.ILabelProviderListener;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelectionChangedListener;
31
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.ITreeContentProvider;
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.jface.viewers.TreeViewer;
35
import org.eclipse.jface.viewers.Viewer;
36
import org.eclipse.jface.viewers.ViewerFilter;
37
import org.eclipse.jface.window.Window;
38
import org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTask;
39
import org.eclipse.m2m.internal.qvt.oml.runtime.launch.QvtLaunchConfigurationDelegate;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.events.SelectionEvent;
42
import org.eclipse.swt.events.SelectionListener;
43
import org.eclipse.swt.graphics.Image;
44
import org.eclipse.swt.layout.GridData;
45
import org.eclipse.swt.layout.GridLayout;
46
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.ui.model.WorkbenchViewerComparator;
49
50
public class ChooseDataSourcePage extends AbstractCompositeWizardPage {
51
52
	protected ChooseDataSourcePage() {
53
		super("dataSourcePage"); //$NON-NLS-1$
54
        setTitle(Messages.SourcePage_title1);
55
        setDescription(Messages.SourcePage_descr1);
56
	}
57
	
58
	@Override
59
	public void setVisible(boolean visible) {
60
		if (visible && getSelectedLaunchConfiguration() == null) {
61
			myViewer.setSelection(new IStructuredSelection() {
62
				
63
				public Object getFirstElement() {
64
					Object[] array = toArray();
65
					if (array.length == 0) {
66
						return null;
67
					}
68
					return array[0];
69
				}
70
	
71
				public Iterator<Object> iterator() {
72
					return toList().iterator();
73
				}
74
	
75
				public int size() {
76
					return toArray().length;
77
				}
78
	
79
				public Object[] toArray() {
80
					return ((ITreeContentProvider) myViewer.getContentProvider()).getElements(null);
81
				}
82
	
83
				public List<Object> toList() {
84
					Object[] array = toArray();
85
					List<Object> list = new ArrayList<Object>(array.length);
86
					for (Object o : array) {
87
						list.add(o);
88
					}
89
					return list;
90
				}
91
	
92
				public boolean isEmpty() {
93
					return toArray().length > 0;
94
				}
95
				
96
			});
97
		}
98
		super.setVisible(visible);
99
	}
100
101
	@Override
102
	protected void doCreateControl(Composite parent) {
103
		myViewer = new TreeViewer(parent);
104
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
105
		myViewer.getControl().setLayoutData(data);
106
		myViewer.setLabelProvider(new TypeNamesWithTaskTypes(DebugUITools.newDebugModelPresentation()));
107
		myViewer.setComparator(new WorkbenchViewerComparator());
108
		myViewer.setContentProvider(new LaunchConfigurationTreeContentProvider(ILaunchManager.RUN_MODE, parent.getShell()));
109
		myViewer.addFilter(new AntFilter());
110
		myViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
111
		myViewer.expandAll();
112
113
		myViewer.addSelectionChangedListener(new ISelectionChangedListener() {
114
			public void selectionChanged(SelectionChangedEvent event) {
115
				getContainer().updateButtons();
116
				myConfigButton.setEnabled(getSelectedConfigType() != null);
117
			}
118
		});
119
120
		myConfigButton = new Button(parent, SWT.NULL);
121
		myConfigButton.setText(Messages.SourcePage_configBtn);
122
		myConfigButton.setEnabled(false);
123
		myConfigButton.addSelectionListener(new SelectionListener() {
124
125
			public void widgetSelected(SelectionEvent e) {
126
				ILaunchConfigurationType configType = getSelectedConfigType();
127
				if (configType == null) {
128
					return;
129
				}
130
				try {
131
					if ((myCreatedConfig == null) || (!configType.equals(myCreatedConfig.getType()))) {
132
						ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, "qvto.antTask.newConfiguration"); //$NON-NLS-1$
133
						wc.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true);
134
						myCreatedConfig = wc.doSave();
135
					}
136
					ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(myCreatedConfig, ILaunchManager.RUN_MODE);
137
					if (DebugUITools.openLaunchConfigurationPropertiesDialog(getShell(), myCreatedConfig, launchGroup.getIdentifier()) == Window.OK) {
138
						myConfig = myCreatedConfig;
139
						if (canFlipToNextPage()) {
140
							getContainer().showPage(getNextPage());
141
							myConfig = null;
142
						}
143
					}
144
					getContainer().updateButtons();
145
				} catch (CoreException e1) {
146
					e1.printStackTrace();
147
				}
148
			}
149
150
			public void widgetDefaultSelected(SelectionEvent e) {
151
				widgetSelected(e);
152
			}
153
		});
154
155
		Composite container = new Composite(parent, SWT.NULL);
156
		container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
157
		GridLayout layout = new GridLayout();
158
		container.setLayout(layout);
159
		layout.numColumns = 2;
160
		layout.verticalSpacing = 9;
161
	}
162
163
	@Override
164
	public boolean canFlipToNextPage() {
165
		setErrorMessage(null);
166
		myTaskModel = null;
167
		
168
		ILaunchConfiguration conf = getSelectedLaunchConfiguration();
169
		if (conf == null) {
170
			return false;
171
		}
172
		
173
		try {
174
			myTaskModel = new TaskModel(conf, QvtoAntTransformationTask.QVTO_ANTTASK_NAME);
175
		}
176
		catch (Exception e) {
177
			setErrorMessage(e.getMessage());
178
			return false;
179
		}
180
		
181
		return true;
182
	}
183
184
	public TaskModel getTaskModel() {
185
		return myTaskModel;
186
	}
187
188
	private ILaunchConfiguration getSelectedLaunchConfiguration() {
189
		if (myConfig != null) {
190
			return myConfig;
191
		}
192
		
193
		ISelection selection = myViewer.getSelection();
194
		if (selection instanceof IStructuredSelection) {
195
			IStructuredSelection ssel = (IStructuredSelection) selection;
196
			Object firstElement = ssel.getFirstElement();
197
			if (firstElement instanceof ILaunchConfiguration) {
198
				return (ILaunchConfiguration) firstElement;
199
			}
200
		}
201
		return null;
202
	}
203
	
204
	private ILaunchConfigurationType getSelectedConfigType() {
205
		ISelection selection = myViewer.getSelection();
206
		if (selection instanceof IStructuredSelection) {
207
			IStructuredSelection ssel = (IStructuredSelection) selection;
208
			Object firstElement = ssel.getFirstElement();
209
			if (firstElement instanceof ILaunchConfigurationType) {
210
				return (ILaunchConfigurationType) firstElement;
211
			}
212
			if (firstElement instanceof ILaunchConfiguration) {
213
				try {
214
					return ((ILaunchConfiguration) firstElement).getType();
215
				} catch (CoreException e) {
216
				}
217
			}
218
		}
219
		return null;
220
	}
221
	
222
	private class AntFilter extends ViewerFilter {
223
224
		@Override
225
		public boolean select(Viewer viewer, Object parentElement, Object element) {
226
			if (element instanceof ILaunchConfigurationType) {
227
				ILaunchConfigurationType type = (ILaunchConfigurationType) element;
228
				return isTypeSupported(type);
229
			}
230
			if (element instanceof ILaunchConfiguration) {
231
				ILaunchConfiguration config = (ILaunchConfiguration) element;
232
				boolean priv = false;
233
				try {
234
					priv = config.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false);
235
				} catch (CoreException e) {
236
					// Ignored
237
				}
238
				if (priv) {
239
					return false;
240
				}
241
				ILaunchConfigurationType type = null;
242
				try {
243
					type = config.getType();
244
				} catch (CoreException e) {
245
					return false;
246
				}
247
				return isTypeSupported(type);
248
			}
249
250
			return false;
251
		}
252
253
		private boolean isTypeSupported(ILaunchConfigurationType type) {
254
			return QvtLaunchConfigurationDelegate.LAUNCH_CONFIGURATION_TYPE_ID.equals(type.getIdentifier());
255
		}
256
257
	}
258
259
	private static class TypeNamesWithTaskTypes implements ILabelProvider {
260
261
		TypeNamesWithTaskTypes(ILabelProvider dmp) {
262
			myWrapped = dmp;
263
		}
264
265
		public Image getImage(Object element) {
266
			return myWrapped.getImage(element);
267
		}
268
269
		public String getText(Object element) {
270
			String suffix = ""; //$NON-NLS-1$
271
			if (element instanceof ILaunchConfigurationType) {
272
				ILaunchConfigurationType type = (ILaunchConfigurationType) element;
273
				suffix = " (" + getTaskName(type) + ")"; //$NON-NLS-1$//$NON-NLS-2$
274
			}
275
			return myWrapped.getText(element) + suffix;
276
		}
277
278
		private String getTaskName(ILaunchConfigurationType type) {
279
			return QvtoAntTransformationTask.QVTO_ANTTASK_NAME;
280
		}
281
282
		public void addListener(ILabelProviderListener listener) {
283
			myWrapped.addListener(listener);
284
		}
285
286
		public void dispose() {
287
			myWrapped.dispose();
288
		}
289
290
		public boolean isLabelProperty(Object element, String property) {
291
			return myWrapped.isLabelProperty(element, property);
292
		}
293
294
		public void removeListener(ILabelProviderListener listener) {
295
			myWrapped.removeListener(listener);
296
		}
297
298
		private final ILabelProvider myWrapped;
299
300
	}
301
302
	private TreeViewer myViewer;
303
	private Button myConfigButton;
304
	private ILaunchConfiguration myConfig;
305
	private ILaunchConfiguration myCreatedConfig;
306
	private TaskModel myTaskModel;
307
308
}

Return to bug 267493