View Javadoc

1   /*
2    *  
3    *  Fosstrak LLRP Commander (www.fosstrak.org)
4    * 
5    *  Copyright (C) 2008 ETH Zurich
6    *
7    *  This program is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  This program is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with this program.  If not, see <http://www.gnu.org/licenses/> 
19   *
20   */
21  
22  package org.fosstrak.llrp.commander.editors.graphical;
23  
24  import java.util.LinkedList;
25  
26  import org.eclipse.jface.action.Action;
27  import org.eclipse.jface.action.ToolBarManager;
28  import org.eclipse.jface.fieldassist.ControlDecoration;
29  import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
30  import org.eclipse.jface.resource.ImageDescriptor;
31  import org.eclipse.jface.viewers.DoubleClickEvent;
32  import org.eclipse.jface.viewers.IDoubleClickListener;
33  import org.eclipse.jface.viewers.ISelection;
34  import org.eclipse.jface.viewers.IStructuredContentProvider;
35  import org.eclipse.jface.viewers.IStructuredSelection;
36  import org.eclipse.jface.viewers.StructuredSelection;
37  import org.eclipse.jface.viewers.TableViewer;
38  import org.eclipse.jface.viewers.TreeViewer;
39  import org.eclipse.jface.viewers.Viewer;
40  import org.eclipse.swt.SWT;
41  import org.eclipse.swt.SWTError;
42  import org.eclipse.swt.browser.Browser;
43  import org.eclipse.swt.events.ControlAdapter;
44  import org.eclipse.swt.events.ControlEvent;
45  import org.eclipse.swt.events.DisposeEvent;
46  import org.eclipse.swt.events.DisposeListener;
47  import org.eclipse.swt.events.ModifyEvent;
48  import org.eclipse.swt.events.ModifyListener;
49  import org.eclipse.swt.events.SelectionEvent;
50  import org.eclipse.swt.events.SelectionListener;
51  import org.eclipse.swt.events.VerifyEvent;
52  import org.eclipse.swt.events.VerifyListener;
53  import org.eclipse.swt.graphics.Cursor;
54  import org.eclipse.swt.graphics.Image;
55  import org.eclipse.swt.layout.GridData;
56  import org.eclipse.swt.layout.GridLayout;
57  import org.eclipse.swt.widgets.Combo;
58  import org.eclipse.swt.widgets.Composite;
59  import org.eclipse.swt.widgets.Control;
60  import org.eclipse.swt.widgets.Display;
61  import org.eclipse.swt.widgets.Event;
62  import org.eclipse.swt.widgets.Label;
63  import org.eclipse.swt.widgets.Listener;
64  import org.eclipse.swt.widgets.Shell;
65  import org.eclipse.swt.widgets.Table;
66  import org.eclipse.swt.widgets.Text;
67  import org.eclipse.swt.widgets.ToolBar;
68  import org.eclipse.ui.PlatformUI;
69  import org.eclipse.ui.forms.IDetailsPage;
70  import org.eclipse.ui.forms.IFormPart;
71  import org.eclipse.ui.forms.IManagedForm;
72  import org.eclipse.ui.forms.events.HyperlinkAdapter;
73  import org.eclipse.ui.forms.events.HyperlinkEvent;
74  import org.eclipse.ui.forms.widgets.FormToolkit;
75  import org.eclipse.ui.forms.widgets.Hyperlink;
76  import org.eclipse.ui.forms.widgets.Section;
77  import org.eclipse.ui.forms.widgets.TableWrapData;
78  import org.eclipse.ui.forms.widgets.TableWrapLayout;
79  import org.fosstrak.llrp.commander.ResourceCenter;
80  import org.fosstrak.llrp.commander.util.LLRP;
81  import org.fosstrak.llrp.commander.util.LLRPFactory;
82  import org.fosstrak.llrp.commander.util.LLRPTreeMaintainer;
83  import org.llrp.ltk.types.LLRPEnumeration;
84  import org.llrp.ltk.types.LLRPParameter;
85  import org.llrp.ltk.types.LLRPType;
86  import org.llrp.ltkGenerator.generated.ChoiceReference;
87  import org.llrp.ltkGenerator.generated.EnumerationDefinition;
88  import org.llrp.ltkGenerator.generated.EnumerationEntryDefinition;
89  import org.llrp.ltkGenerator.generated.FieldDefinition;
90  import org.llrp.ltkGenerator.generated.MessageDefinition;
91  import org.llrp.ltkGenerator.generated.ParameterDefinition;
92  import org.llrp.ltkGenerator.generated.ParameterReference;
93  
94  /**
95   * The LLRPDetailsPage shows details about the message/parameter currently selected in the
96   * master part.
97   *
98   * @author Ulrich Etter, ETHZ
99   *
100  */
101 public class LLRPDetailsPage implements IDetailsPage {
102 	private IManagedForm mform;
103 	private Object input;
104 	private LLRPTreeMaintainer treeMaintainer;
105 	private Section section;
106 	
107 	private java.util.List<ModifyListener> textModifyListeners = new LinkedList<ModifyListener>();
108 	private java.util.List<VerifyListener> textVerifyListeners = new LinkedList<VerifyListener>();
109 	private java.util.List<Text> texts = new LinkedList<Text>();
110 	private java.util.List<ControlDecoration> textControlDecorations = new LinkedList<ControlDecoration>();
111 	
112 	private java.util.List<Combo> combos = new LinkedList<Combo>();
113 	private java.util.List<ControlDecoration> comboControlDecorations = new LinkedList<ControlDecoration>();
114 	
115 	private java.util.List<TableViewer> tableViewers = new LinkedList<TableViewer>();
116 	private java.util.List<ControlDecoration> tableViewerControlDecorations = new LinkedList<ControlDecoration>();
117 	
118 	private java.util.List<Hyperlink> hyperlinks = new LinkedList<Hyperlink>();
119 	private java.util.List<ControlDecoration> hyperlinkControlDecorations = new LinkedList<ControlDecoration>();
120 	
121 	private TreeViewer treeViewer;
122 	private LLRPMasterDetailsBlock block;
123 	
124 	/**
125 	 * Creates a new LLRPDetailsPage.
126 	 * 
127 	 * @param input the object for which this page should show details (either a LLRPMessage or a LLRPParameter)
128 	 * @param treeViewer the tree viewer of the master part
129 	 * @param treeMaintainer the TreeMaintainer associated with the input object
130 	 * @param block the LLRPMasterDetailsBlock
131 	 */
132 	public LLRPDetailsPage(Object input, TreeViewer treeViewer, 
133 			LLRPTreeMaintainer treeMaintainer, LLRPMasterDetailsBlock block) {
134 		this.input = input;
135 		this.treeViewer = treeViewer;
136 		this.treeMaintainer = treeMaintainer;
137 		this.block = block;
138 	}
139 	
140 	/* (non-Javadoc)
141 	 * @see org.eclipse.ui.forms.IDetailsPage#initialize(org.eclipse.ui.forms.IManagedForm)
142 	 */
143 	public void initialize(IManagedForm mform) {
144 		this.mform = mform;
145 	}
146 	
147 	/* (non-Javadoc)
148 	 * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
149 	 */
150 	public void createContents(Composite parent) {
151 
152 		TableWrapLayout layout = new TableWrapLayout();
153 		layout.topMargin = 5;
154 		layout.leftMargin = 5;
155 		layout.rightMargin = 2;
156 		layout.bottomMargin = 2;
157 		parent.setLayout(layout);
158 		
159 		FormToolkit toolkit = mform.getToolkit();
160 		section = toolkit.createSection(parent, Section.TITLE_BAR);
161 		section.marginWidth = 10;
162 		section.setText(treeMaintainer.getName(input));
163 		TableWrapData td = new TableWrapData(TableWrapData.FILL, TableWrapData.TOP);
164 		td.grabHorizontal = true;
165 		section.setLayoutData(td);
166 		createSectionToolbar(toolkit);
167 		
168 		Composite client = toolkit.createComposite(section);
169 		GridLayout gridLayout = new GridLayout();
170 		gridLayout.marginWidth = 0;
171 		gridLayout.marginHeight = 0;
172 		gridLayout.horizontalSpacing = 10;
173 		gridLayout.numColumns = 2;
174 		client.setLayout(gridLayout);
175 		
176 		createFieldControls(client, toolkit);
177 		createListAndParameterControls(client, toolkit);
178 		
179 		toolkit.paintBordersFor(section);
180 		section.setClient(client);
181 	}
182 	
183 	private void createSectionToolbar(FormToolkit toolkit) {
184 		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
185 		ToolBar toolbar = toolBarManager.createControl(section);
186 		final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
187 		toolbar.setCursor(handCursor);
188 		// Cursor needs to be explicitly disposed
189 		toolbar.addDisposeListener(new DisposeListener() {
190 			public void widgetDisposed(DisposeEvent e) {
191 				if ((handCursor != null) &&
192 						(handCursor.isDisposed() == false)) {
193 					handCursor.dispose();
194 				}
195 			}
196 		});	
197 		Action descriptionAction = createDescriptionAction();
198 		if (descriptionAction != null){
199 			toolBarManager.add(descriptionAction);
200 			toolBarManager.update(true);
201 			section.setTextClient(toolbar);
202 		}
203 	}
204 
205 	/**
206 	 * Creates an action that opens a pop-up window and displays the description of the current message/parameter.
207 	 * 
208 	 * @return the action or <code>null</code> if there is no description for the current message/parameter or if 
209 	 * the SWT browser widget is not supported on this platform
210 	 */
211 	private Action createDescriptionAction() {
212 		final String description = LLRP.getDescription(treeMaintainer.getDefinition(input));
213 		if (description == null || description.equals("")){
214 			return null;
215 		}
216 		try {
217 			// try to create a browser widget
218 			Shell popUp = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SHELL_TRIM);
219 			Browser browser = new Browser(popUp, SWT.NONE);
220 		} catch (SWTError e) {
221 			// browser widget is not available on this platform -> don't provide "description" action
222 			return null;
223 		}
224 		Action descriptionAction = new Action(){
225 			public void run() {				
226 				final Shell popUp = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SHELL_TRIM);
227 				popUp.setText(treeMaintainer.getName(input));
228 				popUp.setSize(800, 400);
229 				final Browser browser = new Browser(popUp, SWT.NONE);
230 				int fontHeight = section.getFont().getFontData()[0].getHeight();
231 				String fontName = section.getFont().getFontData()[0].getName();
232 				String css = "overflow:auto;font-family:" + fontName + ";font-size:" + fontHeight + "pt";
233 				String html = "<html><body style='" + css + "'>" + description + "</body></html>";
234 				browser.setText(html);
235 				
236 				// disable browser context menu
237 				browser.addListener(SWT.MenuDetect, new Listener() {
238 					public void handleEvent(Event event) {
239 						event.doit = false;
240 					}
241 				});
242 				
243 				browser.setSize(popUp.getClientArea().width, popUp.getClientArea().height);
244 				popUp.addControlListener(new ControlAdapter() {
245 					public void controlResized(ControlEvent e) {
246 						browser.setSize(popUp.getClientArea().width, popUp.getClientArea().height);
247 					}
248 				});
249 				popUp.open();
250 			}
251 		};
252 		descriptionAction.setToolTipText("Show Description");
253 		ImageDescriptor imageDescriptor = ResourceCenter.getInstance().getImageDescriptor("information.gif");
254 		descriptionAction.setImageDescriptor(imageDescriptor);
255 		return descriptionAction;
256 	}
257 
258 	private void createFieldControls(Composite client, FormToolkit toolkit) {
259 		java.util.List<FieldDefinition> fieldDefinitions = LLRP.getFieldDefinitions(treeMaintainer.getDefinition(input));
260 		for (int i = 0; i < fieldDefinitions.size(); i++){
261 			final FieldDefinition fieldDefinition = fieldDefinitions.get(i);
262 			toolkit.createLabel(client, fieldDefinition.getName() + ":");
263 			if (LLRP.isEnumeration(fieldDefinition)){
264 				Combo combo = createFieldCombo(client, toolkit, fieldDefinition);
265 				combos.add(combo);
266 			}
267 			else{
268 				Text text = createFieldText(client, toolkit, fieldDefinition);
269 				text.setToolTipText(LLRP.getFieldType(fieldDefinition));
270 				texts.add(text);
271 			}
272 		}
273 	}
274 	
275 	private Combo createFieldCombo(Composite client, FormToolkit toolkit, final FieldDefinition fieldDefinition) {
276 		final Combo combo = new Combo(client, SWT.READ_ONLY);
277 		final ControlDecoration controlDecoration = createControlDecoration(combo);
278 		comboControlDecorations.add(controlDecoration);
279 		EnumerationDefinition enumerationDefinition = LLRP.getEnumerationDefinition(fieldDefinition.getEnumeration());
280 		if (enumerationDefinition != null){
281 			java.util.List<EnumerationEntryDefinition> list = enumerationDefinition.getEntry();
282 			for (EnumerationEntryDefinition e : list){
283 				combo.add(e.getName());
284 			}
285 		}
286 		combo.addSelectionListener(new SelectionListener(){
287 			
288 			public void widgetDefaultSelected(SelectionEvent e) {
289 				widgetSelected(e);
290 			}
291 			
292 			public void widgetSelected(SelectionEvent e) {
293 				if (input != null){
294 					LLRPEnumeration field = (LLRPEnumeration) treeMaintainer.getField(input, fieldDefinition.getName());
295 					Class fieldClass;
296 					try {
297 						fieldClass = Class.forName("org.llrp.ltk.generated.enumerations." + fieldDefinition.getEnumeration());
298 						field = (LLRPEnumeration) fieldClass.getConstructor(new Class[0]).newInstance(new Object[0]);
299 					} catch (Exception e1) {
300 						e1.printStackTrace();
301 					}
302 					field.set(combo.getText());
303 					treeMaintainer.setField(input, fieldDefinition.getName(), (LLRPType) field);
304 					block.refresh(input);
305 				}
306 			}
307 			
308 		});
309 		GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
310 		combo.setLayoutData(gd);
311 		return combo;
312 	}
313 	
314 	private Text createFieldText(Composite client, FormToolkit toolkit, final FieldDefinition fieldDefinition) {
315 		final Text text = toolkit.createText(client, "", SWT.SINGLE);
316 		final ControlDecoration controlDecoration = createControlDecoration(text);
317 		textControlDecorations.add(controlDecoration);
318 		ModifyListener modifyListener = new ModifyListener() {
319 			public void modifyText(ModifyEvent e) {
320 				if (input != null){
321 					
322 					LLRPType fieldValue = null;
323 					String fieldType = LLRP.getFieldType(fieldDefinition);
324 					
325 					try {
326 						fieldValue = LLRPFactory.createLLRPType(fieldType, text.getText());
327 						treeMaintainer.setField(input, fieldDefinition.getName(), fieldValue);
328 					} catch (Exception e1) {
329 						// do nothing
330 					}
331 					
332 					// validation
333 					String errorMessage = treeMaintainer.validateField(input, fieldDefinition.getName());
334 					updateControlDecoration(controlDecoration, errorMessage);
335 					block.refresh(null);
336 				}
337 			}
338 		};
339 		textModifyListeners.add(modifyListener);
340 		text.addModifyListener(modifyListener);
341 		VerifyListener verifyListener = new VerifyListener(){
342 
343 			public void verifyText(VerifyEvent e) {
344 				String fieldType = LLRP.getFieldType(fieldDefinition);
345 				try {
346 					String oldTextValue = text.getText();
347 					String newTextValue = 
348 						oldTextValue.substring(0, e.start) + 
349 						e.text + 
350 						oldTextValue.substring(e.end);
351 					LLRPFactory.createLLRPType(fieldType, newTextValue);
352 					e.doit = true;
353 				} catch (Exception exception) {
354 					e.doit = false;
355 				}
356 			}
357 			
358 		};
359 		textVerifyListeners.add(verifyListener);
360 		text.addVerifyListener(verifyListener);
361 		GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
362 		text.setLayoutData(gd);
363 		return text;
364 	}
365 
366 	private void createListAndParameterControls(Composite client, FormToolkit toolkit) {
367 		GridData gd;
368 		Object messageOrParameterDefinition = treeMaintainer.getDefinition(input);
369 		java.util.List<Object> parameterOrChoiceList = new LinkedList<Object>();
370 		if (messageOrParameterDefinition instanceof MessageDefinition){
371 			parameterOrChoiceList = ((MessageDefinition) messageOrParameterDefinition).getParameterOrChoice();
372 		}
373 		else if (messageOrParameterDefinition instanceof ParameterDefinition){
374 			parameterOrChoiceList = ((ParameterDefinition) messageOrParameterDefinition).getParameterOrChoice();
375 		}
376 		for (Object o : parameterOrChoiceList){
377 			String childName = "";
378 			if (o instanceof ChoiceReference){
379 				ChoiceReference choiceReference = (ChoiceReference) o;
380 				childName = choiceReference.getType();
381 			}
382 			else if (o instanceof ParameterReference){
383 				ParameterReference parameterReference = (ParameterReference) o;
384 				childName = parameterReference.getType();
385 			}
386 			Label label = toolkit.createLabel(client, childName + ":");
387 			gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
388 			label.setLayoutData(gd);
389 			if (LLRP.canOccurMultipleTimes(treeMaintainer.getDefinition(input), childName)){
390 				TableViewer tableViewer = createListTableViewer(client, toolkit);
391 				tableViewers.add(tableViewer);
392 			}
393 			else{
394 				Hyperlink hyperlink = createParameterHyperlink(client, toolkit);
395 				hyperlinks.add(hyperlink);
396 			}
397 		}
398 	}
399 
400 	private TableViewer createListTableViewer(Composite client, FormToolkit toolkit) {
401 		Table table = toolkit.createTable(client, SWT.NULL);
402 		GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
403 		table.setLayoutData(gd);
404 		
405 		ControlDecoration controlDecoration = createControlDecoration(table);
406 		tableViewerControlDecorations.add(controlDecoration);
407 		
408 		final TableViewer tableViewer = new TableViewer(table);
409 		
410 		tableViewer.setContentProvider(new IStructuredContentProvider(){
411 			public Object[] getElements(Object inputElement) {
412 				if (inputElement instanceof java.util.List){
413 					return ((java.util.List<LLRPParameter>) inputElement).toArray(new Object[0]);
414 				}
415 				return null;
416 			}
417 			public void dispose() {}
418 			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
419 		});
420 		
421 		tableViewer.setLabelProvider(new LLRPTreeLabelProvider(treeMaintainer));
422 		
423 		tableViewer.addDoubleClickListener(new IDoubleClickListener(){
424 			public void doubleClick(DoubleClickEvent event) {
425 				IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection();
426 				if (selection.size() == 1 && selection.getFirstElement() instanceof LLRPParameter){
427 					treeViewer.setSelection(new StructuredSelection(selection.getFirstElement()), true);
428 				}
429 			}
430 		});
431 		
432 		return tableViewer;
433 	}
434 	
435 	private Hyperlink createParameterHyperlink(Composite client, FormToolkit toolkit) {
436 		final Hyperlink hyperlink = toolkit.createHyperlink(client, "", SWT.NULL);
437 		ControlDecoration controlDecoration = createControlDecoration(hyperlink);
438 		hyperlinkControlDecorations.add(controlDecoration);
439 		
440 		hyperlink.addHyperlinkListener(new HyperlinkAdapter(){
441 			public void linkActivated(HyperlinkEvent e) {
442 				treeViewer.setSelection(new StructuredSelection(hyperlink.getData()), true);
443 			}
444 		});
445 		return hyperlink;
446 	}
447 
448 	private ControlDecoration createControlDecoration(Control control){
449 		final ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.BOTTOM);
450 		Image errorImage = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
451 		controlDecoration.setImage(errorImage);
452 		controlDecoration.hide();
453 		return controlDecoration;
454 	}
455 	
456 	private void update() {
457 		if (input != null){
458 			section.setText(treeMaintainer.getName(input));			
459 			updateFieldControls();
460 			updateListAndParameterControls();	
461 		}
462 	}
463 	
464 	private void updateFieldControls() {
465 		int textIndex = 0;
466 		int comboIndex = 0;
467 		java.util.List<FieldDefinition> fieldDefinitions = LLRP.getFieldDefinitions(treeMaintainer.getDefinition(input));
468 		for (int i = 0; i < fieldDefinitions.size(); i++){
469 			FieldDefinition fieldDefinition = fieldDefinitions.get(i);
470 			String fieldName = fieldDefinition.getName();
471 			LLRPType fieldValue = treeMaintainer.getField(input, fieldName);
472 			fieldDefinition.getType().value();
473 			if (LLRP.isEnumeration(fieldDefinition)){
474 				if (fieldValue != null){
475 					combos.get(comboIndex).setText(fieldValue.toString());
476 				}
477 				else{
478 					combos.get(comboIndex).clearSelection();
479 				}
480 				
481 				//validation
482 				String errorMessage = treeMaintainer.validateField(input, fieldName);
483 				updateControlDecoration(comboControlDecorations.get(comboIndex), errorMessage);
484 				
485 				comboIndex++;
486 			}
487 			else{
488 				String fieldValueAsString = "";
489 				if (fieldValue != null){
490 					fieldValueAsString = fieldValue.toString();
491 				}
492 				texts.get(textIndex).removeVerifyListener(textVerifyListeners.get(textIndex));
493 				texts.get(textIndex).removeModifyListener(textModifyListeners.get(textIndex));
494 				texts.get(textIndex).setText(fieldValueAsString);
495 				texts.get(textIndex).addVerifyListener(textVerifyListeners.get(textIndex));
496 				texts.get(textIndex).addModifyListener(textModifyListeners.get(textIndex));
497 				
498 				//validation
499 				String errorMessage = treeMaintainer.validateField(input, fieldName);
500 				updateControlDecoration(textControlDecorations.get(textIndex), errorMessage);
501 				
502 				textIndex++;
503 			}
504 		}
505 	}
506 	
507 	private void updateListAndParameterControls() {
508 		int tableViewerIndex = 0;
509 		int hyperlinkIndex = 0;
510 		java.util.List<String> childrenNames = LLRP.getParameterAndChoiceNames(treeMaintainer.getDefinition(input));
511 		for (String childName : childrenNames){
512 			Object o = treeMaintainer.getChild(input, childName);
513 			if (LLRP.canOccurMultipleTimes(treeMaintainer.getDefinition(input), childName)){
514 				// fill table
515 				java.util.List<LLRPParameter> parameterList = (java.util.List<LLRPParameter>) o;
516 				tableViewers.get(tableViewerIndex).setInput(parameterList);
517 				
518 				//validation
519 				String errorMessage = treeMaintainer.validateEmptiness(parameterList);
520 				updateControlDecoration(tableViewerControlDecorations.get(tableViewerIndex), errorMessage);
521 				
522 				tableViewerIndex++;
523 			}
524 			else {
525 				final LLRPParameter parameter = (LLRPParameter) o;
526 				// "fill" link
527 				if (parameter == null){
528 					hyperlinks.get(hyperlinkIndex).setText(childName);
529 					hyperlinks.get(hyperlinkIndex).setEnabled(false);
530 					hyperlinks.get(hyperlinkIndex).setUnderlined(false);
531 				}
532 				else{
533 					hyperlinks.get(hyperlinkIndex).setText(treeMaintainer.getName(parameter));
534 					hyperlinks.get(hyperlinkIndex).setEnabled(true);
535 					hyperlinks.get(hyperlinkIndex).setUnderlined(true);
536 					hyperlinks.get(hyperlinkIndex).setData(parameter);
537 				}
538 				
539 				// validation
540 				String errorMessage = treeMaintainer.validateChildPresence(input, childName);
541 				updateControlDecoration(hyperlinkControlDecorations.get(hyperlinkIndex), errorMessage);
542 				
543 				hyperlinkIndex++;
544 			}
545 		}	
546 	}
547 
548 	private void updateControlDecoration(ControlDecoration controlDecoration, String errorMessage){
549 		if (! errorMessage.equals("")){
550 			// add error flag
551 			controlDecoration.setDescriptionText(errorMessage);
552 			controlDecoration.show();
553 		}
554 		else{
555 			// remove error flag
556 			controlDecoration.hide();
557 		}
558 	}
559 	
560 	/* (non-Javadoc)
561 	 * @see org.eclipse.ui.forms.IDetailsPage#inputChanged(org.eclipse.jface.viewers.IStructuredSelection)
562 	 */
563 	public void selectionChanged(IFormPart part, ISelection selection) {
564 		IStructuredSelection ssel = (IStructuredSelection) selection;
565 		if (ssel.size() == 1) {
566 			input = ssel.getFirstElement();
567 		}
568 		else{
569 			input = null;
570 		}
571 		update();
572 	}
573 	
574 	/* (non-Javadoc)
575 	 * @see org.eclipse.ui.forms.IDetailsPage#commit()
576 	 */
577 	public void commit(boolean onSave) {
578 		
579 	}
580 	
581 	/* (non-Javadoc)
582 	 * @see org.eclipse.ui.forms.IDetailsPage#setFocus()
583 	 */
584 	public void setFocus() {
585 		if (!texts.isEmpty()){
586 			texts.get(0).setFocus();
587 		}
588 	}
589 	
590 	/* (non-Javadoc)
591 	 * @see org.eclipse.ui.forms.IDetailsPage#dispose()
592 	 */
593 	public void dispose() {
594 	}
595 	
596 	/* (non-Javadoc)
597 	 * @see org.eclipse.ui.forms.IDetailsPage#isDirty()
598 	 */
599 	public boolean isDirty() {
600 		return false;
601 	}
602 	
603 	public boolean isStale() {
604 		return false;
605 	}
606 	
607 	/* (non-Javadoc)
608 	 * @see org.eclipse.ui.forms.IDetailsPage#refresh()
609 	 */
610 	public void refresh() {
611 		update();
612 	}
613 	
614 	public boolean setFormInput(Object input) {
615 		return false;
616 	}
617 }
618