|
Lines 12-42
Link Here
|
| 12 |
package org.eclipse.hyades.trace.ui.internal.core; |
12 |
package org.eclipse.hyades.trace.ui.internal.core; |
| 13 |
|
13 |
|
| 14 |
import org.eclipse.hyades.trace.ui.UIPlugin; |
14 |
import org.eclipse.hyades.trace.ui.UIPlugin; |
| 15 |
import org.eclipse.hyades.trace.ui.internal.util.CList; |
|
|
| 16 |
import org.eclipse.hyades.ui.util.GridUtil; |
15 |
import org.eclipse.hyades.ui.util.GridUtil; |
|
|
16 |
import org.eclipse.jface.dialogs.Dialog; |
| 17 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 18 |
import org.eclipse.jface.window.Window; |
| 17 |
import org.eclipse.swt.SWT; |
19 |
import org.eclipse.swt.SWT; |
| 18 |
import org.eclipse.swt.events.ModifyEvent; |
20 |
import org.eclipse.swt.events.ModifyEvent; |
| 19 |
import org.eclipse.swt.events.ModifyListener; |
21 |
import org.eclipse.swt.events.ModifyListener; |
| 20 |
import org.eclipse.swt.events.SelectionAdapter; |
|
|
| 21 |
import org.eclipse.swt.events.SelectionEvent; |
22 |
import org.eclipse.swt.events.SelectionEvent; |
| 22 |
import org.eclipse.swt.events.SelectionListener; |
23 |
import org.eclipse.swt.events.SelectionListener; |
| 23 |
import org.eclipse.swt.events.TraverseEvent; |
|
|
| 24 |
import org.eclipse.swt.events.TraverseListener; |
| 25 |
import org.eclipse.swt.layout.GridData; |
24 |
import org.eclipse.swt.layout.GridData; |
| 26 |
import org.eclipse.swt.layout.GridLayout; |
25 |
import org.eclipse.swt.layout.GridLayout; |
| 27 |
import org.eclipse.swt.widgets.Button; |
26 |
import org.eclipse.swt.widgets.Button; |
| 28 |
import org.eclipse.swt.widgets.Composite; |
27 |
import org.eclipse.swt.widgets.Composite; |
|
|
28 |
import org.eclipse.swt.widgets.Control; |
| 29 |
import org.eclipse.swt.widgets.Display; |
| 29 |
import org.eclipse.swt.widgets.Label; |
30 |
import org.eclipse.swt.widgets.Label; |
|
|
31 |
import org.eclipse.swt.widgets.Shell; |
| 32 |
import org.eclipse.swt.widgets.Table; |
| 33 |
import org.eclipse.swt.widgets.TableItem; |
| 30 |
import org.eclipse.swt.widgets.Text; |
34 |
import org.eclipse.swt.widgets.Text; |
| 31 |
|
35 |
|
| 32 |
public class TraceLogUI implements SelectionListener, ModifyListener { |
36 |
public class TraceLogUI implements SelectionListener, ModifyListener { |
| 33 |
|
37 |
|
| 34 |
private CList _list; |
38 |
private Table _list; |
| 35 |
private Button _delete; |
39 |
private Button _delete; |
| 36 |
private Button _addAgent; |
40 |
private Button _addAgent; |
| 37 |
private Label _newAgentLabel; |
|
|
| 38 |
private Text _newAgent; |
41 |
private Text _newAgent; |
| 39 |
|
42 |
|
|
|
43 |
class AddAgentDialog extends Dialog implements ModifyListener { |
| 44 |
private Text agent; |
| 45 |
private String agentStr; |
| 46 |
|
| 47 |
public AddAgentDialog() { |
| 48 |
super(Display.getCurrent().getActiveShell()); |
| 49 |
} |
| 50 |
|
| 51 |
protected void configureShell(Shell shell) { |
| 52 |
super.configureShell(shell); |
| 53 |
shell.setText(UIPlugin.getResourceString("ADD_LOG_AGENT")); |
| 54 |
} |
| 55 |
|
| 56 |
protected Control createDialogArea(Composite parent) { |
| 57 |
Composite result = (Composite) super.createDialogArea(parent); |
| 58 |
|
| 59 |
GridLayout layout; |
| 60 |
GridData data; |
| 61 |
Label label; |
| 62 |
|
| 63 |
layout = new GridLayout(); |
| 64 |
layout.numColumns = 2; |
| 65 |
result.setLayout(layout); |
| 66 |
data = GridUtil.createFill(); |
| 67 |
data.widthHint = 400; |
| 68 |
result.setLayoutData(data); |
| 69 |
|
| 70 |
label = new Label(result, SWT.NONE); |
| 71 |
label.setText(UIPlugin.getResourceString("LOG_AGENT_LABEL")); |
| 72 |
agent = new Text(result, SWT.BORDER); |
| 73 |
agent.setLayoutData(GridUtil.createHorizontalFill()); |
| 74 |
|
| 75 |
agent.setText("logAgent"); |
| 76 |
agent.setFocus(); |
| 77 |
agent.selectAll(); |
| 78 |
|
| 79 |
return result; |
| 80 |
} |
| 81 |
|
| 82 |
public void modifyText(ModifyEvent e) { |
| 83 |
if (getButton(IDialogConstants.OK_ID) != null) |
| 84 |
getButton(IDialogConstants.OK_ID).setEnabled( |
| 85 |
agent.getText().trim().length() > 0); |
| 86 |
} |
| 87 |
|
| 88 |
protected void okPressed() { |
| 89 |
agentStr = agent.getText().trim(); |
| 90 |
super.okPressed(); |
| 91 |
} |
| 92 |
|
| 93 |
/* |
| 94 |
* Set the initial Ok button enablement. |
| 95 |
*/ |
| 96 |
protected Control createContents(Composite parent) { |
| 97 |
Control result = super.createContents(parent); |
| 98 |
getButton(IDialogConstants.OK_ID).setEnabled(agent.getText().trim().length() > 0); |
| 99 |
return result; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* @return Returns the agentStr. |
| 104 |
*/ |
| 105 |
public String getAgentName() { |
| 106 |
return agentStr; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 40 |
public TraceLogUI() { |
110 |
public TraceLogUI() { |
| 41 |
super(); |
111 |
super(); |
| 42 |
} |
112 |
} |
|
Lines 45-69
Link Here
|
| 45 |
* Creation date: (11/06/2000 3:38:47 PM) |
115 |
* Creation date: (11/06/2000 3:38:47 PM) |
| 46 |
*/ |
116 |
*/ |
| 47 |
protected void addAgent() { |
117 |
protected void addAgent() { |
| 48 |
String agentName = _newAgent.getText().trim(); |
118 |
|
| 49 |
|
119 |
AddAgentDialog dialog = new AddAgentDialog(); |
| 50 |
addAgent(agentName); |
120 |
dialog.open(); |
|
|
121 |
|
| 122 |
if (dialog.getReturnCode() == Window.OK) { |
| 123 |
|
| 124 |
addAgent(dialog.getAgentName()); |
| 125 |
} |
| 51 |
} |
126 |
} |
| 52 |
/** |
127 |
/** |
| 53 |
* Insert the method's description here. |
128 |
* Insert the method's description here. |
| 54 |
* Creation date: (4/30/2001 12:21:38 PM) |
129 |
* Creation date: (4/30/2001 12:21:38 PM) |
| 55 |
* @param name java.lang.String |
130 |
* @param name java.lang.String |
| 56 |
*/ |
131 |
*/ |
| 57 |
public void addAgent(String name) { |
132 |
public void addAgent(String text) { |
| 58 |
_list.add(name); |
133 |
|
| 59 |
_list.getList().setSelection(_list.getList().indexOf(name)); |
134 |
for (int idx = 0; idx < _list.getItemCount(); idx++) { |
|
|
135 |
if (text.equals(_list.getItem(idx).getText())) |
| 136 |
{ |
| 137 |
_list.select(idx); |
| 138 |
setAgentText(); |
| 139 |
return; |
| 140 |
} |
| 141 |
} |
| 60 |
|
142 |
|
| 61 |
_newAgent.setText(""); |
143 |
TableItem item = new TableItem(_list, SWT.NONE); |
| 62 |
_newAgent.setFocus(); |
144 |
item.setText(text); |
| 63 |
|
145 |
|
| 64 |
_addAgent.setEnabled(false); |
146 |
_list.setSelection(new TableItem[] { item }); |
| 65 |
_delete.setEnabled(true); |
147 |
setAgentText(); |
| 66 |
} |
148 |
} |
|
|
149 |
|
| 67 |
public Composite createControl(Composite parent) { |
150 |
public Composite createControl(Composite parent) { |
| 68 |
GridLayout layout; |
151 |
GridLayout layout; |
| 69 |
GridData gd; |
152 |
GridData gd; |
|
Lines 75-81
Link Here
|
| 75 |
_result.setLayout(layout); |
158 |
_result.setLayout(layout); |
| 76 |
_result.setLayoutData(GridUtil.createFill()); |
159 |
_result.setLayoutData(GridUtil.createFill()); |
| 77 |
|
160 |
|
| 78 |
_list = new CList(_result, ""); |
161 |
_list = new Table(_result, SWT.BORDER | SWT.H_SCROLL); |
|
|
162 |
gd = GridUtil.createFill(); |
| 163 |
_list.setLayoutData(gd); |
| 79 |
|
164 |
|
| 80 |
Composite buttons = new Composite(_result, SWT.NULL); |
165 |
Composite buttons = new Composite(_result, SWT.NULL); |
| 81 |
layout = new GridLayout(); |
166 |
layout = new GridLayout(); |
|
Lines 88-95
Link Here
|
| 88 |
gd.widthHint = 120; |
173 |
gd.widthHint = 120; |
| 89 |
buttons.setLayoutData(gd); |
174 |
buttons.setLayoutData(gd); |
| 90 |
|
175 |
|
|
|
176 |
_addAgent = new Button(buttons, SWT.PUSH); |
| 177 |
_addAgent.setText(UIPlugin.getResourceString("STR_PREF_ADD")); |
| 178 |
_addAgent.setLayoutData(GridUtil.createHorizontalFill()); |
| 179 |
|
| 91 |
_delete = new Button(buttons, SWT.PUSH | SWT.NULL); |
180 |
_delete = new Button(buttons, SWT.PUSH | SWT.NULL); |
| 92 |
_delete.setText(UIPlugin.getResourceString("REMOVE_AGENT")); |
181 |
_delete.setText(UIPlugin.getResourceString("REMOVE_TEXT")); |
| 93 |
_delete.setLayoutData(GridUtil.createHorizontalFill()); |
182 |
_delete.setLayoutData(GridUtil.createHorizontalFill()); |
| 94 |
Composite space = new Composite(buttons, SWT.NULL); |
183 |
Composite space = new Composite(buttons, SWT.NULL); |
| 95 |
space.setLayout(layout); |
184 |
space.setLayout(layout); |
|
Lines 102-160
Link Here
|
| 102 |
addAgent.setLayout(layout); |
191 |
addAgent.setLayout(layout); |
| 103 |
addAgent.setLayoutData(GridUtil.createHorizontalFill()); |
192 |
addAgent.setLayoutData(GridUtil.createHorizontalFill()); |
| 104 |
|
193 |
|
| 105 |
_newAgentLabel = new Label(addAgent, SWT.NULL); |
194 |
Label label = new Label(addAgent, SWT.NULL); |
| 106 |
_newAgentLabel.setText(UIPlugin.getResourceString("ADD_AGENT")); |
195 |
label.setText(UIPlugin.getResourceString("LOG_AGENT_LABEL")); |
| 107 |
_newAgent = new Text(addAgent, SWT.BORDER); |
196 |
_newAgent = new Text(addAgent, SWT.BORDER); |
| 108 |
_newAgent.setLayoutData(GridUtil.createHorizontalFill()); |
197 |
_newAgent.setLayoutData(GridUtil.createHorizontalFill()); |
| 109 |
|
198 |
|
| 110 |
Composite addButton = new Composite(_result, SWT.NULL); |
|
|
| 111 |
layout = new GridLayout(); |
| 112 |
layout.numColumns = 1; |
| 113 |
layout.verticalSpacing = 1; |
| 114 |
addButton.setLayout(layout); |
| 115 |
gd = new GridData(); |
| 116 |
gd.widthHint = 120; |
| 117 |
addButton.setLayoutData(gd); |
| 118 |
|
| 119 |
_addAgent = new Button(addButton, SWT.PUSH); |
| 120 |
_addAgent.setText(UIPlugin.getResourceString("ADD_AGENT_BUTTON")); |
| 121 |
_addAgent.setLayoutData(GridUtil.createHorizontalFill()); |
| 122 |
|
| 123 |
_addAgent.setEnabled(false); |
| 124 |
_delete.setEnabled(false); |
| 125 |
|
| 126 |
_delete.addSelectionListener(this); |
199 |
_delete.addSelectionListener(this); |
| 127 |
_addAgent.addSelectionListener(this); |
200 |
_addAgent.addSelectionListener(this); |
| 128 |
_newAgent.addModifyListener(this); |
201 |
_newAgent.addModifyListener(this); |
| 129 |
|
202 |
|
| 130 |
/*_newAgent.addKeyListener(new KeyAdapter() { |
203 |
_list.addSelectionListener(this); |
| 131 |
public void keyReleased(KeyEvent key) { |
|
|
| 132 |
if (key.character == 13) |
| 133 |
addAgent(); |
| 134 |
} |
| 135 |
});*/ |
| 136 |
|
| 137 |
_newAgent.addTraverseListener(new TraverseListener() { |
| 138 |
public void keyTraversed(TraverseEvent e) { |
| 139 |
if (e.detail == SWT.TRAVERSE_RETURN) { |
| 140 |
addAgent(); |
| 141 |
e.doit = false; |
| 142 |
} |
| 143 |
} |
| 144 |
}); |
| 145 |
|
| 146 |
_list.getList().addSelectionListener(new SelectionAdapter() { |
| 147 |
public void widgetSelected(SelectionEvent e) { |
| 148 |
_delete.setEnabled(_list.getSelectedIndices().length > 0); |
| 149 |
} |
| 150 |
}); |
| 151 |
|
204 |
|
| 152 |
_newAgent.setFocus(); |
205 |
_delete.setEnabled(false); |
| 153 |
|
206 |
|
| 154 |
return _result; |
207 |
return _result; |
| 155 |
} |
208 |
} |
| 156 |
public String[] getAgents() { |
209 |
public String[] getAgents() { |
| 157 |
return _list.getList().getItems(); |
210 |
|
|
|
211 |
TableItem[] items = _list.getItems(); |
| 212 |
String[] agents = new String[items.length]; |
| 213 |
|
| 214 |
for(int idx=0; idx<items.length; idx++) |
| 215 |
{ |
| 216 |
agents[idx]=items[idx].getText(); |
| 217 |
} |
| 218 |
|
| 219 |
return agents; |
| 158 |
} |
220 |
} |
| 159 |
/** |
221 |
/** |
| 160 |
* Insert the method's description here. |
222 |
* Insert the method's description here. |
|
Lines 163-199
Link Here
|
| 163 |
*/ |
225 |
*/ |
| 164 |
public void modifyText(ModifyEvent event) { |
226 |
public void modifyText(ModifyEvent event) { |
| 165 |
if (event.widget == _newAgent) |
227 |
if (event.widget == _newAgent) |
| 166 |
_addAgent.setEnabled(!_newAgent.getText().trim().equals("")); |
228 |
{ |
|
|
229 |
TableItem[] selected = _list.getSelection(); |
| 230 |
if(selected.length > 0) |
| 231 |
{ |
| 232 |
selected[0].setText(_newAgent.getText().trim()); |
| 233 |
} |
| 234 |
} |
| 167 |
} |
235 |
} |
| 168 |
/** |
236 |
/** |
| 169 |
* Insert the method's description here. |
237 |
* Insert the method's description here. |
| 170 |
* Creation date: (11/06/2000 3:52:27 PM) |
238 |
* Creation date: (11/06/2000 3:52:27 PM) |
| 171 |
*/ |
239 |
*/ |
| 172 |
protected void removeAgent() { |
240 |
protected void removeAgent() { |
| 173 |
int selection = _list.getSelectedIndex(); |
241 |
int i = _list.getSelectionIndex(); |
| 174 |
_list.remove(selection); |
242 |
if (i != -1) |
| 175 |
|
243 |
_list.remove(i); |
| 176 |
if (_list.getItemCount() > 0) { |
244 |
|
| 177 |
if (selection == 0) |
245 |
_newAgent.setText(""); |
| 178 |
_list.setSelectedIndex(0); |
|
|
| 179 |
if (selection < _list.getItemCount()) |
| 180 |
_list.setSelectedIndex(selection); |
| 181 |
else if ((selection - 1) < _list.getItemCount()) |
| 182 |
_list.setSelectedIndex(selection - 1); |
| 183 |
else |
| 184 |
_list.setSelectedIndex(0); |
| 185 |
} else |
| 186 |
_delete.setEnabled(false); |
| 187 |
|
| 188 |
_newAgent.setFocus(); |
| 189 |
_newAgent.selectAll(); |
| 190 |
} |
246 |
} |
| 191 |
/** |
247 |
/** |
| 192 |
* Insert the method's description here. |
248 |
* Insert the method's description here. |
| 193 |
* Creation date: (4/30/2001 12:22:33 PM) |
249 |
* Creation date: (4/30/2001 12:22:33 PM) |
| 194 |
*/ |
250 |
*/ |
| 195 |
public void reset() { |
251 |
public void reset() { |
| 196 |
_list.getList().removeAll(); |
252 |
_list.removeAll(); |
| 197 |
_delete.setEnabled(false); |
253 |
_delete.setEnabled(false); |
| 198 |
} |
254 |
} |
| 199 |
/** |
255 |
/** |
|
Lines 213-217
Link Here
|
| 213 |
addAgent(); |
269 |
addAgent(); |
| 214 |
else if (event.widget == _delete) |
270 |
else if (event.widget == _delete) |
| 215 |
removeAgent(); |
271 |
removeAgent(); |
|
|
272 |
else if (event.widget == _list) { |
| 273 |
_delete.setEnabled(_list.getSelectionIndex() != -1); |
| 274 |
setAgentText(); |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
private void setAgentText() |
| 279 |
{ |
| 280 |
TableItem[] selected = _list.getSelection(); |
| 281 |
if(selected.length > 0) |
| 282 |
{ |
| 283 |
_newAgent.setText(selected[0].getText()); |
| 284 |
} |
| 285 |
else |
| 286 |
{ |
| 287 |
_newAgent.setText(""); |
| 288 |
} |
| 289 |
|
| 216 |
} |
290 |
} |
|
|
291 |
|
| 217 |
} |
292 |
} |