Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9bae72fb99e9df7a9f82a27843dc401506153707 (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
/*****************************************************************************
 * Copyright (c) 2014 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:
 *  CEA LIST - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.moka.ui.launch;

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog;
import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.model.WorkbenchLabelProvider;

public class MokaProjectSelection extends SelectionAdapter {

	private static final String DIALOG_NAME = "Please select an fUML model";

	protected transient Text projectSelection;

	protected transient IFile currentSelection;

	protected transient MokaRunConfigurationTab launchConfigTab;

	public MokaProjectSelection(Text projectSelection, MokaRunConfigurationTab tab) {
		this.projectSelection = projectSelection;
		this.launchConfigTab = tab;
	}

	@Override
	public void widgetSelected(SelectionEvent event) {
		TreeSelectorDialog dialog = new TreeSelectorDialog(Display.getCurrent().getActiveShell());
		dialog.setTitle(DIALOG_NAME);
		dialog.setContentProvider(new WorkspaceContentProvider());
		dialog.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());

		if (this.currentSelection != null && this.currentSelection.exists()) {
			dialog.setInitialSelections(new IFile[] { this.currentSelection });
		}

		dialog.open();
		Object[] selection = dialog.getResult();
		if (dialog.getReturnCode() == Window.OK && selection.length > 0 && (selection[0] instanceof IFile)) {
			this.currentSelection = (IFile) selection[0];
			URI fileURI = URI.createPlatformResourceURI(this.currentSelection.getFullPath().toString(), true);
			this.projectSelection.setText(fileURI.toString());
			if (this.launchConfigTab != null) {
				this.launchConfigTab.updateLaunchConfigurationDialog();
			}
		}
	}
}

Back to the top