package oic.simulator.serviceprovider.view;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
-import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.manager.UiListenerHandler;
-import oic.simulator.serviceprovider.model.MetaProperty;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.UpdateResourceInterfaceDialog;
-
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.oic.simulator.SimulatorException;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
+import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.model.MetaProperty;
+import oic.simulator.serviceprovider.model.Resource;
+import oic.simulator.serviceprovider.model.SingleResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+import oic.simulator.serviceprovider.view.dialogs.UpdateResourceInterfaceDialog;
+
/**
* This class manages and shows the meta properties view in the perspective.
*/
updatedIfSet = resource.getResourceInterfaces();
}
} else {
- boolean result = false;
Resource resourceInSelection = resourceManagerRef
.getCurrentResourceInSelection();
if (null != resourceInSelection) {
// Null Check
- result = resourceManagerRef.isPropertyValueInvalid(
- resourceInSelection, properties,
- Constants.RESOURCE_URI);
+ boolean result = resourceManagerRef
+ .isPropertyValueInvalid(resourceInSelection,
+ properties, Constants.RESOURCE_URI);
if (result) {
MessageDialog.openError(parent.getShell(),
"Invalid Resource URI.",
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;
update = true;
nameChange = true;
}
+
if (resourceManagerRef.isPropValueChanged(
resourceInSelection, properties,
Constants.RESOURCE_URI)) {
return;
}
- 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;
- }
- }
-
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.
- if (null != updatedIfSet) {
- Set<String> curIfSet = resourceInSelection
- .getResourceInterfaces();
+ Set<String> curIfSet = resourceInSelection
+ .getResourceInterfaces();
+ if (null != curIfSet && null != updatedIfSet) {
if (curIfSet.size() != updatedIfSet.size()) {
update = true;
interfaceChange = true;
}
}
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)
+ if (uriChange || nameChange || typeChange)
result = Activator
.getDefault()
.getResourceManager()
resourceManagerRef
.getCurrentResourceInSelection(),
properties, uriChange,
- nameChange);
+ nameChange, typeChange);
if (interfaceChange)
result = Activator
.getDefault()
} catch (SimulatorException ex) {
result = false;
}
- if (result) {
- MessageDialog.openInformation(
- parent.getShell(), "Operation status",
- "Resource properties updated.");
- } else {
+ if (!result) {
MessageDialog.openInformation(
parent.getShell(), "Operation status",
"Failed to update the resource properties.");
resourceSelectionChangedListener);
}
- class PropertycontentProvider implements IStructuredContentProvider {
+ private static class PropertycontentProvider implements
+ IStructuredContentProvider {
@Override
public void dispose() {
if (!getEnableEdit()) {
return null;
}
- // Disabling edit for resource type
String propName = ((MetaProperty) element).getPropName();
- if (null != propName && propName.equals(Constants.RESOURCE_TYPE)) {
- return null;
- }
-
CellEditor editor = new TextCellEditor(viewer.getTable());
if (null != propName && propName.equals(Constants.INTERFACE_TYPES)) {
editor.setStyle(SWT.READ_ONLY);
// Update the local copy of the current resource
// interfaces to keep the state for save operation.
updatedIfSet.clear();
- String newPropValue = "";
+ StringBuilder newPropValue = new StringBuilder();
for (Map.Entry<String, String> entry : curResInterfaces
.entrySet()) {
- if (!newPropValue.isEmpty()) {
- newPropValue += ", ";
+ if (!newPropValue.toString().isEmpty()) {
+ newPropValue.append(", ");
}
String value = ifTypes.get(entry.getKey());
- newPropValue += value;
+ newPropValue.append(value);
updatedIfSet.add(value);
}
// Update the model
MetaProperty prop = (MetaProperty) element;
- prop.setPropValue(newPropValue);
+ prop.setPropValue(newPropValue.toString());
// Update the viewer in a separate UI thread.
Display.getDefault().asyncExec(new Runnable() {
@Override