+ editBtn = new Button(parent, SWT.PUSH);
+ editBtn.setText("Edit");
+ gd = new GridData();
+ gd.widthHint = 50;
+ editBtn.setLayoutData(gd);
+ editBtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (editBtn.getText().equals("Edit")) {
+ cancelBtn.setEnabled(true);
+ editBtn.setText("Save");
+ setEnableEdit(true);
+
+ Resource resource = resourceManagerRef
+ .getCurrentResourceInSelection();
+ if (null != resource) {
+ updatedIfSet = resource.getResourceInterfaces();
+ }
+ } else {
+ Resource resourceInSelection = resourceManagerRef
+ .getCurrentResourceInSelection();
+ if (null != resourceInSelection) {
+
+ // Null Check
+ boolean result = resourceManagerRef
+ .isPropertyValueInvalid(resourceInSelection,
+ properties, Constants.RESOURCE_URI);
+ if (result) {
+ MessageDialog.openError(parent.getShell(),
+ "Invalid Resource URI.",
+ Constants.INVALID_URI_MESSAGE);
+ return;
+ }
+
+ result = resourceManagerRef.isPropertyValueInvalid(
+ resourceInSelection, properties,
+ Constants.RESOURCE_NAME);
+ if (result) {
+ MessageDialog.openError(parent.getShell(),
+ "Invalid Input",
+ "Resource Name is invalid.");
+ return;
+ }
+
+ result = resourceManagerRef.isPropertyValueInvalid(
+ resourceInSelection, properties,
+ Constants.RESOURCE_TYPE);
+ if (result) {
+ MessageDialog.openError(parent.getShell(),
+ "Invalid Resource Type.",
+ Constants.INVALID_RESOURCE_TYPE_MESSAGE);
+ return;
+ }
+
+ boolean update = false;
+ boolean uriChange = false;
+ boolean typeChange = false;
+ boolean nameChange = false;
+ boolean interfaceChange = false;
+
+ if (resourceManagerRef.isPropValueChanged(
+ resourceInSelection, properties,
+ Constants.RESOURCE_NAME)) {
+ update = true;
+ nameChange = true;
+ }
+
+ if (resourceManagerRef.isPropValueChanged(
+ resourceInSelection, properties,
+ Constants.RESOURCE_URI)) {
+ // Check whether the new URI is unique.
+ if (!resourceManagerRef.isUriUnique(properties)) {
+ MessageDialog.openError(parent.getShell(),
+ "Resource URI in use",
+ "Resource URI is in use. Please try a different URI.");
+ return;
+ }
+
+ update = true;
+ uriChange = true;
+ }
+
+ if (resourceManagerRef.isPropValueChanged(
+ resourceInSelection, properties,
+ Constants.RESOURCE_TYPE)) {
+ update = true;
+ typeChange = true;
+ }
+ // Checking whether any changes made in resource
+ // interfaces by
+ // comparing the current interface set and updated
+ // interface set.
+ Set<String> curIfSet = resourceInSelection
+ .getResourceInterfaces();
+ if (null != curIfSet && null != updatedIfSet) {
+ if (curIfSet.size() != updatedIfSet.size()) {
+ update = true;
+ interfaceChange = true;
+ } else {
+ Iterator<String> itr = updatedIfSet.iterator();
+ while (itr.hasNext()) {
+ if (!curIfSet.contains(itr.next())) {
+ update = true;
+ interfaceChange = true;
+ break;
+ }
+ }
+ }
+ }
+ if (update) {
+ if (uriChange || typeChange || interfaceChange) {
+ if (resourceManagerRef
+ .isResourceStarted(resourceInSelection)) {
+ update = MessageDialog.openQuestion(
+ parent.getShell(),
+ "Save Details",
+ "Resource will be restarted to take the changes."
+ + " Do you want to continue?");
+ if (!update) {
+ return;
+ }
+ }
+ }
+ try {
+ if (uriChange || nameChange || typeChange)
+ result = Activator
+ .getDefault()
+ .getResourceManager()
+ .updateResourceProperties(
+ resourceManagerRef
+ .getCurrentResourceInSelection(),
+ properties, uriChange,
+ nameChange, typeChange);
+ if (interfaceChange)
+ result = Activator
+ .getDefault()
+ .getResourceManager()
+ .updateResourceInterfaces(
+ resourceInSelection,
+ updatedIfSet);
+
+ } catch (SimulatorException ex) {
+ result = false;
+ }
+ if (!result) {
+ MessageDialog.openInformation(
+ parent.getShell(), "Operation status",
+ "Failed to update the resource properties.");
+
+ // Reset the old property values.
+ properties = getData(resourceManagerRef
+ .getCurrentResourceInSelection());
+ updateViewer(properties);
+ }
+ }
+ }
+ cancelBtn.setEnabled(false);
+ editBtn.setText("Edit");
+ setEnableEdit(false);
+ }
+ }
+ });
+
+ cancelBtn = new Button(parent, SWT.PUSH);
+ cancelBtn.setText("Cancel");
+ cancelBtn.setEnabled(false);
+ gd = new GridData();
+ gd.widthHint = 70;
+ cancelBtn.setLayoutData(gd);
+ cancelBtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Resource res = resourceManagerRef
+ .getCurrentResourceInSelection();
+ if (null != res) {
+ properties = getData(res);
+ }
+ updateViewer(properties);
+
+ cancelBtn.setEnabled(false);
+ editBtn.setText("Edit");
+ setEnableEdit(false);
+ if (null != updatedIfSet)
+ updatedIfSet.clear();
+ }
+ });
+
+ // Get the supported interfaces.
+ Map<String, String> ifTypesSupported = Utility
+ .getResourceInterfaces(SingleResource.class);
+ if (null != ifTypesSupported && !ifTypesSupported.isEmpty()) {
+ ifTypes = new HashMap<String, String>();
+ String key;
+ for (Map.Entry<String, String> entry : ifTypesSupported.entrySet()) {
+ key = entry.getValue() + " (" + entry.getKey() + ")";
+ ifTypes.put(key, entry.getKey());
+ }
+ }
+