Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 710b0fe3d22d6c8c54271c22612a4748e9cba87c (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
/*******************************************************************************
 *  Copyright (c) 2005, 2008 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.internal.ui.editor.plugin;

import org.eclipse.jface.dialogs.StatusDialog;
import org.eclipse.pde.core.plugin.IPluginImport;
import org.eclipse.pde.internal.core.text.bundle.ExportPackageObject;
import org.eclipse.pde.internal.core.text.bundle.ImportPackageObject;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
import org.eclipse.pde.internal.ui.parts.PluginVersionPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

// TODO this needs a rewrite along with PluginVersionPart
public class DependencyPropertiesDialog extends StatusDialog {

	private Button fReexportButton;
	private Button fOptionalButton;
	private boolean fEditable;
	private boolean fShowReexport;

	private boolean fExported;
	private boolean fOptional;

	private PluginVersionPart fVersionPart;

	private boolean fShowOptional;
	private String fVersion;
	private String fPluginId;

	public DependencyPropertiesDialog(boolean editable, IPluginImport plugin) {
		this(editable, true, plugin.isReexported(), plugin.isOptional(), plugin.getVersion(), true, true, plugin.getId());
	}

	public DependencyPropertiesDialog(boolean editable, ImportPackageObject object) {
		this(editable, false, false, object.isOptional(), object.getVersion(), true, true, null);
	}

	public DependencyPropertiesDialog(boolean editable, ExportPackageObject object) {
		this(editable, false, false, false, object.getVersion(), false, false, null);
	}

	public DependencyPropertiesDialog(boolean editable, boolean showReexport, boolean export, boolean optional, String version, boolean showOptional, boolean isImport, String pluginId) {
		super(PDEPlugin.getActiveWorkbenchShell());
		fEditable = editable;
		fShowReexport = showReexport;
		fExported = export;
		fOptional = optional;
		fShowOptional = showOptional;
		fPluginId = pluginId;
		if (isImport)
			fVersionPart = new PluginVersionPart(true);
		else
			fVersionPart = new PluginVersionPart(false) {
				protected String getGroupText() {
					return PDEUIMessages.DependencyPropertiesDialog_exportGroupText;
				}
			};
		fVersionPart.setVersion(version);
	}

	protected void createButtonsForButtonBar(Composite parent) {
		super.createButtonsForButtonBar(parent);
	}

	protected Control createDialogArea(Composite parent) {
		Composite comp = (Composite) super.createDialogArea(parent);

		if (fShowOptional || fShowReexport) {
			Group container = new Group(comp, SWT.NONE);
			container.setText(PDEUIMessages.DependencyPropertiesDialog_properties);
			container.setLayout(new GridLayout());
			container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

			if (fShowOptional) {
				fOptionalButton = new Button(container, SWT.CHECK);
				fOptionalButton.setText(PDEUIMessages.DependencyPropertiesDialog_optional);
				GridData gd = new GridData();
				gd.horizontalSpan = 2;
				fOptionalButton.setLayoutData(gd);
				fOptionalButton.setEnabled(fEditable);
				fOptionalButton.setSelection(fOptional);
			}

			if (fShowReexport) {
				fReexportButton = new Button(container, SWT.CHECK);
				fReexportButton.setText(PDEUIMessages.DependencyPropertiesDialog_reexport);
				GridData gd = new GridData();
				gd.horizontalSpan = 2;
				fReexportButton.setLayoutData(gd);
				fReexportButton.setEnabled(fEditable);
				fReexportButton.setSelection(fExported);
			}
		}

		fVersionPart.createVersionFields(comp, true, fEditable);
		ModifyListener ml = new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				updateStatus(fVersionPart.validateFullVersionRangeText(true));
			}
		};
		fVersionPart.addListeners(ml, ml);

		// we need a better way to do this
		if (fPluginId != null && !fPluginId.equals("system.bundle")) //$NON-NLS-1$
			fVersionPart.createVersionSelectionField(comp, fPluginId);

		return comp;
	}

	public boolean isReexported() {
		return fExported;
	}

	public boolean isOptional() {
		return fOptional;
	}

	public String getVersion() {
		return fVersion;
	}

	protected void okPressed() {
		fOptional = (fOptionalButton == null) ? false : fOptionalButton.getSelection();
		fExported = (fReexportButton == null) ? false : fReexportButton.getSelection();

		fVersion = fVersionPart.getVersion();

		super.okPressed();
	}
}

Back to the top