1 package oic.simulator.serviceprovider.view;
3 import java.util.ArrayList;
4 import java.util.Iterator;
9 import oic.simulator.serviceprovider.Activator;
10 import oic.simulator.serviceprovider.listener.IAutomationUIListener;
11 import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
12 import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
13 import oic.simulator.serviceprovider.manager.ResourceManager;
14 import oic.simulator.serviceprovider.resource.AutomationSettingHelper;
15 import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
16 import oic.simulator.serviceprovider.resource.ResourceAttribute;
17 import oic.simulator.serviceprovider.resource.SimulatorResource;
18 import oic.simulator.serviceprovider.utils.Constants;
19 import oic.simulator.serviceprovider.utils.Utility;
21 import org.eclipse.jface.viewers.CellEditor;
22 import org.eclipse.jface.viewers.CellLabelProvider;
23 import org.eclipse.jface.viewers.ColumnLabelProvider;
24 import org.eclipse.jface.viewers.ComboBoxCellEditor;
25 import org.eclipse.jface.viewers.EditingSupport;
26 import org.eclipse.jface.viewers.ISelectionChangedListener;
27 import org.eclipse.jface.viewers.IStructuredContentProvider;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.viewers.SelectionChangedEvent;
30 import org.eclipse.jface.viewers.StyledCellLabelProvider;
31 import org.eclipse.jface.viewers.TableViewer;
32 import org.eclipse.jface.viewers.TableViewerColumn;
33 import org.eclipse.jface.viewers.Viewer;
34 import org.eclipse.jface.viewers.ViewerCell;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.custom.CCombo;
37 import org.eclipse.swt.events.SelectionAdapter;
38 import org.eclipse.swt.events.SelectionEvent;
39 import org.eclipse.swt.events.TraverseEvent;
40 import org.eclipse.swt.events.TraverseListener;
41 import org.eclipse.swt.events.VerifyEvent;
42 import org.eclipse.swt.events.VerifyListener;
43 import org.eclipse.swt.graphics.Color;
44 import org.eclipse.swt.graphics.Point;
45 import org.eclipse.swt.layout.GridData;
46 import org.eclipse.swt.layout.GridLayout;
47 import org.eclipse.swt.widgets.Button;
48 import org.eclipse.swt.widgets.Composite;
49 import org.eclipse.swt.widgets.Display;
50 import org.eclipse.swt.widgets.Group;
51 import org.eclipse.swt.widgets.Label;
52 import org.eclipse.swt.widgets.Table;
53 import org.eclipse.ui.part.ViewPart;
54 import org.oic.simulator.AutomationType;
56 public class AttributeView extends ViewPart {
58 public static final String VIEW_ID = "oic.simulator.serviceprovider.view.attribute";
60 private TableViewer attTblViewer;
61 private TableViewer automtnSettingsTblViewer;
63 private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
64 private IResourceModelChangedUIListener resourceModelChangedUIListener;
65 private IAutomationUIListener automationUIListener;
67 private Label newValueLbl;
68 private CCombo valueCmb;
69 private Button submitButton;
70 private Button clearButton;
72 private ResourceAttribute attributeInSelection;
73 private AttributeAutomationSettingEditor automationSettingEditor;
74 private List<AutomationSettingHelper> localSettingList;
76 private final String[] attTblHeaders = { "Name",
77 "Value", "Automation Status" };
78 private final String[] settingTblHeaders = {
80 private final Integer[] attTblColWidth = { 150,
82 private final Integer[] settingTblColWidth = { 140, 85 };
84 private ResourceManager resourceManager;
86 public AttributeView() {
88 resourceManager = Activator.getDefault().getResourceManager();
90 resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
93 public void onResourceSelectionChange() {
94 Display.getDefault().asyncExec(new Runnable() {
98 if (null != attTblViewer) {
99 updateViewer(checkSelection());
106 resourceModelChangedUIListener = new IResourceModelChangedUIListener() {
109 public void onResourceModelChange(
110 final ModelChangeNotificationType notificationType,
111 final String resourceURI) {
112 Display.getDefault().asyncExec(new Runnable() {
115 // Handle the notification only if it is for the current
116 // resource in selection
117 SimulatorResource resource = resourceManager
118 .getCurrentResourceInSelection();
119 if (null == resource) {
122 if (!resourceURI.equals(resource.getResourceURI())) {
125 // Refresh the table viewers which will display
126 // the updated values
127 if (null != attTblViewer) {
128 attTblViewer.refresh();
130 // If this call has a new value for the current
132 // in selection, then update it in the combo box
133 if (notificationType != ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED) {
136 if (null != valueCmb && !valueCmb.isDisposed()
137 && null != attributeInSelection) {
138 Map<String, ResourceAttribute> attributeMap = resource
139 .getResourceAttributesMap();
140 if (null != attributeMap) {
141 ResourceAttribute attribute = attributeMap
142 .get(attributeInSelection
143 .getAttributeName());
144 if (null != attribute) {
145 Object valueObj = attribute
146 .getAttributeValue();
147 if (null != valueObj) {
148 String valueStr = String
150 int index = valueCmb.indexOf(valueStr);
152 valueCmb.select(index);
154 valueCmb.add(valueStr);
155 valueCmb.select(valueCmb
167 automationUIListener = new IAutomationUIListener() {
170 public void onResourceAutomationStart(final String resourceURI) {
171 Display.getDefault().asyncExec(new Runnable() {
175 if (null == resourceURI) {
178 SimulatorResource resource = resourceManager
179 .getCurrentResourceInSelection();
180 if (null == resource) {
183 String uri = resource.getResourceURI();
184 // Checking whether attributes view is currently
185 // displaying the attributes of the
186 // resource whose automation has just started
187 if (null != uri && uri.equals(resourceURI)) {
189 tbl = attTblViewer.getTable();
190 if (!tbl.isDisposed()) {
191 attTblViewer.refresh();
194 // If any attribute is in selection, then update
195 // the automation setting to enable.
196 if (null != attributeInSelection) {
197 tbl = automtnSettingsTblViewer.getTable();
198 if (!tbl.isDisposed()) {
199 // Change the local automation settings
200 AutomationSettingHelper
201 .updateAutomationStatus(
204 automtnSettingsTblViewer.refresh();
208 // Disable the manual change UI controls
209 setVisibilityForManualValueChange(false);
216 public void onAutomationComplete(final String resourceURI,
217 final String attName) {
218 // This method notifies the completion of attribute level
220 Display.getDefault().asyncExec(new Runnable() {
224 if (null == resourceURI) {
227 // Check if the given resourceURI is the uri of the
228 // resource whose attributes are currently being
229 // displayed by this view.
230 SimulatorResource resource = resourceManager
231 .getCurrentResourceInSelection();
232 if (null == resource) {
235 String uri = resource.getResourceURI();
236 if (null != uri && uri.equals(resourceURI)) {
238 tbl = attTblViewer.getTable();
239 if (!tbl.isDisposed()) {
240 attTblViewer.refresh();
243 if (null != attributeInSelection) {
245 || attributeInSelection
246 .getAttributeName().equals(
248 tbl = automtnSettingsTblViewer.getTable();
249 if (!tbl.isDisposed()) {
250 // Change the local automation settings
251 AutomationSettingHelper
252 .updateAutomationStatus(
255 automtnSettingsTblViewer.refresh();
257 setVisibilityForManualValueChange(true);
268 public void createPartControl(Composite parent) {
269 Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
271 parent.setLayout(new GridLayout(2, false));
272 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
273 parent.setLayoutData(gd);
275 Group attGroup = new Group(parent, SWT.NONE);
276 attGroup.setLayout(new GridLayout(1, false));
277 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
278 gd.horizontalSpan = 2;
279 gd.minimumHeight = 175;
280 attGroup.setLayoutData(gd);
281 attGroup.setText("Attributes");
282 attGroup.setBackground(color);
284 attTblViewer = new TableViewer(attGroup, SWT.MULTI | SWT.H_SCROLL
285 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
287 createAttributeColumns(attTblViewer);
289 // make lines and header visible
290 Table table = attTblViewer.getTable();
291 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
292 table.setHeaderVisible(true);
293 table.setLinesVisible(true);
295 attTblViewer.setContentProvider(new AttributeContentProvider());
297 Group automationSettingsTableGrp = new Group(parent, SWT.NONE);
298 automationSettingsTableGrp.setLayout(new GridLayout(1, false));
299 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
300 automationSettingsTableGrp.setLayoutData(gd);
301 automationSettingsTableGrp.setText("Automation Settings");
302 automationSettingsTableGrp.setBackground(color);
304 automtnSettingsTblViewer = new TableViewer(automationSettingsTableGrp,
305 SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
308 createSettingColumns(automtnSettingsTblViewer);
310 // make lines visible
311 table = automtnSettingsTblViewer.getTable();
312 gd = new GridData(SWT.FILL, SWT.FILL, true, true);
313 table.setLayoutData(gd);
314 table.setHeaderVisible(true);
315 table.setLinesVisible(true);
317 automtnSettingsTblViewer
318 .setContentProvider(new AttributeContentProvider());
320 Composite rightViewComp = new Composite(parent, SWT.NONE);
321 rightViewComp.setLayout(new GridLayout(1, false));
323 Group valueUpdateGroup = new Group(rightViewComp, SWT.NONE);
324 valueUpdateGroup.setLayout(new GridLayout(2, false));
326 gd.horizontalAlignment = SWT.FILL;
327 gd.grabExcessHorizontalSpace = true;
328 gd.horizontalSpan = 2;
329 valueUpdateGroup.setLayoutData(gd);
330 valueUpdateGroup.setText("Change Attribute Value");
331 valueUpdateGroup.setBackground(color);
333 newValueLbl = new Label(valueUpdateGroup, SWT.NONE);
334 newValueLbl.setText("Select New Value");
336 valueCmb = new CCombo(valueUpdateGroup, SWT.BORDER);
339 valueCmb.setLayoutData(gd);
341 submitButton = new Button(rightViewComp, SWT.PUSH);
344 gd.verticalIndent = 10;
345 gd.horizontalSpan = 2;
346 gd.horizontalAlignment = SWT.CENTER;
347 submitButton.setLayoutData(gd);
348 submitButton.setText("Apply Changes");
350 clearButton = new Button(rightViewComp, SWT.PUSH);
353 gd.verticalIndent = 10;
354 gd.horizontalSpan = 2;
355 gd.horizontalAlignment = SWT.CENTER;
356 clearButton.setLayoutData(gd);
357 clearButton.setText("Reset Changes");
361 addManagerListeners();
363 // Check whether there is any resource selected already
364 List<ResourceAttribute> propertyList = checkSelection();
365 if (null != propertyList) {
366 updateViewer(propertyList);
369 setSettingSubmitVisibility(false);
372 public void createAttributeColumns(TableViewer tableViewer) {
373 TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
374 attName.getColumn().setWidth(attTblColWidth[0]);
375 attName.getColumn().setText(attTblHeaders[0]);
376 attName.setLabelProvider(new ColumnLabelProvider() {
378 public String getText(Object element) {
379 if (element instanceof ResourceAttribute) {
380 ResourceAttribute attribute = (ResourceAttribute) element;
381 if (null != attribute) {
382 return attribute.getAttributeName();
389 TableViewerColumn attValue = new TableViewerColumn(tableViewer,
391 attValue.getColumn().setWidth(attTblColWidth[1]);
392 attValue.getColumn().setText(attTblHeaders[1]);
393 attValue.setLabelProvider(new ColumnLabelProvider() {
395 public String getText(Object element) {
396 if (element instanceof ResourceAttribute) {
397 ResourceAttribute attribute = (ResourceAttribute) element;
398 if (null != attribute) {
399 Object val = attribute.getAttributeValue();
401 return String.valueOf(val);
409 TableViewerColumn automationStatus = new TableViewerColumn(tableViewer,
411 automationStatus.getColumn().setWidth(attTblColWidth[2]);
412 automationStatus.getColumn().setText(attTblHeaders[2]);
413 automationStatus.setLabelProvider(new ColumnLabelProvider() {
415 public String getText(Object element) {
416 if (element instanceof ResourceAttribute) {
417 ResourceAttribute attribute = (ResourceAttribute) element;
418 if (null != attribute) {
419 boolean progress = attribute.isAutomationInProgress();
420 return Utility.getAutomationStatus(progress);
428 public void createSettingColumns(TableViewer tableViewer) {
429 TableViewerColumn key = new TableViewerColumn(tableViewer, SWT.NONE);
430 key.getColumn().setWidth(settingTblColWidth[0]);
431 key.getColumn().setText(settingTblHeaders[0]);
432 key.setLabelProvider(new StyledCellLabelProvider() {
434 public void update(ViewerCell cell) {
435 Object element = cell.getElement();
436 if (element instanceof AutomationSettingHelper) {
437 AutomationSettingHelper setting = (AutomationSettingHelper) element;
438 cell.setText(setting.getSettingID());
443 TableViewerColumn value = new TableViewerColumn(tableViewer, SWT.NONE);
444 value.getColumn().setWidth(settingTblColWidth[1]);
445 value.getColumn().setText(settingTblHeaders[1]);
446 value.setLabelProvider(new CellLabelProvider() {
448 public void update(ViewerCell cell) {
449 Object element = cell.getElement();
450 if (element instanceof AutomationSettingHelper) {
451 AutomationSettingHelper setting = (AutomationSettingHelper) element;
452 if (null != setting) {
453 cell.setText(String.valueOf(setting.getSettingValue()));
458 automationSettingEditor = new AttributeAutomationSettingEditor(
460 value.setEditingSupport(automationSettingEditor);
463 private void addUIListeners() {
465 .addSelectionChangedListener(new ISelectionChangedListener() {
468 public void selectionChanged(SelectionChangedEvent e) {
469 IStructuredSelection selection = (IStructuredSelection) attTblViewer
471 Object firstElement = selection.getFirstElement();
472 if (firstElement instanceof ResourceAttribute) {
473 ResourceAttribute attribute = (ResourceAttribute) firstElement;
475 // Store the attribute selection
476 attributeInSelection = attribute;
478 // Change the visibility of the manual change
479 // controls according to the automation status
480 if (attribute.isAutomationInProgress()) {
481 setVisibilityForManualValueChange(false);
483 setVisibilityForManualValueChange(true);
486 // Hide the visibility of submit and clear buttons
487 setSettingSubmitVisibility(false);
489 if (null != attribute) {
490 if (null != automtnSettingsTblViewer) {
491 localSettingList = AutomationSettingHelper
492 .getAutomationSettings(attribute);
493 if (null != localSettingList) {
494 automtnSettingsTblViewer.getTable()
495 .setLinesVisible(true);
496 automtnSettingsTblViewer
497 .setInput(localSettingList
501 // Populate the attribute value combo
502 if (null != valueCmb && !valueCmb.isDisposed()) {
503 // Clear the existing combo list contents
504 valueCmb.removeAll();
505 Set<Object> valueList = attribute
508 if (null != valueList) {
509 Iterator<Object> valueItr = valueList
511 while (valueItr.hasNext()) {
512 value = valueItr.next();
514 // Casting the value to String
515 // for showing in combo
520 // Setting the selection to the current
521 // value of the attribute
522 String attValue = String
524 .getAttributeValue());
525 int index = valueCmb.indexOf(attValue);
527 valueCmb.select(index);
536 valueCmb.addSelectionListener(new SelectionAdapter() {
538 public void widgetSelected(SelectionEvent e) {
539 if (null != attributeInSelection) {
540 // attributeInSelection.setAttributeValue(valueCmb.getText());
541 if (!valueCmb.getText().equals(
542 String.valueOf(attributeInSelection
543 .getAttributeValue()))) {
544 // Enable the submit and clear button controls
545 setSettingSubmitVisibility(true);
547 setSettingSubmitVisibility(false);
553 submitButton.addSelectionListener(new SelectionAdapter() {
555 public void widgetSelected(SelectionEvent e) {
557 if (null != attributeInSelection && null != localSettingList) {
558 if (attributeInSelection.isAutomationInProgress()
559 || valueCmb.getText().equals(
560 String.valueOf(attributeInSelection
561 .getAttributeValue()))) {
562 // Change in automation settings
563 Iterator<AutomationSettingHelper> settingItr = localSettingList
566 // These variables will hold the new automation
568 boolean autoEnable = false;
569 AutomationType autoType = AutomationType.NORMAL;
570 int autoUpdateInterval = Constants.DEFAULT_AUTOMATION_INTERVAL;
572 // These variables will hold the old automation settings
573 // and are used to roll-back the settings
574 // if automation fails.
575 boolean autoEnablePrev = false;
576 AutomationType autoTypePrev = AutomationType.NORMAL;
577 int autoUpdateIntervalPrev = Constants.DEFAULT_AUTOMATION_INTERVAL;
581 AutomationSettingHelper setting;
582 while (settingItr.hasNext()) {
583 setting = settingItr.next();
584 id = setting.getSettingID();
585 value = setting.getSettingValue();
586 if (id.equals(Constants.AUTOMATION)) {
588 .getAutomationBoolean(value);
589 autoEnablePrev = attributeInSelection
590 .isAutomationInProgress();
593 .setAutomationInProgress(autoEnable);
594 // Automation is disabled and hence the manual
595 // controls should be enabled
597 setVisibilityForManualValueChange(true);
599 } else if (id.equals(Constants.AUTOMATION_TYPE)) {
600 autoType = AutomationType.valueOf(value);
601 autoTypePrev = attributeInSelection
602 .getAutomationType();
605 .setAutomationType(autoType);
607 .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
608 autoUpdateInterval = Utility
609 .getUpdateIntervalFromString(value);
610 autoUpdateIntervalPrev = attributeInSelection
611 .getAutomationUpdateInterval();
614 .setAutomationUpdateInterval(autoUpdateInterval);
618 // Updating the automation status in the resource
619 SimulatorResource resource = resourceManager
620 .getCurrentResourceInSelection();
621 resource.setAttributeAutomationInProgress(autoEnable);
624 // Send automation enable request
625 int autoId = resourceManager.startAutomation(
626 resource, attributeInSelection, autoType,
630 // Roll-back the attribute model and automation
632 settingItr = localSettingList.iterator();
633 while (settingItr.hasNext()) {
634 setting = settingItr.next();
635 id = setting.getSettingID();
636 value = setting.getSettingValue();
637 if (id.equals(Constants.AUTOMATION)) {
638 setting.setSettingValue(Utility
639 .getAutomationString(autoEnablePrev));
641 .equals(Constants.AUTOMATION_TYPE)) {
642 setting.setSettingValue(autoTypePrev
645 .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
646 setting.setSettingValue(String
647 .valueOf(autoUpdateIntervalPrev));
652 .setAutomationInProgress(autoEnablePrev);
654 .setAutomationType(autoTypePrev);
656 .setAutomationUpdateInterval(autoUpdateIntervalPrev);
658 automtnSettingsTblViewer.refresh();
660 // Automation is disabled and hence the manual
661 // controls should be enabled
662 setVisibilityForManualValueChange(true);
665 // Send automation disable request
666 int autoId = attributeInSelection.getAutomationId();
667 resourceManager.stopAutomation(resource, autoId);
670 // Change in attribute value manually
671 String input = valueCmb.getText();
672 if (null != input && input.length() > 0) {
673 attributeInSelection.setAttributeValue(input);
675 SimulatorResource resource = resourceManager
676 .getCurrentResourceInSelection();
677 resourceManager.attributeValueUpdated(resource,
678 attributeInSelection.getAttributeName(),
684 attTblViewer.refresh();
686 setSettingSubmitVisibility(false);
690 clearButton.addSelectionListener(new SelectionAdapter() {
692 public void widgetSelected(SelectionEvent e) {
693 if (null != attributeInSelection) {
694 // Update the settings table
695 List<AutomationSettingHelper> settingList = AutomationSettingHelper
696 .getAutomationSettings(attributeInSelection);
697 if (null != settingList) {
698 // clear the existing table contents
699 Table tbl = automtnSettingsTblViewer.getTable();
700 if (!tbl.isDisposed()) {
702 localSettingList = settingList;
703 automtnSettingsTblViewer.setInput(localSettingList
707 // Update the allowed values combo
708 if (!valueCmb.isDisposed()) {
709 valueCmb.setText(String.valueOf(attributeInSelection
710 .getAttributeValue()));
711 setVisibilityForManualValueChange(!attributeInSelection
712 .isAutomationInProgress());
715 setSettingSubmitVisibility(false);
720 private void addManagerListeners() {
722 .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
724 .addResourceModelChangedUIListener(resourceModelChangedUIListener);
725 resourceManager.addAutomationUIListener(automationUIListener);
728 private void setSettingSubmitVisibility(boolean visible) {
729 if (!submitButton.isDisposed())
730 submitButton.setEnabled(visible);
731 if (!clearButton.isDisposed())
732 clearButton.setEnabled(visible);
735 private List<ResourceAttribute> checkSelection() {
736 SimulatorResource resourceInSelection = resourceManager
737 .getCurrentResourceInSelection();
738 if (null != resourceInSelection) {
739 List<ResourceAttribute> attList = resourceManager
740 .getAttributes(resourceInSelection);
747 private void updateViewer(List<ResourceAttribute> attList) {
749 if (null != attList) {
750 tbl = attTblViewer.getTable();
751 if (null != tbl && !tbl.isDisposed()) {
752 tbl.setLinesVisible(true);
753 attTblViewer.setInput(attList.toArray());
756 // Clear the attributes table viewer
757 if (null != attTblViewer) {
758 tbl = attTblViewer.getTable();
759 if (null != tbl && !tbl.isDisposed()) {
760 // tbl.deselectAll();
762 tbl.setLinesVisible(false);
767 attributeInSelection = null;
769 // Clear the Settings table viewer
770 if (null != automtnSettingsTblViewer) {
771 tbl = automtnSettingsTblViewer.getTable();
772 if (null != tbl && !tbl.isDisposed()) {
773 // tbl.deselectAll();
775 tbl.setLinesVisible(false);
778 // Clear the value list combo
779 if (!valueCmb.isDisposed()) {
780 valueCmb.removeAll();
781 valueCmb.setEnabled(false);
784 // Hide the visibility of submit and clear buttons
785 setSettingSubmitVisibility(false);
788 class AttributeContentProvider implements IStructuredContentProvider {
791 public void dispose() {
795 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
799 public Object[] getElements(Object element) {
800 return (Object[]) element;
805 class AttributeAutomationSettingEditor extends EditingSupport {
807 private final TableViewer viewer;
809 private AutomationSettingHelper currentSettingInSelection;
811 public AttributeAutomationSettingEditor(TableViewer viewer) {
813 this.viewer = viewer;
817 protected boolean canEdit(Object element) {
822 protected CellEditor getCellEditor(Object element) {
823 ComboBoxCellEditor combo = null;
824 if (null != element) {
825 List<String> valueList;
826 boolean readOnly = true;
827 AutomationSettingHelper setting = (AutomationSettingHelper) element;
829 currentSettingInSelection = setting;
831 String settingID = setting.getSettingID();
832 if (settingID.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
835 valueList = setting.getAllowedValues();
836 if (null == valueList) {
837 valueList = new ArrayList<String>();
839 // Convert list to String[] for passing it to ComboBoxCellEditor
841 values = valueList.toArray(new String[1]);
843 combo = new ComboBoxCellEditor(viewer.getTable(), values,
846 combo = new ComboBoxCellEditor(viewer.getTable(), values);
849 // If resource level automation is enabled, then all setting
850 // should be disabled
851 SimulatorResource resourceInSelection;
852 resourceInSelection = resourceManager
853 .getCurrentResourceInSelection();
854 if (null != resourceInSelection
855 && resourceInSelection.isResourceAutomationInProgress()) {
856 CCombo c = (CCombo) combo.getControl();
859 // Enable the automation type and update interval combo
860 // boxes only if the current value of automation is 'enable'
861 if (settingID.equals(Constants.AUTOMATION_TYPE)
863 .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
864 if (!showSettings()) {
865 // Disable the combo box
866 CCombo c = (CCombo) combo.getControl();
871 // Enabling editing support in update interval combo box
872 if (settingID.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
873 final CCombo c = (CCombo) combo.getControl();
874 c.addVerifyListener(new VerifyListener() {
876 public void verifyText(VerifyEvent e) {
877 String text = c.getText();
878 String newText = text.substring(0, e.start)
879 + e.text + text.substring(e.end);
881 if (newText.length() != 0) {
882 Integer.parseInt(newText);
884 } catch (NumberFormatException ex) {
889 c.addTraverseListener(new TraverseListener() {
891 public void keyTraversed(TraverseEvent e) {
892 if (e.detail == SWT.TRAVERSE_RETURN) {
894 e.detail = SWT.TRAVERSE_NONE;
895 String newText = c.getText();
897 Integer.parseInt(newText);
898 if (null != currentSettingInSelection
899 && currentSettingInSelection
901 .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
902 currentSettingInSelection
903 .addAllowedValue(newText);
906 c.setSelection(new Point(0, newText
908 currentSettingInSelection
909 .setSettingValue(newText);
910 } catch (NumberFormatException ex) {
922 protected Object getValue(Object element) {
923 // This method returns the index of the item selected in the combo
926 AutomationSettingHelper setting = (AutomationSettingHelper) element;
927 List<String> itemList = setting.getAllowedValues();
928 String currentValue = setting.getSettingValue();
929 index = itemList.indexOf(currentValue);
934 protected void setValue(Object element, Object value) {
935 AutomationSettingHelper setting = (AutomationSettingHelper) element;
936 int index = (Integer) value;
937 List<String> valueList = setting.getAllowedValues();
938 if (null != valueList) {
941 targetValue = valueList.get(index);
942 setting.setSettingValue(targetValue);
944 if (setting.getSettingID().equals(Constants.AUTOMATION)) {
946 if (attributeInSelection.isAutomationInProgress()) {
947 // settingsVisibility = false;
948 setVisibilityForManualValueChange(false);
950 if (targetValue.equals(Constants.ENABLE)) {
951 // settingsVisibility = true;
952 setVisibilityForManualValueChange(false);
954 // settingsVisibility = false;
955 setVisibilityForManualValueChange(true);
959 // If status is changed, then enable the submit and
961 if (!targetValue.equals(Utility
962 .getAutomationString(attributeInSelection
963 .isAutomationInProgress()))) {
964 setSettingSubmitVisibility(true);
966 setSettingSubmitVisibility(false);
975 private boolean showSettings() {
976 boolean show = false;
977 if (!attributeInSelection.isAutomationInProgress()) {
978 AutomationSettingHelper setting;
979 Iterator<AutomationSettingHelper> list = localSettingList
981 while (list.hasNext()) {
982 setting = list.next();
983 if (setting.getSettingID().equals(Constants.AUTOMATION)) {
984 if (setting.getSettingValue().equals(Constants.ENABLE)) {
994 // Disable the appropriate controls which are used for manual value change
995 private void setVisibilityForManualValueChange(boolean visibility) {
996 if (null != valueCmb && !valueCmb.isDisposed()) {
997 valueCmb.setEnabled(visibility);
999 if (null != newValueLbl && !newValueLbl.isDisposed()) {
1000 newValueLbl.setEnabled(visibility);
1005 public void dispose() {
1006 // Unregister the selection listener
1007 if (null != resourceSelectionChangedListener) {
1009 .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
1012 // Unregister the model change listener
1013 if (null != resourceModelChangedUIListener) {
1015 .removeResourceModelChangedUIListener(resourceModelChangedUIListener);
1018 // Unregister the automation complete listener
1019 if (null != automationUIListener) {
1020 resourceManager.removeAutomationUIListener(automationUIListener);
1027 public void setFocus() {