Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ui.internal.ide.dialogs; |
13 |
|
14 |
import java.util.Set; |
15 |
|
16 |
import org.eclipse.core.resources.IPathVariableManager; |
17 |
import org.eclipse.jface.dialogs.Dialog; |
18 |
import org.eclipse.jface.dialogs.IDialogConstants; |
19 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
20 |
import org.eclipse.swt.SWT; |
21 |
import org.eclipse.swt.layout.FormAttachment; |
22 |
import org.eclipse.swt.layout.FormData; |
23 |
import org.eclipse.swt.layout.FormLayout; |
24 |
import org.eclipse.swt.layout.GridData; |
25 |
import org.eclipse.swt.widgets.Button; |
26 |
import org.eclipse.swt.widgets.Composite; |
27 |
import org.eclipse.swt.widgets.Control; |
28 |
import org.eclipse.swt.widgets.Label; |
29 |
import org.eclipse.swt.widgets.List; |
30 |
import org.eclipse.swt.widgets.Shell; |
31 |
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; |
32 |
|
33 |
/** |
34 |
* @since 3.4 |
35 |
* |
36 |
*/ |
37 |
public class MissingPathVariableDialog extends TitleAreaDialog { |
38 |
|
39 |
private Set missingNames; |
40 |
private IPathVariableManager manager; |
41 |
private Label variableNameLabel; |
42 |
private List variableNameField; |
43 |
private Button okButton; |
44 |
|
45 |
/** |
46 |
* @param parentShell |
47 |
*/ |
48 |
public MissingPathVariableDialog(Shell parentShell, IPathVariableManager manager, Set missingNames) { |
49 |
super(parentShell); |
50 |
this.missingNames = missingNames; |
51 |
this.manager = manager; |
52 |
this.manager.getPathVariableNames(); |
53 |
} |
54 |
|
55 |
/* (non-Javadoc) |
56 |
* @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
57 |
*/ |
58 |
protected Control createDialogArea(Composite parent) { |
59 |
// top level composite |
60 |
Composite parentComposite = (Composite) super.createDialogArea(parent); |
61 |
|
62 |
initializeDialogUnits(parentComposite); |
63 |
|
64 |
// creates dialog area composite |
65 |
Composite contents = createComposite(parentComposite); |
66 |
|
67 |
// creates and lay outs dialog area widgets |
68 |
createWidgets(contents); |
69 |
|
70 |
|
71 |
Dialog.applyDialogFont(parentComposite); |
72 |
|
73 |
return contents; |
74 |
} |
75 |
|
76 |
/** |
77 |
* Creates and configures this dialog's main composite. |
78 |
* |
79 |
* @param parentComposite parent's composite |
80 |
* @return this dialog's main composite |
81 |
*/ |
82 |
private Composite createComposite(Composite parentComposite) { |
83 |
// creates a composite with standard margins and spacing |
84 |
Composite contents = new Composite(parentComposite, SWT.NONE); |
85 |
|
86 |
FormLayout layout = new FormLayout(); |
87 |
|
88 |
contents.setLayout(layout); |
89 |
contents.setLayoutData(new GridData(GridData.FILL_BOTH)); |
90 |
|
91 |
setTitle(IDEWorkbenchMessages.PathVariableDialog_dialogTitle_newVariable); |
92 |
setMessage(IDEWorkbenchMessages.PathVariableDialog_message_newVariable); |
93 |
return contents; |
94 |
} |
95 |
|
96 |
/** |
97 |
* Creates widgets for this dialog. |
98 |
* |
99 |
* @param contents the parent composite where to create widgets |
100 |
*/ |
101 |
private void createWidgets(Composite contents) { |
102 |
FormData data; |
103 |
|
104 |
String nameLabelText = IDEWorkbenchMessages.PathVariableDialog_variableName; |
105 |
|
106 |
// variable name label |
107 |
variableNameLabel = new Label(contents, SWT.LEFT); |
108 |
variableNameLabel.setText(nameLabelText); |
109 |
|
110 |
data = new FormData(); |
111 |
data.top = new FormAttachment(0, |
112 |
convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN)); |
113 |
data.left = new FormAttachment(0, |
114 |
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN)); |
115 |
variableNameLabel.setLayoutData(data); |
116 |
|
117 |
// variable name field. Attachments done after all widgets created. |
118 |
variableNameField = new List(contents, SWT.SINGLE | SWT.BORDER); |
119 |
String[] names = new String[missingNames.size()]; |
120 |
variableNameField.setItems((String[])this.missingNames.toArray(names)); |
121 |
|
122 |
|
123 |
data = new FormData(); |
124 |
data.left = new FormAttachment(0, |
125 |
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN)); |
126 |
data.top = new FormAttachment(variableNameLabel, |
127 |
convertVerticalDLUsToPixels(5)); |
128 |
|
129 |
|
130 |
data = new FormData(); |
131 |
data.left = new FormAttachment(variableNameLabel, |
132 |
convertHorizontalDLUsToPixels(5)); |
133 |
data.top = new FormAttachment(variableNameLabel, |
134 |
convertVerticalDLUsToPixels(5), SWT.CENTER); |
135 |
variableNameField.setLayoutData(data); |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
} |
141 |
|
142 |
/** |
143 |
* Adds buttons to this dialog's button bar. |
144 |
* |
145 |
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar |
146 |
*/ |
147 |
protected void createButtonsForButtonBar(Composite parent) { |
148 |
okButton = createButton(parent, IDialogConstants.OK_ID, |
149 |
IDialogConstants.OK_LABEL, true); |
150 |
okButton.setEnabled(true); |
151 |
|
152 |
createButton(parent, IDialogConstants.CANCEL_ID, |
153 |
IDialogConstants.CANCEL_LABEL, false); |
154 |
} |
155 |
|
156 |
} |