<classpathentry exported="true" kind="lib" path="libs/Simulator.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>
import java.util.Vector;
import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.listener.IConfigurationUpload;
-import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
-import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
-import oic.simulator.clientcontroller.listener.IGetUIListener;
-import oic.simulator.clientcontroller.listener.IObserveUIListener;
-import oic.simulator.clientcontroller.listener.IPostUIListener;
-import oic.simulator.clientcontroller.listener.IPutUIListener;
-import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
-import oic.simulator.clientcontroller.listener.IVerificationUIListener;
import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
import oic.simulator.clientcontroller.remoteresource.MetaProperty;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
*/
public class ResourceManager {
- private Set<String> lastKnownSearchTypes;
+ private Set<String> lastKnownSearchTypes;
- private RemoteResource currentResourceInSelection;
+ private RemoteResource currentResourceInSelection;
- private FindResourceListener findResourceListener;
- private GetResponseListener getListener;
- private PutResponseListener putListener;
- private PostResponseListener postListener;
- private ObserveNotificationListener observeListener;
- private VerificationListener verifyListener;
- private DeviceListener deviceListener;
- private PlatformListener platformListener;
+ private FindResourceListener findResourceListener;
+ private GetResponseListener getListener;
+ private PutResponseListener putListener;
+ private PostResponseListener postListener;
+ private ObserveNotificationListener observeListener;
+ private VerificationListener verifyListener;
+ private DeviceListener deviceListener;
+ private PlatformListener platformListener;
- private ResponseSynchronizerThread synchronizerThread;
+ private ResponseSynchronizerThread synchronizerThread;
- private Thread threadHandle;
-
- private List<IFindResourceUIListener> findResourceUIListeners;
- private List<IResourceSelectionChangedUIListener> resourceSelectionChangedUIListeners;
- private List<IGetUIListener> getUIListeners;
- private List<IPutUIListener> putUIListeners;
- private List<IPostUIListener> postUIListeners;
- private List<IObserveUIListener> observeUIListeners;
- private List<IVerificationUIListener> verificationUIListeners;
- private List<IConfigurationUpload> configUploadUIListeners;
- private List<IDevicePlatformInfoUIListener> devicePlatformInfoUIListeners;
+ private Thread threadHandle;
// Map with Server ID as key and the complete object as the value
- private Map<String, RemoteResource> resourceMap;
- private List<RemoteResource> favoriteResources;
+ private Map<String, RemoteResource> resourceMap;
+ private List<RemoteResource> favoriteResources;
// Maintaining a list of resource URIs for favorite resources feature.
- private List<String> favoriteURIList;
+ private List<String> favoriteURIList;
// Maintaining a list of observed resource URIs.
- private List<String> observedResourceURIList;
+ private List<String> observedResourceURIList;
- private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
+ private Map<String, DeviceAndPlatformInfo> hostDeviceAndPlatformMap;
public ResourceManager() {
resourceMap = new HashMap<String, RemoteResource>();
observedResourceURIList = new ArrayList<String>();
hostDeviceAndPlatformMap = new HashMap<String, DeviceAndPlatformInfo>();
- findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
- resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
- getUIListeners = new ArrayList<IGetUIListener>();
- putUIListeners = new ArrayList<IPutUIListener>();
- postUIListeners = new ArrayList<IPostUIListener>();
- observeUIListeners = new ArrayList<IObserveUIListener>();
- verificationUIListeners = new ArrayList<IVerificationUIListener>();
- configUploadUIListeners = new ArrayList<IConfigurationUpload>();
- devicePlatformInfoUIListeners = new ArrayList<IDevicePlatformInfoUIListener>();
-
findResourceListener = new FindResourceListener() {
@Override
return;
}
- // Fetch the resource data
- // RemoteResource resource =
- // fetchResourceDetails(resourceN);
RemoteResource resource = new RemoteResource();
resource.setRemoteResourceRef(resourceN);
addResourceDetails(resource);
// Notify the UI listener
- newResourceFoundNotification(resource);
+ UiListenerHandler.getInstance()
+ .newResourceFoundNotification(resource);
Activator
.getDefault()
}
};
- // TODO: Listeners for device and platform information.
+ // Listeners for device and platform information.
deviceListener = new DeviceListener() {
@Override
}
// Notify UI listeners
- deviceInfoReceivedNotification();
+ UiListenerHandler.getInstance()
+ .deviceInfoReceivedNotification();
}
});
}
}
// Notify UI listeners
- platformInfoReceivedNotification();
+ UiListenerHandler.getInstance()
+ .platformInfoReceivedNotification();
}
});
}
public void onGetResponse(final String uid,
final SimulatorResult result,
final SimulatorResourceModel resourceModelN) {
- System.out.println(result);
if (result != SimulatorResult.SIMULATOR_OK) {
Activator
.getDefault()
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- getCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .getCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- putCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .putCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- postCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .postCompleteNotification(resource);
}
}
});
resourceModelN);
if (null != resource) {
// Notify the UI listeners
- observeCompleteNotification(resource);
+ UiListenerHandler.getInstance()
+ .observeCompleteNotification(resource);
}
}
});
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationStartedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationStartedNotification(resource,
+ autoType);
}
});
}
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationCompletedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationCompletedNotification(resource,
+ autoType);
}
});
}
int autoType = resource.getAutomationtype(autoId);
// Notify the listeners.
- verificationAbortedNotification(resource, autoType);
+ UiListenerHandler.getInstance()
+ .verificationAbortedNotification(resource,
+ autoType);
}
});
}
return null;
}
- // if(!resource.isConfigUploaded() || null ==
- // resource.getResourceModelRef())
SimulatorResourceModel resourceModel = resource.getResourceModelRef();
if (null == resourceModel) {
resource.setResourceModelRef(resourceModelN);
}
}
- public void addResourceSelectionChangedUIListener(
- IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
- synchronized (resourceSelectionChangedUIListeners) {
- resourceSelectionChangedUIListeners
- .add(resourceSelectionChangedUIListener);
- }
- }
-
- public void addGetUIListener(IGetUIListener getUIListener) {
- synchronized (getUIListeners) {
- getUIListeners.add(getUIListener);
- }
- }
-
- public void addPutUIListener(IPutUIListener putUIListener) {
- synchronized (putUIListeners) {
- putUIListeners.add(putUIListener);
- }
- }
-
- public void addPostUIListener(IPostUIListener postUIListener) {
- synchronized (postUIListeners) {
- postUIListeners.add(postUIListener);
- }
- }
-
- public void addObserveUIListener(IObserveUIListener observeUIListener) {
- synchronized (observeUIListeners) {
- observeUIListeners.add(observeUIListener);
- }
- }
-
- public void addVerificationUIListener(
- IVerificationUIListener verificationUIListener) {
- synchronized (verificationUIListeners) {
- verificationUIListeners.add(verificationUIListener);
- }
- }
-
- public void addConfigUploadUIListener(IConfigurationUpload configListener) {
- synchronized (configUploadUIListeners) {
- configUploadUIListeners.add(configListener);
- }
- }
-
- public void addDevicePlatformInfoUIListener(
- IDevicePlatformInfoUIListener deviceUIListener) {
- synchronized (devicePlatformInfoUIListeners) {
- devicePlatformInfoUIListeners.add(deviceUIListener);
- }
- }
-
- public void removeDevicePlatformInfoUIListener(
- IDevicePlatformInfoUIListener platformUIListener) {
- synchronized (devicePlatformInfoUIListeners) {
- devicePlatformInfoUIListeners.remove(platformUIListener);
- }
- }
-
- public void removeResourceSelectionChangedUIListener(
- IResourceSelectionChangedUIListener listener) {
- synchronized (resourceSelectionChangedUIListeners) {
- if (null != listener
- && resourceSelectionChangedUIListeners.size() > 0) {
- resourceSelectionChangedUIListeners.remove(listener);
- }
- }
- }
-
- public void removeGetUIListener(IGetUIListener getUIListener) {
- synchronized (getUIListeners) {
- getUIListeners.remove(getUIListener);
- }
- }
-
- public void removePutUIListener(IPutUIListener putUIListener) {
- synchronized (putUIListeners) {
- putUIListeners.remove(putUIListener);
- }
- }
-
- public void removePostUIListener(IPostUIListener postUIListener) {
- synchronized (postUIListeners) {
- postUIListeners.remove(postUIListener);
- }
- }
-
- public void removeObserveUIListener(IObserveUIListener observeUIListener) {
- synchronized (observeUIListeners) {
- observeUIListeners.remove(observeUIListener);
- }
- }
-
- public void removeVerificationUIListener(
- IVerificationUIListener verificationUIListener) {
- synchronized (verificationUIListeners) {
- verificationUIListeners.remove(verificationUIListener);
- }
- }
-
- public void removeConfigUploadUIListener(IConfigurationUpload configListener) {
- synchronized (configUploadUIListeners) {
- configUploadUIListeners.remove(configListener);
- }
- }
-
public void addResourcetoFavorites(RemoteResource resource) {
if (null == resource) {
return;
}
}
- public void addFindresourceUIListener(IFindResourceUIListener listener) {
- if (null == listener) {
- return;
- }
- synchronized (findResourceUIListeners) {
- findResourceUIListeners.add(listener);
- }
- }
-
- public void removeFindresourceUIListener(IFindResourceUIListener listener) {
- if (null == listener) {
- return;
- }
- synchronized (findResourceUIListeners) {
- findResourceUIListeners.remove(listener);
- }
- }
-
private boolean isUidExist(String uid) {
boolean exist;
synchronized (resourceMap) {
return resource;
}
- private void newResourceFoundNotification(RemoteResource resource) {
- synchronized (findResourceUIListeners) {
- if (findResourceUIListeners.size() > 0) {
- IFindResourceUIListener listener;
- Iterator<IFindResourceUIListener> listenerItr = findResourceUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onNewResourceFound(resource);
- }
- }
- }
- }
- }
-
- private void resourceSelectionChangedUINotification(RemoteResource resource) {
- synchronized (resourceSelectionChangedUIListeners) {
- if (resourceSelectionChangedUIListeners.size() > 0) {
- IResourceSelectionChangedUIListener listener;
- Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onResourceSelectionChange(resource);
- }
- }
- }
- }
- }
-
- private void getCompleteNotification(RemoteResource resource) {
- synchronized (getUIListeners) {
- if (getUIListeners.size() > 0) {
- IGetUIListener listener;
- Iterator<IGetUIListener> listenerItr = getUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onGetCompleted(resource);
- }
- }
- }
- }
- }
-
- private void putCompleteNotification(RemoteResource resource) {
- synchronized (putUIListeners) {
- if (putUIListeners.size() > 0) {
- IPutUIListener listener;
- Iterator<IPutUIListener> listenerItr = putUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPutCompleted(resource);
- }
- }
- }
- }
- }
-
- private void postCompleteNotification(RemoteResource resource) {
- synchronized (postUIListeners) {
- if (postUIListeners.size() > 0) {
- IPostUIListener listener;
- Iterator<IPostUIListener> listenerItr = postUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPostCompleted(resource);
- }
- }
- }
- }
- }
-
- private void observeCompleteNotification(RemoteResource resource) {
- synchronized (observeUIListeners) {
- if (observeUIListeners.size() > 0) {
- IObserveUIListener listener;
- Iterator<IObserveUIListener> listenerItr = observeUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onObserveCompleted(resource);
- }
- }
- }
- }
- }
-
- private void verificationStartedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationStarted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void verificationAbortedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationAborted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void verificationCompletedNotification(RemoteResource resource,
- int autoType) {
- synchronized (verificationUIListeners) {
- if (verificationUIListeners.size() > 0) {
- IVerificationUIListener listener;
- Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onVerificationCompleted(resource, autoType);
- }
- }
- }
- }
- }
-
- private void configUploadedNotification(RemoteResource resource) {
- synchronized (configUploadUIListeners) {
- if (configUploadUIListeners.size() > 0) {
- IConfigurationUpload listener;
- Iterator<IConfigurationUpload> listenerItr = configUploadUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onConfigurationUploaded(resource);
- }
- }
- }
- }
- }
-
- private void deviceInfoReceivedNotification() {
- synchronized (devicePlatformInfoUIListeners) {
- if (devicePlatformInfoUIListeners.size() > 0) {
- IDevicePlatformInfoUIListener listener;
- Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onDeviceInfoFound();
- }
- }
- }
- }
- }
-
- private void platformInfoReceivedNotification() {
- synchronized (devicePlatformInfoUIListeners) {
- if (devicePlatformInfoUIListeners.size() > 0) {
- IDevicePlatformInfoUIListener listener;
- Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onPlatformInfoFound();
- }
- }
- }
- }
- }
-
public synchronized Set<String> getLastKnownSearchTypes() {
return lastKnownSearchTypes;
}
}
// Change the current resource in selection
setCurrentResourceInSelection(null);
- resourceSelectionChangedUINotification(null);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(null);
} else {
Iterator<String> typeItr = searchTypes.iterator();
String resType;
type = itr.next();
if (searchTypes.contains(type)) {
setCurrentResourceInSelection(null);
- resourceSelectionChangedUINotification(null);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(null);
break;
}
}
public void run() {
setCurrentResourceInSelection(resource);
// Notify all observers for resource selection change event
- resourceSelectionChangedUINotification(resource);
+ UiListenerHandler.getInstance()
+ .resourceSelectionChangedUINotification(resource);
}
}.start();
}
metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME,
platInfo.getSystemTime()));
}
- /*
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, ""));
- * metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME,
- * "")); metaProperties .add(new
- * MetaProperty(Constants.PLATFORM_MANUFAC_URL, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO,
- * "")); metaProperties.add(new
- * MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION, ""));
- * metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION,
- * "")); metaProperties.add(new MetaProperty(
- * Constants.PLATFORM_HARDWARE_VERSION, "")); metaProperties.add(new
- * MetaProperty( Constants.PLATFORM_FIRMWARE_VERSION, ""));
- * metaProperties .add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL,
- * "")); metaProperties .add(new
- * MetaProperty(Constants.PLATFORM_SYSTEM_TIME, ""));
- */
return metaProperties;
}
return values;
}
- /*
- * public String getAttributeValue(RemoteResource res, String attName) { if
- * (null == res || null == attName) { return null; } return
- * res.getAttributeValue(attName); }
- */
public void sendGetRequest(RemoteResource resource) {
if (null == resource) {
return;
if (null == resourceN) {
return;
}
+
try {
resourceN.get(null, getListener);
} catch (SimulatorException e) {
resource.setConfigUploaded(true);
// Notify the UI listeners
- configUploadedNotification(resource);
+ UiListenerHandler.getInstance().configUploadedNotification(resource);
return true;
}
--- /dev/null
+package oic.simulator.clientcontroller.manager;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import oic.simulator.clientcontroller.listener.IConfigurationUpload;
+import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
+import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
+import oic.simulator.clientcontroller.listener.IGetUIListener;
+import oic.simulator.clientcontroller.listener.IObserveUIListener;
+import oic.simulator.clientcontroller.listener.IPostUIListener;
+import oic.simulator.clientcontroller.listener.IPutUIListener;
+import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.clientcontroller.listener.IVerificationUIListener;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+
+public class UiListenerHandler {
+ private static UiListenerHandler uiHandler;
+
+ private List<IFindResourceUIListener> findResourceUIListeners;
+ private List<IResourceSelectionChangedUIListener> resourceSelectionChangedUIListeners;
+ private List<IGetUIListener> getUIListeners;
+ private List<IPutUIListener> putUIListeners;
+ private List<IPostUIListener> postUIListeners;
+ private List<IObserveUIListener> observeUIListeners;
+ private List<IVerificationUIListener> verificationUIListeners;
+ private List<IConfigurationUpload> configUploadUIListeners;
+ private List<IDevicePlatformInfoUIListener> devicePlatformInfoUIListeners;
+
+ private UiListenerHandler() {
+ findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
+ resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
+ getUIListeners = new ArrayList<IGetUIListener>();
+ putUIListeners = new ArrayList<IPutUIListener>();
+ postUIListeners = new ArrayList<IPostUIListener>();
+ observeUIListeners = new ArrayList<IObserveUIListener>();
+ verificationUIListeners = new ArrayList<IVerificationUIListener>();
+ configUploadUIListeners = new ArrayList<IConfigurationUpload>();
+ devicePlatformInfoUIListeners = new ArrayList<IDevicePlatformInfoUIListener>();
+ }
+
+ public static UiListenerHandler getInstance() {
+ if (null == uiHandler) {
+ uiHandler = new UiListenerHandler();
+ }
+ return uiHandler;
+ }
+
+ public void addResourceSelectionChangedUIListener(
+ IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
+ synchronized (resourceSelectionChangedUIListeners) {
+ resourceSelectionChangedUIListeners
+ .add(resourceSelectionChangedUIListener);
+ }
+ }
+
+ public void addGetUIListener(IGetUIListener getUIListener) {
+ synchronized (getUIListeners) {
+ getUIListeners.add(getUIListener);
+ }
+ }
+
+ public void addPutUIListener(IPutUIListener putUIListener) {
+ synchronized (putUIListeners) {
+ putUIListeners.add(putUIListener);
+ }
+ }
+
+ public void addPostUIListener(IPostUIListener postUIListener) {
+ synchronized (postUIListeners) {
+ postUIListeners.add(postUIListener);
+ }
+ }
+
+ public void addObserveUIListener(IObserveUIListener observeUIListener) {
+ synchronized (observeUIListeners) {
+ observeUIListeners.add(observeUIListener);
+ }
+ }
+
+ public void addVerificationUIListener(
+ IVerificationUIListener verificationUIListener) {
+ synchronized (verificationUIListeners) {
+ verificationUIListeners.add(verificationUIListener);
+ }
+ }
+
+ public void addConfigUploadUIListener(IConfigurationUpload configListener) {
+ synchronized (configUploadUIListeners) {
+ configUploadUIListeners.add(configListener);
+ }
+ }
+
+ public void addDevicePlatformInfoUIListener(
+ IDevicePlatformInfoUIListener deviceUIListener) {
+ synchronized (devicePlatformInfoUIListeners) {
+ devicePlatformInfoUIListeners.add(deviceUIListener);
+ }
+ }
+
+ public void removeDevicePlatformInfoUIListener(
+ IDevicePlatformInfoUIListener platformUIListener) {
+ synchronized (devicePlatformInfoUIListeners) {
+ devicePlatformInfoUIListeners.remove(platformUIListener);
+ }
+ }
+
+ public void removeResourceSelectionChangedUIListener(
+ IResourceSelectionChangedUIListener listener) {
+ synchronized (resourceSelectionChangedUIListeners) {
+ if (null != listener
+ && resourceSelectionChangedUIListeners.size() > 0) {
+ resourceSelectionChangedUIListeners.remove(listener);
+ }
+ }
+ }
+
+ public void removeGetUIListener(IGetUIListener getUIListener) {
+ synchronized (getUIListeners) {
+ getUIListeners.remove(getUIListener);
+ }
+ }
+
+ public void removePutUIListener(IPutUIListener putUIListener) {
+ synchronized (putUIListeners) {
+ putUIListeners.remove(putUIListener);
+ }
+ }
+
+ public void removePostUIListener(IPostUIListener postUIListener) {
+ synchronized (postUIListeners) {
+ postUIListeners.remove(postUIListener);
+ }
+ }
+
+ public void removeObserveUIListener(IObserveUIListener observeUIListener) {
+ synchronized (observeUIListeners) {
+ observeUIListeners.remove(observeUIListener);
+ }
+ }
+
+ public void removeVerificationUIListener(
+ IVerificationUIListener verificationUIListener) {
+ synchronized (verificationUIListeners) {
+ verificationUIListeners.remove(verificationUIListener);
+ }
+ }
+
+ public void removeConfigUploadUIListener(IConfigurationUpload configListener) {
+ synchronized (configUploadUIListeners) {
+ configUploadUIListeners.remove(configListener);
+ }
+ }
+
+ public void addFindresourceUIListener(IFindResourceUIListener listener) {
+ if (null == listener) {
+ return;
+ }
+ synchronized (findResourceUIListeners) {
+ findResourceUIListeners.add(listener);
+ }
+ }
+
+ public void removeFindresourceUIListener(IFindResourceUIListener listener) {
+ if (null == listener) {
+ return;
+ }
+ synchronized (findResourceUIListeners) {
+ findResourceUIListeners.remove(listener);
+ }
+ }
+
+ public void newResourceFoundNotification(RemoteResource resource) {
+ synchronized (findResourceUIListeners) {
+ if (findResourceUIListeners.size() > 0) {
+ IFindResourceUIListener listener;
+ Iterator<IFindResourceUIListener> listenerItr = findResourceUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onNewResourceFound(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void resourceSelectionChangedUINotification(RemoteResource resource) {
+ synchronized (resourceSelectionChangedUIListeners) {
+ if (resourceSelectionChangedUIListeners.size() > 0) {
+ IResourceSelectionChangedUIListener listener;
+ Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onResourceSelectionChange(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void getCompleteNotification(RemoteResource resource) {
+ synchronized (getUIListeners) {
+ if (getUIListeners.size() > 0) {
+ IGetUIListener listener;
+ Iterator<IGetUIListener> listenerItr = getUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onGetCompleted(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void putCompleteNotification(RemoteResource resource) {
+ synchronized (putUIListeners) {
+ if (putUIListeners.size() > 0) {
+ IPutUIListener listener;
+ Iterator<IPutUIListener> listenerItr = putUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onPutCompleted(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void postCompleteNotification(RemoteResource resource) {
+ synchronized (postUIListeners) {
+ if (postUIListeners.size() > 0) {
+ IPostUIListener listener;
+ Iterator<IPostUIListener> listenerItr = postUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onPostCompleted(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void observeCompleteNotification(RemoteResource resource) {
+ synchronized (observeUIListeners) {
+ if (observeUIListeners.size() > 0) {
+ IObserveUIListener listener;
+ Iterator<IObserveUIListener> listenerItr = observeUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onObserveCompleted(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void verificationStartedNotification(RemoteResource resource,
+ int autoType) {
+ synchronized (verificationUIListeners) {
+ if (verificationUIListeners.size() > 0) {
+ IVerificationUIListener listener;
+ Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onVerificationStarted(resource, autoType);
+ }
+ }
+ }
+ }
+ }
+
+ public void verificationAbortedNotification(RemoteResource resource,
+ int autoType) {
+ synchronized (verificationUIListeners) {
+ if (verificationUIListeners.size() > 0) {
+ IVerificationUIListener listener;
+ Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onVerificationAborted(resource, autoType);
+ }
+ }
+ }
+ }
+ }
+
+ public void verificationCompletedNotification(RemoteResource resource,
+ int autoType) {
+ synchronized (verificationUIListeners) {
+ if (verificationUIListeners.size() > 0) {
+ IVerificationUIListener listener;
+ Iterator<IVerificationUIListener> listenerItr = verificationUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onVerificationCompleted(resource, autoType);
+ }
+ }
+ }
+ }
+ }
+
+ public void configUploadedNotification(RemoteResource resource) {
+ synchronized (configUploadUIListeners) {
+ if (configUploadUIListeners.size() > 0) {
+ IConfigurationUpload listener;
+ Iterator<IConfigurationUpload> listenerItr = configUploadUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onConfigurationUploaded(resource);
+ }
+ }
+ }
+ }
+ }
+
+ public void deviceInfoReceivedNotification() {
+ synchronized (devicePlatformInfoUIListeners) {
+ if (devicePlatformInfoUIListeners.size() > 0) {
+ IDevicePlatformInfoUIListener listener;
+ Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onDeviceInfoFound();
+ }
+ }
+ }
+ }
+ }
+
+ public void platformInfoReceivedNotification() {
+ synchronized (devicePlatformInfoUIListeners) {
+ if (devicePlatformInfoUIListeners.size() > 0) {
+ IDevicePlatformInfoUIListener listener;
+ Iterator<IDevicePlatformInfoUIListener> listenerItr = devicePlatformInfoUIListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.onPlatformInfoFound();
+ }
+ }
+ }
+ }
+ }
+}
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.clientcontroller.remoteresource;
import java.util.HashMap;
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.clientcontroller.remoteresource;
import org.oic.simulator.DeviceInfo;
private SimulatorRemoteResource remoteResourceRef;
private SimulatorResourceModel resourceModelRef;
private ResourceRepresentation mResourceRepresentation;
- // private Map<String, RemoteResourceAttribute> resourceAttributesMap;
private boolean configUploaded;
this.resourceModelRef = resourceModel;
}
- /*
- * public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
- * return resourceAttributesMap; }
- *
- * public void setResourceAttributesMap( Map<String,
- * RemoteResourceAttribute> resourceAttributesMap) {
- * this.resourceAttributesMap = resourceAttributesMap; }
- */
public int getGetAutomtnId() {
return getAutomtnId;
}
this.observed = observed;
}
- /*
- * public List<PutPostAttributeModel> getPutPostModel() { Map<String,
- * RemoteResourceAttribute> attMap = getResourceAttributesMap(); if (null ==
- * attMap || attMap.size() < 1) { return null; } List<PutPostAttributeModel>
- * putPostModelList = new ArrayList<PutPostAttributeModel>(); String
- * attName; RemoteResourceAttribute attribute; PutPostAttributeModel
- * putPostModel; Iterator<String> attItr = attMap.keySet().iterator(); while
- * (attItr.hasNext()) { attName = attItr.next(); attribute =
- * attMap.get(attName); putPostModel =
- * PutPostAttributeModel.getModel(attribute); if (null != putPostModel) {
- * putPostModelList.add(putPostModel); } } return putPostModelList; }
- *
- * public String getAttributeValue(String attName) { RemoteResourceAttribute
- * attribute = resourceAttributesMap.get(attName); if (null == attribute) {
- * return null; } return String.valueOf(attribute.getAttributeValue()); }
- */
public int getAutomationtype(int autoId) {
if (getAutomtnId == autoId) {
return Constants.GET_AUTOMATION_INDEX;
} else if (putAutomtnId == autoId) {
return Constants.PUT_AUTOMATION_INDEX;
- } else {// if(postAutomtnId == autoId) {
+ } else {
return Constants.POST_AUTOMATION_INDEX;
}
}
getAutomtnInProgress = status;
} else if (putAutomtnId == autoId) {
putAutomtnInProgress = status;
- } else {// if(postAutomtnId == autoId) {
+ } else {
postAutomtnInProgress = status;
}
}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.clientcontroller.remoteresource;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.oic.simulator.AttributeProperty.Type;
-import org.oic.simulator.AttributeValue.ValueType;
-import org.oic.simulator.SimulatorResourceAttribute;
-
-/**
- * This class represents an attribute in the remote resource.
- */
-public class RemoteResourceAttribute {
-
- // Native object reference
- private SimulatorResourceAttribute resourceAttributeRef;
-
- private String attributeName;
- private Object attributeValue;
-
- private ValueType attValType;
- private ValueType attValBaseType;
- private int depth;
-
- private Type valuesType;
- private List<Object> allowedValues;
- private Object minValue;
- private Object maxValue;
-
- public SimulatorResourceAttribute getResourceAttributeRef() {
- return resourceAttributeRef;
- }
-
- public void setResourceAttributeRef(
- SimulatorResourceAttribute resourceAttribute) {
- this.resourceAttributeRef = resourceAttribute;
- }
-
- public String getAttributeName() {
- return attributeName;
- }
-
- public void setAttributeName(String attributeName) {
- this.attributeName = attributeName;
- }
-
- public Object getAttributeValue() {
- return attributeValue;
- }
-
- public void setAttributeValue(Object attributeValue) {
- this.attributeValue = attributeValue;
- }
-
- public List<Object> getAllowedValues() {
- return allowedValues;
- }
-
- public void setAllowedValues(List<Object> allowedValues) {
- this.allowedValues = allowedValues;
- }
-
- public void setAllowedValues(String[] allowedValues) {
- List<Object> allowedValueList = null;
- if (null != allowedValues && allowedValues.length > 0) {
- allowedValueList = new ArrayList<Object>();
- for (String value : allowedValues) {
- allowedValueList.add(value);
- }
- }
- this.allowedValues = allowedValueList;
- }
-
- public Object getMinValue() {
- return minValue;
- }
-
- public void setMinValue(Object minValue) {
- this.minValue = minValue;
- }
-
- public Object getMaxValue() {
- return maxValue;
- }
-
- public void setMaxValue(Object maxValue) {
- this.maxValue = maxValue;
- }
-
- public static RemoteResourceAttribute clone(
- RemoteResourceAttribute attribute) {
- RemoteResourceAttribute clone = null;
- if (null != attribute) {
- clone = new RemoteResourceAttribute();
- clone.setAttributeName(attribute.getAttributeName());
- clone.setAttributeValue(attribute.getAttributeValue());
- clone.setAllowedValues(attribute.getAllowedValues());
- clone.setAttValBaseType(attribute.getAttValBaseType());
- clone.setAttValType(attribute.getAttValType());
- clone.setMinValue(attribute.getMinValue());
- clone.setMaxValue(attribute.getMaxValue());
- clone.setResourceAttributeRef(null);
- }
- return clone;
- }
-
- // This method gives all known possible values of the attribute in string
- // format.
- // It takes allowed values or range of values whichever is available
- public List<String> getAllValues() {
- List<String> valueList = new ArrayList<String>();
- if (null != allowedValues) {
- Iterator<Object> values = allowedValues.iterator();
- Object value;
- while (values.hasNext()) {
- value = values.next();
- if (null != value) {
- valueList.add(String.valueOf(value));
- }
- }
- } else if (null != minValue && null != maxValue) {
- double min = (Double) minValue;
- double max = (Double) maxValue;
- for (double value = min; value <= max; value++) {
- valueList.add(String.valueOf(value));
- }
- }
- if (valueList.size() < 1 && null != attributeValue) {
- valueList.add(String.valueOf(attributeValue));
- }
- return valueList;
- }
-
- // Method added for debugging purpose
- public static void printAttributes(
- Map<String, RemoteResourceAttribute> attributeMap) {
- Iterator<String> itr = attributeMap.keySet().iterator();
- String attName;
- RemoteResourceAttribute att;
- while (itr.hasNext()) {
- attName = itr.next();
- att = attributeMap.get(attName);
- System.out.println("AttributeName:" + attName);
- System.out.println("AttributeValue:"
- + att.getAttributeValue().toString());
- System.out.println("Allowed Values:" + att.getAllValues());
- }
- }
-
- public ValueType getAttValType() {
- return attValType;
- }
-
- public void setAttValType(ValueType attValType) {
- this.attValType = attValType;
- }
-
- public ValueType getAttValBaseType() {
- return attValBaseType;
- }
-
- public void setAttValBaseType(ValueType attValBaseType) {
- this.attValBaseType = attValBaseType;
- }
-
- public Type getValuesType() {
- return valuesType;
- }
-
- public void setValuesType(Type valuesType) {
- this.valuesType = valuesType;
- }
-
- public int getDepth() {
- return depth;
- }
-
- public void setDepth(int depth) {
- this.depth = depth;
- }
-}
\ No newline at end of file
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.clientcontroller.remoteresource;
import java.util.HashMap;
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.clientcontroller.utils;
import java.util.Map;
public static final String DEBUG = "Debug";
public static final String UNKNOWN = "Unknown";
- public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] {
- "*.raml", "*" };
+ public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" };
public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] {
"*.log", "*" };
public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version";
public static final String PLATFORM_SUPPORT_URL = "Support URL";
public static final String PLATFORM_SYSTEM_TIME = "System Time";
+
+ public static final String BASELINE_INTERFACE = "oic.if.baseline";
+ public static final String LINKS_LIST_INTERFACE = "oic.if.ll";
+ public static final String BATCH_INTERFACE = "oic.if.b";
+ public static final String LINK_BATCH_INTERFACE = "oic.if.lb";
+ public static final String READ_ONLY_INTERFACE = "oic.if.r";
+ public static final String READ_WRITE_INTERFACE = "oic.if.rw";
+ public static final String ACTUATOR_INTERFACE = "oic.if.a";
+ public static final String SENSOR_INTERFACE = "oic.if.s";
}
package oic.simulator.clientcontroller.utils;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.oic.simulator.AttributeValue;
return String.valueOf(value);
}
}
+
+ public static Map<String, String> getResourceInterfaces() {
+ Map<String, String> ifTypes = null;
+ ifTypes = new HashMap<String, String>();
+ ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline");
+ ifTypes.put(Constants.LINKS_LIST_INTERFACE, "Links List");
+ ifTypes.put(Constants.BATCH_INTERFACE, "Batch");
+ ifTypes.put(Constants.LINK_BATCH_INTERFACE, "Link Batch");
+ ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only");
+ ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write");
+ ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator");
+ ifTypes.put(Constants.SENSOR_INTERFACE, "Sensor");
+ return ifTypes;
+ }
}
\ No newline at end of file
if (dialog instanceof PostRequestDialog) {
viewer.update(attributeElement, null);
- // comboBox.setVisible(false);
}
}
});
public void updateAttributeValue(SimulatorResourceAttribute att,
AttributeValue value) {
- att.setValue(value);
-
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (null == selection) {
import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
import oic.simulator.clientcontroller.listener.IVerificationUIListener;
import oic.simulator.clientcontroller.manager.ResourceManager;
+import oic.simulator.clientcontroller.manager.UiListenerHandler;
import oic.simulator.clientcontroller.remoteresource.AttributeElement;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
getButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (resourceInSelection.isGetAutomtnInProgress()) {
- MessageDialog
- .openInformation(Display.getDefault()
- .getActiveShell(), "GET Request",
- "GET Automation is in progress. Please wait or stop the automation.");
- } else {
- resourceManager.sendGetRequest(resourceInSelection);
- }
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() {
+ @Override
+ public void run() {
+ resourceManager.sendGetRequest(resourceInSelection);
+ }
+ });
}
});
PutRequestDialog putDialog = new PutRequestDialog(
Display.getDefault().getActiveShell());
if (putDialog.open() == Window.OK) {
- // Call the native PUT method
resourceManager.sendPutRequest(resourceInSelection,
putDialog.getUpdatedRepresentation()
.getModel());
PostRequestDialog postDialog = new PostRequestDialog(
Display.getDefault().getActiveShell());
if (postDialog.open() == Window.OK) {
- // Call the native POST method
ResourceRepresentation representation = postDialog
.getUpdatedRepresentation();
resourceManager.sendPostRequest(
}
private void addManagerListeners() {
- resourceManager
- .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
- resourceManager.addGetUIListener(getUIListener);
- resourceManager.addPutUIListener(putUIListener);
- resourceManager.addPostUIListener(postUIListener);
- resourceManager.addObserveUIListener(observeUIListener);
- resourceManager.addVerificationUIListener(verificationUIListener);
- resourceManager.addConfigUploadUIListener(configUploadUIListener);
+ UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
+ resourceSelectionChangedListener);
+ UiListenerHandler.getInstance().addGetUIListener(getUIListener);
+ UiListenerHandler.getInstance().addPutUIListener(putUIListener);
+ UiListenerHandler.getInstance().addPostUIListener(postUIListener);
+ UiListenerHandler.getInstance().addObserveUIListener(observeUIListener);
+ UiListenerHandler.getInstance().addVerificationUIListener(
+ verificationUIListener);
+ UiListenerHandler.getInstance().addConfigUploadUIListener(
+ configUploadUIListener);
}
private void setVisibility(boolean visibility) {
public void dispose() {
// Unregister the selection listener
if (null != resourceSelectionChangedListener) {
- resourceManager
- .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+ UiListenerHandler.getInstance()
+ .removeResourceSelectionChangedUIListener(
+ resourceSelectionChangedListener);
}
// Unregister the GET listener
if (null != getUIListener) {
- resourceManager.removeGetUIListener(getUIListener);
+ UiListenerHandler.getInstance().removeGetUIListener(getUIListener);
}
super.dispose();
import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener;
import oic.simulator.clientcontroller.manager.ResourceManager;
+import oic.simulator.clientcontroller.manager.UiListenerHandler;
import oic.simulator.clientcontroller.remoteresource.MetaProperty;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
}
private void addManagerListeners() {
- resourceManager
- .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
- resourceManager
- .addDevicePlatformInfoUIListener(devicePlatformInfoUIListener);
+ UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
+ resourceSelectionChangedListener);
+ UiListenerHandler.getInstance().addDevicePlatformInfoUIListener(
+ devicePlatformInfoUIListener);
}
class PropertycontentProvider implements IStructuredContentProvider {
public void dispose() {
// Unregister the listener
if (null != resourceSelectionChangedListener) {
- resourceManager
- .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+ UiListenerHandler.getInstance()
+ .removeResourceSelectionChangedUIListener(
+ resourceSelectionChangedListener);
}
super.dispose();
}
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
import oic.simulator.clientcontroller.manager.ResourceManager;
+import oic.simulator.clientcontroller.manager.UiListenerHandler;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
import oic.simulator.clientcontroller.utils.Constants;
import oic.simulator.clientcontroller.view.dialogs.FindResourceWizard;
}
private void addManagerListeners() {
- resourceManager.addFindresourceUIListener(findListener);
+ UiListenerHandler.getInstance().addFindresourceUIListener(findListener);
}
@Override
public void dispose() {
// Unregister the listener
if (null != findListener) {
- resourceManager.removeFindresourceUIListener(findListener);
+ UiListenerHandler.getInstance().removeFindresourceUIListener(
+ findListener);
resourceManager.resourceSelectionChanged(null);
}
super.dispose();
@Override
protected Control createDialogArea(Composite parent) {
Composite compLayout = (Composite) super.createDialogArea(parent);
+
Composite container = new Composite(compLayout, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(1, false);
@Override
protected Control createDialogArea(Composite parent) {
Composite compLayout = (Composite) super.createDialogArea(parent);
+
Composite container = new Composite(compLayout, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(1, false);
public ResourceRepresentation getUpdatedRepresentation() {
return updatedRepresentation;
}
-
}
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.listener;
import oic.simulator.serviceprovider.model.AttributeElement;
*/
public interface IPropertiesChangedListener {
public void onResourcePropertyChange();
-
- public void onDevicePropertyChange();
}
\ No newline at end of file
package oic.simulator.serviceprovider.listener;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
/**
*/
public interface ISelectionChangedListener {
public void onResourceSelectionChange(Resource resource);
-
- public void onDeviceSelectionChange(Device dev);
}
\ No newline at end of file
import java.util.Map;
import java.util.Set;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
public class Data {
- private Map<String, SingleResource> singleResourceMap;
-
- private Map<String, CollectionResource> collectionResourceMap;
-
- private Map<String, Device> deviceMap;
+ private Map<String, SingleResource> singleResourceMap;
// Holds resource type as key and a resource URI set as values.
// Helps in performing operations based on resource type.
- private Map<String, Set<String>> resTypeToResUriMap;
+ private Map<String, Set<String>> resTypeToResUriMap;
public Data() {
singleResourceMap = new HashMap<String, SingleResource>();
- collectionResourceMap = new HashMap<String, CollectionResource>();
- deviceMap = new HashMap<String, Device>();
resTypeToResUriMap = new HashMap<String, Set<String>>();
}
if (resource instanceof SingleResource) {
singleResourceMap.put(resource.getResourceURI(),
(SingleResource) resource);
- } else {
- collectionResourceMap.put(resource.getResourceURI(),
- (CollectionResource) resource);
}
addToTypeAndUriMap(resource);
}
if (null == resource) {
return;
}
- Set<String> resTypes = resource.getResourceTypes();
- if (null == resTypes || resTypes.isEmpty()) {
+ String resType = resource.getResourceType();
+ if (null == resType || resType.isEmpty()) {
return;
}
String uri = resource.getResourceURI();
if (null == uri || uri.isEmpty()) {
return;
}
- Iterator<String> itr = resTypes.iterator();
- String rType;
Set<String> newTypeSet;
- while (itr.hasNext()) {
- rType = itr.next();
- newTypeSet = resTypeToResUriMap.get(rType);
- if (null == newTypeSet) {
- newTypeSet = new HashSet<String>();
- resTypeToResUriMap.put(rType, newTypeSet);
- }
- newTypeSet.add(uri);
- }
- }
-
- public void addDevice(Device dev) {
- if (null == dev) {
- return;
- }
- synchronized (deviceMap) {
- deviceMap.put(dev.getDeviceName(), dev);
+ newTypeSet = resTypeToResUriMap.get(resType);
+ if (null == newTypeSet) {
+ newTypeSet = new HashSet<String>();
+ resTypeToResUriMap.put(resType, newTypeSet);
}
+ newTypeSet.add(uri);
}
public synchronized void deleteResource(Resource resource) {
}
if (resource instanceof SingleResource) {
singleResourceMap.remove(resource.getResourceURI());
- } else {
- collectionResourceMap.remove(resource.getResourceURI());
}
removeFromTypeAndUriMap(resource);
}
- public synchronized void deleteDevice(Device dev) {
- if (null == dev) {
- return;
- }
- deviceMap.remove(dev.getDeviceName());
- }
-
public synchronized void removeFromTypeAndUriMap(Resource resource) {
if (null == resource) {
return;
}
- Set<String> resTypes = resource.getResourceTypes();
- if (null == resTypes || resTypes.isEmpty()) {
+ String resType = resource.getResourceType();
+ if (null == resType || !resType.isEmpty()) {
return;
}
String uri = resource.getResourceURI();
if (null == uri || uri.isEmpty()) {
return;
}
- Iterator<String> itr = resTypes.iterator();
- String rType;
Set<String> newTypeSet;
- while (itr.hasNext()) {
- rType = itr.next();
- newTypeSet = resTypeToResUriMap.get(rType);
- if (null != newTypeSet) {
- newTypeSet.remove(uri);
- }
- if (null == newTypeSet || newTypeSet.isEmpty()) {
- resTypeToResUriMap.remove(rType);
- }
+ newTypeSet = resTypeToResUriMap.get(resType);
+ if (null != newTypeSet) {
+ newTypeSet.remove(uri);
+ }
+ if (null == newTypeSet || newTypeSet.isEmpty()) {
+ resTypeToResUriMap.remove(resType);
}
}
return resources;
}
- public List<CollectionResource> getCollectionResources() {
- List<CollectionResource> resources;
- synchronized (collectionResourceMap) {
- if (collectionResourceMap.isEmpty()) {
- return null;
- }
- resources = new ArrayList<CollectionResource>();
- Set<String> uriSet = collectionResourceMap.keySet();
- Iterator<String> itr = uriSet.iterator();
- while (itr.hasNext()) {
- resources.add(collectionResourceMap.get(itr.next()));
- }
- }
- return resources;
- }
-
public List<Resource> getResources() {
- if (singleResourceMap.isEmpty() && collectionResourceMap.isEmpty()) {
+ if (singleResourceMap.isEmpty()) {
return null;
}
List<Resource> resourceList = new ArrayList<Resource>();
resourceList.add(singleResourceMap.get(itr.next()));
}
}
- synchronized (collectionResourceMap) {
- Set<String> uriSet = collectionResourceMap.keySet();
- Iterator<String> itr = uriSet.iterator();
- while (itr.hasNext()) {
- resourceList.add(collectionResourceMap.get(itr.next()));
- }
- }
return resourceList;
}
- public List<Device> getDevices() {
- List<Device> devices;
- synchronized (deviceMap) {
- if (deviceMap.isEmpty()) {
- return null;
- }
- devices = new ArrayList<Device>();
- Set<String> uriSet = deviceMap.keySet();
- Iterator<String> itr = uriSet.iterator();
- while (itr.hasNext()) {
- devices.add(deviceMap.get(itr.next()));
- }
- }
- return devices;
- }
-
public synchronized boolean isResourceExist(String resourceURI) {
if (null == resourceURI || resourceURI.isEmpty()) {
return false;
}
if ((null != singleResourceMap && singleResourceMap
- .containsKey(resourceURI))
- || (null != collectionResourceMap && collectionResourceMap
- .containsKey(resourceURI))) {
+ .containsKey(resourceURI))) {
return true;
}
return false;
}
public synchronized boolean isAnyResourceExist() {
- return ((null != singleResourceMap && !singleResourceMap.isEmpty()) || (null != collectionResourceMap && !collectionResourceMap
- .isEmpty()));
+ return ((null != singleResourceMap && !singleResourceMap.isEmpty()));
}
public void changeResourceURI(Resource resource, String curURI,
singleResourceMap.remove(curURI);
singleResourceMap.put(newURI, (SingleResource) resource);
}
- } else {
- synchronized (collectionResourceMap) {
- collectionResourceMap.remove(curURI);
- collectionResourceMap
- .put(newURI, (CollectionResource) resource);
- }
}
resource.setResourceURI(newURI);
}
- public void changeDeviceName(Device dev, String curName, String newName) {
- if (null == dev || null == curName || null == newName) {
- return;
- }
- synchronized (deviceMap) {
- deviceMap.remove(curName);
- deviceMap.put(newName, dev);
- }
- dev.setDeviceName(newName);
- }
-
public SingleResource getSingleResourceByURI(String resourceURI) {
if (null == resourceURI) {
return null;
return res;
}
- public CollectionResource getCollectionResourceByURI(String resourceURI) {
- if (null == resourceURI) {
- return null;
- }
- CollectionResource res;
- synchronized (collectionResourceMap) {
- res = collectionResourceMap.get(resourceURI);
- }
- return res;
- }
-
public Resource getResourceByURI(String resourceURI) {
Resource res = getSingleResourceByURI(resourceURI);
- if (null == res) {
- res = getCollectionResourceByURI(resourceURI);
- }
return res;
}
public synchronized int getResourceCount() {
- return singleResourceMap.size() + collectionResourceMap.size();
+ return singleResourceMap.size();
}
}
// Resource icons based on the resource type
r.put(Constants.SINGLE_RESOURCE, ImageDescriptor.createFromURL(bundle
.getEntry("/icons/single_resource.gif")));
- r.put(Constants.COLLECTION_RESOURCE, ImageDescriptor
- .createFromURL(bundle
- .getEntry("/icons/collection_resource.gif")));
- r.put(Constants.DEVICE, ImageDescriptor.createFromURL(bundle
- .getEntry("/icons/device.gif")));
// Log View related icons
r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.MetaProperty;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.server.Observer;
-import org.oic.simulator.server.SimulatorCollectionResource;
import org.oic.simulator.server.SimulatorResource;
import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
private Resource currentResourceInSelection;
- private Device currentDeviceInSelection;
-
private ResourceModelChangeListener resourceModelChangeListener;
private AutoUpdateListener automationListener;
this.currentResourceInSelection = resource;
}
- public synchronized Device getCurrentDeviceInSelection() {
- return currentDeviceInSelection;
- }
-
- public synchronized void setCurrentDeviceInSelection(Device dev) {
- this.currentDeviceInSelection = dev;
- }
-
public boolean isResourceExist(String resourceURI) {
return data.isResourceExist(resourceURI);
}
if (null == resource) {
return false;
}
- String resType = (String) resource.getResourceTypes().toArray()[0];
+
try {
- // 1. Create the resource.
+ // Create the resource.
SimulatorResource jSimulatorResource = SimulatorManager
.createResource(SimulatorResource.Type.SINGLE,
resource.getResourceName(),
- resource.getResourceURI(), resType);
+ resource.getResourceURI(),
+ resource.getResourceType());
if (null == jSimulatorResource
|| !(jSimulatorResource instanceof SimulatorSingleResource)) {
return false;
SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource;
resource.setSimulatorResource(jSimulatorSingleResource);
- // 2. Cancel observable property if requested by user.
+ // Cancel observable property if requested by user.
if (!resource.isObservable()) {
jSimulatorSingleResource.setObservable(false);
}
- // 3. Set the model change listener.
+ // Set the model change listener.
jSimulatorSingleResource
.setResourceModelChangeListener(resourceModelChangeListener);
- // 4. Set the observer listener if the resource is observable.
+ // Set the observer listener if the resource is observable.
if (resource.isObservable()) {
jSimulatorSingleResource.setObserverListener(observer);
}
- // 5. Add attributes.
+ // Add attributes.
if (null != attributes && !attributes.isEmpty()) {
SimulatorResourceAttribute value;
for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
jSimulatorSingleResource.addAttribute(value);
}
- // 6. Get the resource model java object reference.
+ // Get the resource model java object reference.
resource.setResourceModel(jSimulatorSingleResource
.getResourceModel());
resource.setResourceRepresentation(resource.getResourceModel());
}
- // 6. Register the resource with the platform.
+ // Register the resource with the platform.
jSimulatorSingleResource.start();
resource.setStarted(true);
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
-
- // 8. Add to local cache.
- data.addResource(resource);
-
- // 9. Update UI listeners
- UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.SINGLE);
- return true;
- }
-
- public boolean createCollectionResource(CollectionResource resource)
- throws SimulatorException {
- if (null == resource) {
- return false;
- }
- String resType = (String) resource.getResourceTypes().toArray()[0];
- try {
- // 1. Create the resource.
- SimulatorResource jSimulatorResource = SimulatorManager
- .createResource(SimulatorResource.Type.COLLECTION,
- resource.getResourceName(),
- resource.getResourceURI(), resType);
- if (null == jSimulatorResource
- || !(jSimulatorResource instanceof SimulatorCollectionResource)) {
- return false;
- }
- SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) jSimulatorResource;
- resource.setSimulatorResource(jSimulatorCollectionResource);
-
- // 2. Cancel observable property if requested by user.
- if (!resource.isObservable()) {
- jSimulatorCollectionResource.setObservable(false);
- }
-
- // 3. Set the observer listener if the resource is observable.
- if (resource.isObservable()) {
- jSimulatorCollectionResource.setObserverListener(observer);
- }
-
- // 4. Set the model change listener.
- jSimulatorCollectionResource
- .setResourceModelChangeListener(resourceModelChangeListener);
-
- // 5. Fetch the model and attributes.
- resource.setResourceRepresentation(jSimulatorCollectionResource
- .getResourceModel());
-
- // 6. Register the resource with the platform.
- jSimulatorCollectionResource.start();
- resource.setStarted(true);
+ // Get the resource interfaces
+ resource.setResourceInterfaces(Utility
+ .convertVectorToSet(jSimulatorSingleResource.getInterface()));
} catch (SimulatorException e) {
Activator
.getDefault()
throw e;
}
- // 6. Add to local cache.
+ // Add to local cache.
data.addResource(resource);
- // 7. Update UI listeners
+ // Update UI listeners
UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.COLLECTION);
+ ResourceType.SINGLE);
return true;
}
throws SimulatorException {
Resource resource = null;
try {
- // 1. Create the resource
+ // Create the resource
SimulatorResource jSimulatorResource = SimulatorManager
.createResource(configFilePath);
if (null == jSimulatorResource) {
if (jSimulatorResource instanceof SimulatorSingleResource) {
resource = new SingleResource();
} else {
- resource = new CollectionResource();
+ return null;
}
resource.setSimulatorResource(jSimulatorResource);
- // 2. Fetch and locally store the resource name and uri.
+ // Fetch and locally store the resource name and uri.
String uri = jSimulatorResource.getURI();
if (null == uri || uri.trim().isEmpty()) {
return null;
return false;
}
- // 1. Update resource URI and Name if they are changed.
+ // Update resource URI and Name if they are changed.
String newUri = uri.trim();
String newName = name.trim();
}
}
- // 2. Set the model change listener.
+ // Set the model change listener.
jSimulatorSingleResource
.setResourceModelChangeListener(resourceModelChangeListener);
- // 3. Set the observer listener if the resource is observable.
+ // Set the observer listener if the resource is observable.
if (jSimulatorSingleResource.isObservable()) {
jSimulatorSingleResource.setObserverListener(observer);
singleRes.setObservable(true);
}
- // 4. Fetch the resource model.
+ // Fetch the resource model.
SimulatorResourceModel jResModel = jSimulatorSingleResource
.getResourceModel();
if (null == jResModel) {
}
singleRes.setResourceModel(jResModel);
- // 5. Fetch the basic details of the resource.
- singleRes.addResourceType(jSimulatorSingleResource
+ // Fetch the basic details of the resource.
+ singleRes.setResourceType(jSimulatorSingleResource
.getResourceType());
singleRes
.setResourceInterfaces(Utility
.convertVectorToSet(jSimulatorSingleResource
.getInterface()));
- // 6. Fetch the resource attributes.
+ // Fetch the resource attributes.
singleRes.setResourceRepresentation(jResModel);
- // 7. Register the resource with the platform.
+ // Register the resource with the platform.
jSimulatorSingleResource.start();
singleRes.setStarted(true);
- // 8. Add to local cache.
+ // Add to local cache.
data.addResource(singleRes);
- // 9. Update UI listeners for single instance creation
+ // Update UI listeners for single instance creation
if (!multiInstance)
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.SINGLE);
return true;
}
- /**
- * This method can set/change the resource uri and name of an already
- * created resource which is not yet registered with the platform. This
- * method registers the model change and observer listeners, registers the
- * resource, fetches the resource attributes, updates the local cache and
- * notifies the UI listeners.
- */
- public boolean completeCollectionResourceCreationByRAML(Resource resource,
- String uri, String name) throws SimulatorException {
- if (null == resource || !(resource instanceof CollectionResource)) {
- return false;
- }
-
- CollectionResource collectionRes = (CollectionResource) resource;
-
- SimulatorCollectionResource jSimulatorCollectionResource = null;
-
- try {
- jSimulatorCollectionResource = (SimulatorCollectionResource) resource
- .getSimulatorResource();
- if (null == jSimulatorCollectionResource) {
- return false;
- }
-
- // 1. Update resource URI and Name if they are changed.
- String newUri = uri.trim();
- String newName = name.trim();
-
- if (!collectionRes.getResourceURI().equals(newUri)) {
- jSimulatorCollectionResource.setURI(newUri);
- collectionRes.setResourceURI(newUri);
- }
- if (!collectionRes.getResourceName().equals(newName)) {
- jSimulatorCollectionResource.setName(newName);
- collectionRes.setResourceName(newName);
- }
-
- // 2. Set the model change listener.
- jSimulatorCollectionResource
- .setResourceModelChangeListener(resourceModelChangeListener);
-
- // 3. Fetch the resource model.
- SimulatorResourceModel jResModel = jSimulatorCollectionResource
- .getResourceModel();
- if (null == jResModel) {
- return false;
- }
- collectionRes.setResourceModel(jResModel);
-
- // 4. Fetch the basic details of the resource.
- collectionRes.addResourceType(jSimulatorCollectionResource
- .getResourceType());
- collectionRes.setResourceInterfaces(Utility
- .convertVectorToSet(jSimulatorCollectionResource
- .getInterface()));
-
- // 5. Set the observer listener if the resource is observable.
- if (jSimulatorCollectionResource.isObservable()) {
- jSimulatorCollectionResource.setObserverListener(observer);
- collectionRes.setObservable(true);
- }
-
- // 6. Fetch the resource attributes.
- collectionRes.setResourceRepresentation(jResModel);
-
- // 7. Register the resource with the platform.
- jSimulatorCollectionResource.start();
- collectionRes.setStarted(true);
-
- // 8. Add to local cache.
- data.addResource(collectionRes);
-
- // 9. Update UI listeners for single instance creation
- UiListenerHandler.getInstance().resourceCreatedUINotification(
- ResourceType.COLLECTION);
- } catch (Exception e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- return true;
- }
-
public int createSingleResourceMultiInstances(String configFile, int count)
throws SimulatorException {
int createCount = 0;
return createCount;
}
- public Device createDevice(String deviceName, Set<Resource> childs) {
- // 1. Create device
- Device dev = new Device();
- dev.setDeviceName(deviceName);
- data.addDevice(dev);
-
- // 2. Add children to device
- if (null != childs && !childs.isEmpty())
- addResourceToDevice(dev, childs);
-
- // 3. Update ui listeners
- UiListenerHandler.getInstance().resourceListUpdateUINotification(
- ResourceType.DEVICE);
- return dev;
- }
-
public List<Resource> getResourceList() {
List<Resource> resourceList = data.getResources();
if (null == resourceList) {
return resourceList;
}
- public List<CollectionResource> getCollectionResourceList() {
- List<CollectionResource> resourceList = data.getCollectionResources();
- if (null == resourceList) {
- return null;
- }
- // Sort the list
- Collections.sort(resourceList, Utility.collectionResourceComparator);
-
- return resourceList;
- }
-
- public List<Device> getDeviceList() {
- List<Device> deviceList = data.getDevices();
- if (null == deviceList) {
- return null;
- }
- // Sort the list
- Collections.sort(deviceList, Utility.deviceComparator);
- return deviceList;
- }
-
- // Returns the number of resources which are added properly to the
- // collection.
- public int addResourceToCollection(CollectionResource collectionParent,
- Set<Resource> childs) {
- if (null == collectionParent || null == childs || childs.isEmpty()) {
- return -1;
- }
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- int count = childs.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- addResourceToCollection(collectionParent, res);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void addResourceToCollection(CollectionResource collectionParent,
- Resource child) throws SimulatorException {
- if (null == collectionParent || null == child) {
- return;
- }
- try {
- // 1. Add child to collection
- collectionParent.addChildResource(child);
-
- // 2. Add a reference to the collection in the child
- if (child instanceof SingleResource) {
- ((SingleResource) child)
- .addCollectionMembership(collectionParent);
- } else {
- ((CollectionResource) child).addMembership(collectionParent);
- }
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- }
-
- public int addResourceToCollection(Set<CollectionResource> collections,
- Resource child) {
- if (null == collections || collections.isEmpty() || null == child) {
- return -1;
- }
- Iterator<CollectionResource> itr = collections.iterator();
- CollectionResource res;
- int count = collections.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- addResourceToCollection(res, child);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void addResourceToDevice(Device dev, Set<Resource> childs) {
- // 1. Add children to the device.
- dev.addChildResource(childs);
-
- // 2. Add a reference to the device in all children.
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (res instanceof SingleResource) {
- ((SingleResource) res).addDeviceMembership(dev);
- } else {
- ((CollectionResource) res).addDeviceMembership(dev);
- }
- }
- }
-
- public void addResourceToDevice(Device dev, Resource child) {
- // 1. Add child to the device.
- dev.addChildResource(child);
-
- // 2. Add a reference to the device in the child.
- if (child instanceof SingleResource) {
- ((SingleResource) child).addDeviceMembership(dev);
- } else {
- ((CollectionResource) child).addDeviceMembership(dev);
- }
- }
-
- public void addResourceToDevice(Set<Device> devices, Resource child) {
- // 1. Add device reference in child.
- if (child instanceof SingleResource)
- ((SingleResource) child).addDeviceMembership(devices);
- else
- ((CollectionResource) child).addDeviceMembership(devices);
-
- // 2. Add a reference to the child in all devices.
- Iterator<Device> itr = devices.iterator();
- Device dev;
- while (itr.hasNext()) {
- dev = itr.next();
- dev.addChildResource(child);
- }
- }
-
- public int removeResourceFromCollection(
- Set<CollectionResource> collections, Resource resource) {
- // 1. Remove the reference of resource from all the collections.
- Iterator<CollectionResource> itr = collections.iterator();
- CollectionResource colRes;
- int count = collections.size();
- while (itr.hasNext()) {
- colRes = itr.next();
- try {
- removeResourceFromCollection(colRes, resource);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
-
- }
-
- public void removeResourceFromDevice(Set<Device> devices, Resource resource) {
- // 1. Remove the reference of resource from all the devices.
- Iterator<Device> itr = devices.iterator();
- Device dev;
- while (itr.hasNext()) {
- dev = itr.next();
- dev.removeChildResource(resource);
- }
-
- // 2. Remove the reference of devices from the resource.
- resource.removeDeviceMembership(devices);
- }
-
- // Returns the count of resources removed from the collection
- public int removeResourcesFromCollection(CollectionResource colRes,
- Set<Resource> resources) {
- Iterator<Resource> itr = resources.iterator();
- Resource res;
- int count = resources.size();
- while (itr.hasNext()) {
- res = itr.next();
- try {
- removeResourceFromCollection(colRes, res);
- } catch (SimulatorException e) {
- count--;
- }
- }
- return count;
- }
-
- public void removeResourcesFromDevice(Device dev, Set<Resource> resources) {
- Iterator<Resource> itr = resources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- res.removeDeviceMembership(dev);
- }
- dev.removeChildResource(resources);
- }
-
- public void removeResourceFromCollection(CollectionResource parent,
- Resource child) throws SimulatorException {
- try {
- // 1. Remove the child from the parent
- parent.removeChildResource(child);
-
- // 2. Remove the reference to parent from child
- if (child instanceof SingleResource) {
- ((SingleResource) child).removeCollectionMembership(parent);
- } else {
- ((CollectionResource) child).removeMembership(parent);
- }
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- throw e;
- }
- }
-
- public void removeResourceFromDevice(Device parent, Resource child) {
- // 1. Remove the reference to parent from child
- child.removeDeviceMembership(parent);
-
- // 2. Remove the child from the parent
- parent.removeChildResource(child);
- }
-
public void removeSingleResources(Set<SingleResource> resources)
throws SimulatorException {
if (null == resources) {
}
}
- public void removeCollectionResources(Set<CollectionResource> resources)
- throws SimulatorException {
- if (null == resources) {
- return;
- }
- Iterator<CollectionResource> itr = resources.iterator();
- while (itr.hasNext()) {
- removeResource(itr.next());
- }
- }
-
public void removeResource(Resource res) throws SimulatorException {
- // 1. Unregister the resource from the platform.
+ // Unregister the resource from the platform.
SimulatorResource simRes = res.getSimulatorResource();
try {
simRes.stop();
throw e;
}
- Set<CollectionResource> collectionMembership;
- Set<Device> deviceMembership;
-
- if (res instanceof SingleResource) {
- collectionMembership = ((SingleResource) res)
- .getCollectionMembership();
- deviceMembership = ((SingleResource) res).getDeviceMembership();
- } else {
- collectionMembership = ((CollectionResource) res).getMembership();
- deviceMembership = ((CollectionResource) res).getDeviceMembership();
- }
-
- // 2. Delete from the collections to which this resource is a member.
- if (null != collectionMembership && !collectionMembership.isEmpty()) {
- removeResourceFromCollection(collectionMembership, res);
- }
-
- // 3. Delete from the devices to which this resource is a member.
- if (null != deviceMembership && !deviceMembership.isEmpty()) {
- removeResourceFromDevice(deviceMembership, res);
- }
-
- // 4. Delete this resource
+ // Delete this resource
data.deleteResource(res);
}
- public void removeDevice(Device dev) {
- Set<Resource> childs = dev.getChildResources();
- if (null != childs && !childs.isEmpty()) {
- // 1. Remove the reference from all the children.
- Iterator<Resource> itr = childs.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- res.removeDeviceMembership(dev);
- }
- }
- // 2. Delete the device.
- data.deleteDevice(dev);
- }
-
public boolean isUriUnique(List<MetaProperty> properties) {
if (null == properties) {
return false;
return false;
}
- public List<CollectionResource> getCollectionsForAddingToSingleResource(
- SingleResource resource) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- Set<CollectionResource> collectionMembership;
- collectionMembership = resource.getCollectionMembership();
- if (null == collectionMembership || collectionMembership.isEmpty()) {
- return collectionResources;
- }
-
- if (collectionMembership.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(collectionMembership);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<SingleResource> getSingleTypeResourcesForAddingToCollectionResource(
- CollectionResource colRes) {
- List<SingleResource> singleResources = data.getSingleResources();
- if (null == singleResources || singleResources.isEmpty()) {
- return null;
- }
-
- Set<SingleResource> childs;
- childs = colRes.getSingleTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return singleResources;
- }
-
- if (childs.size() == singleResources.size()) {
- return null;
- }
-
- singleResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(singleResources, Utility.singleResourceComparator);
-
- return singleResources;
- }
-
- public List<SingleResource> getSingleTypeResourcesForAddingToDevice(
- Device dev) {
- List<SingleResource> singleResources = data.getSingleResources();
- if (null == singleResources || singleResources.isEmpty()) {
- return null;
- }
-
- Set<SingleResource> childs;
- childs = dev.getSingleTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return singleResources;
- }
-
- if (childs.size() == singleResources.size()) {
- return null;
- }
-
- singleResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(singleResources, Utility.singleResourceComparator);
-
- return singleResources;
- }
-
- public List<CollectionResource> getCollectionTypeResourcesForAddingToCollectionResource(
- CollectionResource colRes) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- // Remove the colRes from the list
- collectionResources.remove(colRes);
-
- Set<CollectionResource> childs;
- childs = colRes.getCollectionTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return collectionResources;
- }
-
- if (childs.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<CollectionResource> getCollectionTypeResourcesForAddingToDevice(
- Device dev) {
- List<CollectionResource> collectionResources = data
- .getCollectionResources();
- if (null == collectionResources || collectionResources.isEmpty()) {
- return null;
- }
-
- Set<CollectionResource> childs;
- childs = dev.getCollectionTypeChildResources();
- if (null == childs || childs.isEmpty()) {
- return collectionResources;
- }
-
- if (childs.size() == collectionResources.size()) {
- return null;
- }
-
- collectionResources.removeAll(childs);
-
- // Sort the list
- Collections.sort(collectionResources,
- Utility.collectionResourceComparator);
-
- return collectionResources;
- }
-
- public List<Device> getDevicesForAddingToResource(Resource resource) {
- List<Device> devices = data.getDevices();
- if (null == devices || devices.isEmpty()) {
- return null;
- }
-
- Set<Device> deviceMembership;
- if (resource instanceof SingleResource) {
- deviceMembership = ((SingleResource) resource)
- .getDeviceMembership();
- } else {
- deviceMembership = ((CollectionResource) resource)
- .getDeviceMembership();
- }
- if (null == deviceMembership || deviceMembership.isEmpty()) {
- return devices;
- }
-
- if (devices.size() == deviceMembership.size()) {
- return null;
- }
-
- devices.removeAll(deviceMembership);
-
- // Sort the list
- Collections.sort(devices, Utility.deviceComparator);
-
- return devices;
- }
-
- public List<CollectionResource> getResourceReferences(
- SingleResource resource) {
- List<CollectionResource> resources = Utility
- .getCollectionResourceListFromSet(resource
- .getCollectionMembership());
- if (null == resources || resources.isEmpty()) {
- return null;
- }
-
- Collections.sort(resources, Utility.collectionResourceComparator);
-
- return resources;
- }
-
- public List<Device> getDeviceReferences(Resource resource) {
- Set<Device> deviceMembership;
- if (resource instanceof SingleResource) {
- deviceMembership = ((SingleResource) resource)
- .getDeviceMembership();
- } else {
- deviceMembership = ((CollectionResource) resource)
- .getDeviceMembership();
- }
-
- List<Device> devices = Utility.getDeviceListFromSet(deviceMembership);
- if (null == devices || devices.isEmpty()) {
- return null;
- }
-
- Collections.sort(devices, Utility.deviceComparator);
-
- return devices;
- }
-
- public List<SingleResource> getSingleTypeChilds(CollectionResource colRes) {
- Set<SingleResource> childs = colRes.getSingleTypeChildResources();
- return Utility.getSingleResourceListFromSet(childs);
- }
-
- public List<SingleResource> getSingleTypeChilds(Device dev) {
- Set<SingleResource> childs = dev.getSingleTypeChildResources();
- return Utility.getSingleResourceListFromSet(childs);
- }
-
- public List<CollectionResource> getCollectionTypeChilds(
- CollectionResource colRes) {
- Set<CollectionResource> childs = colRes
- .getCollectionTypeChildResources();
- return Utility.getCollectionResourceListFromSet(childs);
- }
-
- public List<CollectionResource> getCollectionTypeChilds(Device dev) {
- Set<CollectionResource> childs = dev.getCollectionTypeChildResources();
- return Utility.getCollectionResourceListFromSet(childs);
- }
-
public void resourceSelectionChanged(final Resource selectedResource) {
new Thread() {
@Override
public void run() {
-
- setCurrentDeviceInSelection(null);
-
if (null != selectedResource) {
setCurrentResourceInSelection(selectedResource);
} else {
}.start();
}
- public void deviceSelectionChanged(final Device selectedDevice) {
- new Thread() {
- @Override
- public void run() {
-
- setCurrentResourceInSelection(null);
-
- if (null != selectedDevice) {
- setCurrentDeviceInSelection(selectedDevice);
- } else {
- setCurrentDeviceInSelection(null);
- }
- // Notify all observers for resource selection change event
- UiListenerHandler.getInstance()
- .deviceSelectionChangedUINotification(selectedDevice);
- }
- }.start();
- }
-
public List<MetaProperty> getMetaProperties(Resource resource) {
if (null != resource) {
String propName;
} else if (propName.equals(Constants.RESOURCE_URI)) {
propValue = resource.getResourceURI();
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- Set<String> resTypes = resource.getResourceTypes();
- if (null != resTypes && !resTypes.isEmpty()) {
- propValue = "";
- Iterator<String> itr = resTypes.iterator();
- while (itr.hasNext()) {
- propValue += itr.next();
- if (itr.hasNext()) {
- propValue += ", ";
- }
- }
- } else {
- propValue = null;
- }
+ propValue = resource.getResourceType();
} else {
propValue = null;
}
return null;
}
- public List<MetaProperty> getMetaProperties(Device dev) {
- if (null != dev) {
- List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
- metaPropertyList.add(new MetaProperty(Constants.DEVICE_NAME, dev
- .getDeviceName()));
- return metaPropertyList;
- }
- return null;
- }
-
public boolean startResource(Resource resource) throws SimulatorException {
if (null == resource) {
return false;
return true;
}
- public boolean changeDeviceName(Device dev, String newName) {
- if (null == dev || null == newName) {
- return false;
- }
- data.changeDeviceName(dev, dev.getDeviceName(), newName);
- return true;
- }
-
public boolean changeResourceURI(Resource resource, String newURI)
throws SimulatorException {
if (null == resource || null == newURI) {
return true;
}
- public boolean updateDeviceProperties(Device dev,
- List<MetaProperty> properties) {
- if (null == dev || null == properties) {
- return false;
- }
-
- // Updating the properties
- Iterator<MetaProperty> itr = properties.iterator();
- MetaProperty property;
- String propName;
- String propValue;
- String devName = null;
- while (itr.hasNext()) {
- property = itr.next();
- if (null == property) {
- continue;
- }
- propName = property.getPropName();
- propValue = property.getPropValue();
- if (propName.equals(Constants.DEVICE_NAME)) {
- devName = propValue;
- }
- }
-
- if (!changeDeviceName(dev, devName)) {
- return false;
- }
-
- // Notify UI Listeners
- UiListenerHandler.getInstance().propertiesChangedUINotification(
- Device.class);
-
- return true;
- }
-
public boolean attributeValueUpdated(SingleResource resource,
String attributeName, AttributeValue value) {
if (null != resource && null != attributeName && null != value) {
return false;
}
- // TODO: This method should get the status from the native layer.
public boolean isResourceStarted(Resource resource) {
if (null == resource) {
return false;
return invalid;
}
- public boolean isPropertyValueInvalid(Device dev,
- List<MetaProperty> properties, String propName) {
- if (null == dev || null == properties || null == propName) {
- return false;
- }
- boolean invalid = false;
- MetaProperty prop;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(propName)) {
- String value = prop.getPropValue();
- if (null == value || value.trim().isEmpty()) {
- invalid = true;
- }
- }
- }
- return invalid;
- }
-
public boolean isPropValueChanged(Resource resource,
List<MetaProperty> properties, String propName) {
if (null == resource || null == properties || null == propName) {
return changed;
}
- public boolean isPropValueChanged(Device dev,
- List<MetaProperty> properties, String propName) {
- if (null == dev || null == properties || null == propName) {
- return false;
- }
- boolean changed = false;
- MetaProperty prop;
- String oldValue;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(propName)) {
- oldValue = dev.getDeviceName();
- if (null != oldValue && !prop.getPropValue().equals(oldValue)) {
- changed = true;
- }
- break;
- }
- }
- return changed;
- }
-
private String getPropertyValueFromResource(Resource resource,
String propName) {
if (null == resource || null == propName) {
} else if (propName.equals(Constants.RESOURCE_NAME)) {
return resource.getResourceName();
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- return resource.getResourceTypes().toString();
+ return resource.getResourceType();
} else {
return null;
}
}
- public boolean isURIChanged(Resource resource, List<MetaProperty> properties) {
- if (null == resource || null == properties) {
- return false;
- }
- boolean changed = false;
- MetaProperty prop;
- Iterator<MetaProperty> itr = properties.iterator();
- while (itr.hasNext()) {
- prop = itr.next();
- if (prop.getPropName().equals(Constants.RESOURCE_URI)) {
- if (!prop.getPropValue().equals(resource.getResourceURI())) {
- changed = true;
- }
- break;
- }
- }
- return changed;
- }
-
- public boolean startResource(SingleResource resource) {
- if (null == resource || resource.isStarted()) {
- return false;
- }
- boolean result;
- SimulatorResource server = resource.getSimulatorResource();
- if (null == server) {
- result = false;
- } else {
- try {
- server.start();
- resource.setStarted(true);
- result = true;
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- result = false;
- }
- }
- return result;
- }
-
- public boolean stopResource(SingleResource resource) {
- if (null == resource || !resource.isStarted()) {
- return false;
- }
- boolean result;
- SimulatorResource server = resource.getSimulatorResource();
- if (null == server) {
- result = false;
- } else {
- try {
- server.stop();
- resource.setStarted(false);
- result = true;
- } catch (SimulatorException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- Utility.getSimulatorErrorString(e, null));
- result = false;
- }
- }
- return result;
- }
-
public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) {
if (null == att) {
return false;
}
}
- public void shutdown() {
- threadHandle.interrupt();
- }
-
public List<String> getAllValuesOfAttribute(SimulatorResourceAttribute att) {
if (null == att) {
return null;
public int getResourceCount() {
return data.getResourceCount();
}
+
+ public void shutdown() {
+ threadHandle.interrupt();
+ }
}
\ No newline at end of file
import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
import oic.simulator.serviceprovider.model.SingleResource;
}
}
- public void deviceSelectionChangedUINotification(Device dev) {
- synchronized (selectionChangedUIListeners) {
- if (selectionChangedUIListeners.size() > 0) {
- ISelectionChangedListener listener;
- Iterator<ISelectionChangedListener> listenerItr = selectionChangedUIListeners
- .iterator();
- while (listenerItr.hasNext()) {
- listener = listenerItr.next();
- if (null != listener) {
- listener.onDeviceSelectionChange(dev);
- }
- }
- }
- }
- }
-
public void attributeUpdatedUINotification(AttributeElement attribute) {
synchronized (dataChangeListeners) {
if (dataChangeListeners.size() > 0 && null != attribute) {
if (null != listener) {
if (targetClass == Resource.class) {
listener.onResourcePropertyChange();
- } else {
- listener.onDevicePropertyChange();
}
}
}
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.model;
import java.util.HashMap;
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.model;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.oic.simulator.SimulatorException;
-import org.oic.simulator.server.SimulatorCollectionResource;
-import org.oic.simulator.server.SimulatorResource;
-
-public class CollectionResource extends Resource {
- private Set<Resource> childResources;
- private Set<String> supportedResourceTypes;
-
- private Set<CollectionResource> membership;
-
- public CollectionResource() {
- childResources = new HashSet<Resource>();
- supportedResourceTypes = new HashSet<String>();
- membership = new HashSet<CollectionResource>();
- setDeviceMembership(new HashSet<Device>());
- }
-
- public Set<String> getSupportedResourceTypes() {
- return supportedResourceTypes;
- }
-
- public void setSupportedResourceTypes(Set<String> supportedResourceTypes) {
- this.supportedResourceTypes = supportedResourceTypes;
- }
-
- public void addSupportedResourceType(String rType) {
- if (null == supportedResourceTypes) {
- supportedResourceTypes = new HashSet<String>();
- }
- supportedResourceTypes.add(rType);
- }
-
- public void removeSupportedResourceType(String rType) {
- if (null != supportedResourceTypes) {
- supportedResourceTypes.remove(rType);
- }
- }
-
- public Set<Resource> getChildResources() {
- return childResources;
- }
-
- public Set<SingleResource> getSingleTypeChildResources() {
- if (null == childResources || childResources.isEmpty()) {
- return null;
- }
- Set<SingleResource> resultSet = new HashSet<SingleResource>();
- Iterator<Resource> itr = childResources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (null != res) {
- if (res instanceof SingleResource) {
- resultSet.add((SingleResource) res);
- }
- }
- }
- return resultSet;
- }
-
- public Set<CollectionResource> getCollectionTypeChildResources() {
- if (null == childResources || childResources.isEmpty()) {
- return null;
- }
- Set<CollectionResource> resultSet = new HashSet<CollectionResource>();
- Iterator<Resource> itr = childResources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (null != res) {
- if (res instanceof CollectionResource) {
- resultSet.add((CollectionResource) res);
- }
- }
- }
- return resultSet;
- }
-
- public void setChildResources(Set<Resource> childResources) {
- this.childResources = childResources;
- }
-
- public void addChildResource(Resource resource) throws SimulatorException {
- if (null == resource) {
- return;
- }
- if (null == childResources) {
- childResources = new HashSet<Resource>();
- }
-
- // Native call to add child resource
- SimulatorResource simRes;
- simRes = resource.getSimulatorResource();
- ((SimulatorCollectionResource) simulatorResource)
- .addChildResource(simRes);
-
- childResources.add(resource);
- }
-
- public void addChildResource(Set<Resource> resources)
- throws SimulatorException {
- if (null == resources || resources.isEmpty()) {
- return;
- }
- if (null == childResources) {
- childResources = new HashSet<Resource>();
- }
-
- // Native call to add child resource
- SimulatorResource simRes;
- Resource res;
- Iterator<Resource> itr = resources.iterator();
- while (itr.hasNext()) {
- res = itr.next();
- simRes = res.getSimulatorResource();
- ((SimulatorCollectionResource) simulatorResource)
- .addChildResource(simRes);
-
- childResources.add(res);
- }
- }
-
- public void removeChildResource(Resource resource)
- throws SimulatorException {
- if (null == resource || null == childResources) {
- return;
- }
-
- // Native call to add child resource
- SimulatorResource simRes;
- simRes = resource.getSimulatorResource();
- ((SimulatorCollectionResource) simulatorResource)
- .removeChildResource(simRes);
-
- childResources.remove(resource);
- }
-
- public void removeChildResource(Set<Resource> resources)
- throws SimulatorException {
- if (null == resources || null == childResources) {
- return;
- }
-
- // Native call to add child resource
- SimulatorResource simRes;
- Resource res;
- Iterator<Resource> itr = resources.iterator();
- while (itr.hasNext()) {
- res = itr.next();
- simRes = res.getSimulatorResource();
- ((SimulatorCollectionResource) simulatorResource)
- .removeChildResource(simRes);
-
- childResources.remove(res);
- }
- }
-
- public Set<CollectionResource> getMembership() {
- return membership;
- }
-
- public void setMembership(Set<CollectionResource> membership) {
- this.membership = membership;
- }
-
- public void addMembership(CollectionResource resource) {
- if (null == resource) {
- return;
- }
- if (null == membership) {
- membership = new HashSet<CollectionResource>();
- }
- membership.add(resource);
- }
-
- public void addMembership(Set<CollectionResource> resources) {
- if (null == resources) {
- return;
- }
- if (null == membership) {
- membership = new HashSet<CollectionResource>();
- }
- membership.addAll(resources);
- }
-
- public void removeMembership(CollectionResource resource) {
- if (null == resource || null == membership) {
- return;
- }
- membership.remove(resource);
- }
-
- public void removeMembership(Set<CollectionResource> collections) {
- if (null == collections || null == membership) {
- return;
- }
- membership.removeAll(collections);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.model;
-
-/**
- * Enumerates different types of supported delete operations.
- */
-public enum DeleteCategory {
- ALL, BY_TYPE, BY_URI, NONE
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.model;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class Device {
- private String deviceName;
-
- private Set<Resource> childResources;
-
- public Device() {
- childResources = new HashSet<Resource>();
- }
-
- public String getDeviceName() {
- return deviceName;
- }
-
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
- }
-
- public Set<Resource> getChildResources() {
- return childResources;
- }
-
- public void setChildResources(Set<Resource> childResources) {
- this.childResources = childResources;
- }
-
- public void addChildResource(Resource resource) {
- if (null == resource) {
- return;
- }
- if (null == childResources) {
- childResources = new HashSet<Resource>();
- }
- childResources.add(resource);
- }
-
- public void addChildResource(Set<Resource> resources) {
- if (null == resources) {
- return;
- }
- if (null == childResources) {
- childResources = new HashSet<Resource>();
- }
- childResources.addAll(resources);
- }
-
- public void removeChildResource(Resource resource) {
- if (null == resource || null == childResources) {
- return;
- }
- childResources.remove(resource);
- }
-
- public void removeChildResource(Set<Resource> resources) {
- if (null == resources || null == childResources) {
- return;
- }
- childResources.removeAll(resources);
- }
-
- public Set<SingleResource> getSingleTypeChildResources() {
- if (null == childResources || childResources.isEmpty()) {
- return null;
- }
- Set<SingleResource> resultSet = new HashSet<SingleResource>();
- Iterator<Resource> itr = childResources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (null != res) {
- if (res instanceof SingleResource) {
- resultSet.add((SingleResource) res);
- }
- }
- }
- return resultSet;
- }
-
- public Set<CollectionResource> getCollectionTypeChildResources() {
- if (null == childResources || childResources.isEmpty()) {
- return null;
- }
- Set<CollectionResource> resultSet = new HashSet<CollectionResource>();
- Iterator<Resource> itr = childResources.iterator();
- Resource res;
- while (itr.hasNext()) {
- res = itr.next();
- if (null != res) {
- if (res instanceof CollectionResource) {
- resultSet.add((CollectionResource) res);
- }
- }
- }
- return resultSet;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.model;
-
-/**
- * Enumerates the different types of operations for model change notifications.
- */
-public enum ModelChangeNotificationType {
- ATTRIBUTE_ADDED, ATTRIBUTE_REMOVED, ATTRIBUTE_VALUE_CHANGED, NONE, NO_ATTRIBUTES_IN_MODEL
-}
\ No newline at end of file
private String resourceURI;
private String resourceName;
- private Set<String> resourceTypes;
+ private String resourceType;
private Set<String> resourceInterfaces;
private boolean started;
private boolean observable;
- private Set<Device> deviceMembership;
-
private Map<Integer, ObserverDetail> observers;
public Resource() {
- resourceTypes = new HashSet<String>();
resourceInterfaces = new HashSet<String>();
observers = new HashMap<Integer, ObserverDetail>();
}
this.resourceName = resourceName;
}
- public Set<String> getResourceTypes() {
- return resourceTypes;
+ public String getResourceType() {
+ return resourceType;
}
- public void setResourceTypes(Set<String> resourceTypes) {
- this.resourceTypes = resourceTypes;
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
}
public Set<String> getResourceInterfaces() {
- return resourceInterfaces;
+ if (null != resourceInterfaces) {
+ return new HashSet<String>(resourceInterfaces);
+ }
+ return null;
}
public void setResourceInterfaces(Set<String> resourceInterfaces) {
this.observable = observable;
}
- public void addResourceType(String resType) {
- if (null == resType) {
- return;
- }
- if (null == resourceTypes) {
- resourceTypes = new HashSet<String>();
- }
- resourceTypes.add(resType);
- }
-
- public void removeResourceType(String resType) {
- if (null == resType || null == resourceTypes) {
- return;
- }
- resourceTypes.remove(resType);
- }
-
- public boolean isResourceTypeExist(String resType) {
- if (null == resType || null == resourceTypes) {
- return false;
- }
- return resourceTypes.contains(resType);
- }
-
public void addInterfaceType(String ifType) {
if (null == ifType) {
return;
observers.remove(observer.getId());
}
- public Set<Device> getDeviceMembership() {
- return deviceMembership;
- }
-
- public void setDeviceMembership(Set<Device> deviceMembership) {
- this.deviceMembership = deviceMembership;
- }
-
- public void addDeviceMembership(Device dev) {
- if (null == dev) {
- return;
- }
- if (null == deviceMembership) {
- deviceMembership = new HashSet<Device>();
- }
- deviceMembership.add(dev);
- }
-
- public void addDeviceMembership(Set<Device> devices) {
- if (null == devices) {
- return;
- }
- if (null == deviceMembership) {
- deviceMembership = new HashSet<Device>();
- }
- deviceMembership.addAll(devices);
- }
-
- public void removeDeviceMembership(Device dev) {
- if (null == dev || null == deviceMembership) {
- return;
- }
- deviceMembership.remove(dev);
- }
-
- public void removeDeviceMembership(Set<Device> devices) {
- if (null == devices || null == deviceMembership) {
- return;
- }
- deviceMembership.removeAll(devices);
- }
-
- public boolean isMemberOfAnyDevice() {
- if (null == deviceMembership || deviceMembership.isEmpty()) {
- return false;
- }
- return true;
- }
-
public void setResourceRepresentation(SimulatorResourceModel resModel)
throws NullPointerException {
if (mResourceRepresentation == null)
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.model;
-
-public enum ResourceCategory {
- SIMPLE, COLLECTION
-}
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.model;
import java.util.HashMap;
package oic.simulator.serviceprovider.model;
public enum ResourceType {
- SINGLE, COLLECTION, DEVICE
+ SINGLE
}
package oic.simulator.serviceprovider.model;
-import java.util.HashSet;
-import java.util.Set;
-
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
/**
* information about the resource.
*/
public class SingleResource extends Resource {
- private Set<CollectionResource> collectionMembership;
-
- private boolean getAllowed;
-
- private boolean putAllowed;
-
- private boolean postAllowed;
-
- private int automationId;
-
- private boolean resourceAutomationInProgress;
-
- private boolean attributeAutomationInProgress;
-
- private int automationUpdateInterval;
-
- private AutoUpdateType automationType;
+ private boolean getAllowed;
- public SingleResource() {
- setCollectionMembership(new HashSet<CollectionResource>());
- }
+ private boolean putAllowed;
- public Set<CollectionResource> getCollectionMembership() {
- return collectionMembership;
- }
+ private boolean postAllowed;
- public void setCollectionMembership(
- Set<CollectionResource> collectionMembership) {
- this.collectionMembership = collectionMembership;
- }
+ private int automationId;
- public void addCollectionMembership(CollectionResource resource) {
- if (null == resource) {
- return;
- }
- if (null == collectionMembership) {
- collectionMembership = new HashSet<CollectionResource>();
- }
- collectionMembership.add(resource);
- }
+ private boolean resourceAutomationInProgress;
- public void addCollectionMembership(Set<CollectionResource> resources) {
- if (null == resources) {
- return;
- }
- if (null == collectionMembership) {
- collectionMembership = new HashSet<CollectionResource>();
- }
- collectionMembership.addAll(resources);
- }
+ private boolean attributeAutomationInProgress;
- public void removeCollectionMembership(CollectionResource resource) {
- if (null == resource || null == collectionMembership) {
- return;
- }
- collectionMembership.remove(resource);
- }
-
- public void removeCollectionMembership(Set<CollectionResource> collections) {
- if (null == collections || null == collectionMembership) {
- return;
- }
- collectionMembership.removeAll(collections);
- }
+ private int automationUpdateInterval;
- public boolean isMemberOfAnyCollection() {
- if (null == collectionMembership || collectionMembership.isEmpty()) {
- return false;
- }
- return true;
- }
+ private AutoUpdateType automationType;
public boolean isGetAllowed() {
return getAllowed;
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.utils;
import java.util.Map;
*/
public class Constants {
- public static final String INT = "Int";
- public static final String DOUBLE = "Double";
- public static final String BOOL = "Boolean";
- public static final String STRING = "String";
- public static final String UNKNOWN = "Unknown";
+ public static final String INT = "Int";
+ public static final String DOUBLE = "Double";
+ public static final String BOOL = "Boolean";
+ public static final String STRING = "String";
+ public static final String UNKNOWN = "Unknown";
- public static final String CONFIG_DIRECTORY_PATH = "/resource";
+ public static final String CONFIG_DIRECTORY_PATH = "/resource";
- public static final String UNDERSCORE = "_";
- public static final String FORWARD_SLASH = "/";
+ public static final String UNDERSCORE = "_";
+ public static final String FORWARD_SLASH = "/";
- public static final String OIC_PREFIX = "/oic/r";
- public static final String SIMULATOR = "simulator";
+ public static final String OIC_PREFIX = "/oic/r";
+ public static final String SIMULATOR = "simulator";
- public static final String RESOURCE_URI = "Resource URI";
- public static final String RESOURCE_TYPE = "Resource Type";
- public static final String RESOURCE_TYPES = "Resource Types";
- public static final String RESOURCE_NAME = "Resource Name";
- public static final String RESOURCE_UID = "Resource ID";
- public static final String CONNECTIVITY_TYPE = "Connectivity Type";
+ public static final String RESOURCE_URI = "Resource URI";
+ public static final String RESOURCE_TYPE = "Resource Type";
+ public static final String RESOURCE_TYPES = "Resource Types";
+ public static final String RESOURCE_NAME = "Resource Name";
+ public static final String RESOURCE_UID = "Resource ID";
+ public static final String CONNECTIVITY_TYPE = "Connectivity Type";
+ public static final String INTERFACE_TYPES = "Interface Types";
- public static final String[] META_PROPERTIES = {
- RESOURCE_NAME, RESOURCE_URI, RESOURCE_TYPE };
+ public static final String[] META_PROPERTIES = {
+ RESOURCE_NAME, RESOURCE_URI, RESOURCE_TYPE, INTERFACE_TYPES };
- public static final int META_PROPERTY_COUNT = META_PROPERTIES.length;
+ public static final int META_PROPERTY_COUNT = META_PROPERTIES.length;
- public static final String ENABLE = "Enable";
- public static final String DISABLE = "Disable";
- public static final String ENABLED = "Enabled";
- public static final String DISABLED = "Disabled";
+ public static final String ENABLE = "Enable";
+ public static final String DISABLE = "Disable";
+ public static final String ENABLED = "Enabled";
+ public static final String DISABLED = "Disabled";
- public static final String AUTOMATION = "Automation";
- public static final String AUTOMATION_TYPE = "Automation Type";
- public static final String UPDATE_INTERVAL_IN_MS = "Update Interval(ms)";
+ public static final String AUTOMATION = "Automation";
+ public static final String AUTOMATION_TYPE = "Automation Type";
+ public static final String UPDATE_INTERVAL_IN_MS = "Update Interval(ms)";
- public static final String[] AUTOMATION_SETTINGS = {
- AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS };
+ public static final String[] AUTOMATION_SETTINGS = {
+ AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS };
- public static final int AUTOMATION_SETTINGS_COUNT = AUTOMATION_SETTINGS.length;
+ public static final int AUTOMATION_SETTINGS_COUNT = AUTOMATION_SETTINGS.length;
- public static final String START_RESOURCE_AUTOMATION = "Start Automation";
- public static final String STOP_RESOURCE_AUTOMATION = "Stop Automation";
+ public static final String START_RESOURCE_AUTOMATION = "Start Automation";
+ public static final String STOP_RESOURCE_AUTOMATION = "Stop Automation";
- public static final int DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2;
+ public static final int DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2;
- public static final AutoUpdateType DEFAULT_AUTOMATION_TYPE = AutoUpdateType.ONE_TIME;
+ public static final AutoUpdateType DEFAULT_AUTOMATION_TYPE = AutoUpdateType.ONE_TIME;
- public static final int DEFAULT_AUTOMATION_INTERVAL = 500;
+ public static final int DEFAULT_AUTOMATION_INTERVAL = 500;
- public static final int PROPER_LOG_TIME_TOKEN_LENGTH = 3;
+ public static final int PROPER_LOG_TIME_TOKEN_LENGTH = 3;
- public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" };
- public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] {
- "*.log", "*" };
+ public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" };
+ public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] {
+ "*.log", "*" };
- public static final int LOG_SIZE = 1000;
+ public static final int LOG_SIZE = 1000;
- public static final String INFO_LOG = "info_log";
- public static final String WARNING_LOG = "warning_log";
- public static final String ERROR_LOG = "error_log";
- public static final String DEBUG_LOG = "debug_log";
- public static final String UNKNOWN_LOG = "unknown_log";
+ public static final String INFO_LOG = "info_log";
+ public static final String WARNING_LOG = "warning_log";
+ public static final String ERROR_LOG = "error_log";
+ public static final String DEBUG_LOG = "debug_log";
+ public static final String UNKNOWN_LOG = "unknown_log";
- public static final String INFO = "Info";
- public static final String WARNING = "Warning";
- public static final String ERROR = "Error";
- public static final String DEBUG = "Debug";
+ public static final String INFO = "Info";
+ public static final String WARNING = "Warning";
+ public static final String ERROR = "Error";
+ public static final String DEBUG = "Debug";
- public static final String CHECKED = "Checked";
- public static final String UNCHECKED = "Unchecked";
- public static final String NOTIFY_BUTTON_SELECTED = "Notify_Selected";
- public static final String NOTIFY_BUTTON_UNSELECTED = "Notify_Unselected";
+ public static final String CHECKED = "Checked";
+ public static final String UNCHECKED = "Unchecked";
+ public static final String NOTIFY_BUTTON_SELECTED = "Notify_Selected";
+ public static final String NOTIFY_BUTTON_UNSELECTED = "Notify_Unselected";
- public static final String CREATE_PAGE_TITLE = "Create Resource";
- public static final String CREATE_PAGE_MESSAGE = "Create a resource from RAML file";
+ public static final String CREATE_PAGE_TITLE = "Create Resource";
+ public static final String CREATE_PAGE_MESSAGE = "Create a resource from RAML file";
- public static final String DELETE_PAGE_TITLE = "Delete Resource";
- public static final String DELETE_PAGE_MESSAGE = "Select the resource(s) to be deleted";
+ public static final String DELETE_PAGE_TITLE = "Delete Resource";
+ public static final String DELETE_PAGE_MESSAGE = "Select the resource(s) to be deleted";
- public static final String RAML_FILE_PREFIX = "/resource/";
+ public static final String RAML_FILE_PREFIX = "/resource/";
- public static final String RAML_FILE_EXTENSION = ".raml";
- public static final String JSON_FILE_EXTENSION = ".json";
+ public static final String RAML_FILE_EXTENSION = ".raml";
+ public static final String JSON_FILE_EXTENSION = ".json";
- public static final String SPLIT_BY_DOT_PATTERN = "\\.";
+ public static final String SPLIT_BY_DOT_PATTERN = "\\.";
// Platform information
- public static final String PLATFORM_ID = "Id";
- public static final String PLATFORM_MANUFAC_NAME = "Manufacturer Name";
- public static final String PLATFORM_MANUFAC_URL = "Manufacturer URL";
- public static final String PLATFORM_MODEL_NO = "Model Number";
- public static final String PLATFORM_DATE_OF_MANUFAC = "Date of Manufacture";
- public static final String PLATFORM_VERSION = "Version";
- public static final String PLATFORM_OS_VERSION = "OS Version";
- public static final String PLATFORM_HARDWARE_VERSION = "HardWare Version";
- public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version";
- public static final String PLATFORM_SUPPORT_URL = "Support URL";
- public static final String PLATFORM_SYSTEM_TIME = "System Time";
+ public static final String PLATFORM_ID = "Id";
+ public static final String PLATFORM_MANUFAC_NAME = "Manufacturer Name";
+ public static final String PLATFORM_MANUFAC_URL = "Manufacturer URL";
+ public static final String PLATFORM_MODEL_NO = "Model Number";
+ public static final String PLATFORM_DATE_OF_MANUFAC = "Date of Manufacture";
+ public static final String PLATFORM_VERSION = "Version";
+ public static final String PLATFORM_OS_VERSION = "OS Version";
+ public static final String PLATFORM_HARDWARE_VERSION = "HardWare Version";
+ public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version";
+ public static final String PLATFORM_SUPPORT_URL = "Support URL";
+ public static final String PLATFORM_SYSTEM_TIME = "System Time";
// Device information
- public static final String DEVICE_NAME = "Device Name";
- public static final String DEVICE_ID = "Device ID";
- public static final String DEVICE_SPEC_VERSION = "Spec Version";
- public static final String DEVICE_DMV = "Data Model Version";
+ public static final String DEVICE_NAME = "Device Name";
+ public static final String DEVICE_ID = "Device ID";
+ public static final String DEVICE_SPEC_VERSION = "Spec Version";
+ public static final String DEVICE_DMV = "Data Model Version";
- public static final String SAMPLE_LIGHT = "sample.light";
+ public static final String SAMPLE_LIGHT = "sample.light";
- public static final String UPDATE_PROP_PAGE_TITLE = "Update Properties";
- public static final String UPDATE_PROP_PAGE_MESSAGE = "Update the default values of resource properties";
+ public static final String UPDATE_PROP_PAGE_TITLE = "Update Properties";
+ public static final String UPDATE_PROP_PAGE_MESSAGE = "Update the default values of resource properties";
- public static final String START_STOP_PAGE_TITLE = "Start/Stop Resource";
- public static final String START_STOP_PAGE_MESSAGE = "This page allows to start or stop the created resource(s)";
+ public static final String START_STOP_PAGE_TITLE = "Start/Stop Resource";
+ public static final String START_STOP_PAGE_MESSAGE = "This page allows to start or stop the created resource(s)";
- public static final String START_RESOURCE = "Start Resource";
- public static final String STOP_RESOURCE = "Stop Resource";
+ public static final String START_RESOURCE = "Start Resource";
+ public static final String STOP_RESOURCE = "Stop Resource";
- public static final String DELETE_RESOURCE = "Delete Resource";
+ public static final String DELETE_RESOURCE = "Delete Resource";
- public static final String MAIN_PAGE_TITLE = "Create Resource";
- public static final String MAIN_PAGE_MESSAGE = "Simple resource or Collection resource";
+ public static final String MAIN_PAGE_TITLE = "Create Resource";
+ public static final String MAIN_PAGE_MESSAGE = "Create a Simple resource";
- public static final String SIMPLE_PAGE_TITLE = "Create Simple Resource";
- public static final String SIMPLE_PAGE_MESSAGE = "Either manually or from RAML file";
+ public static final String SIMPLE_PAGE_TITLE = "Create Simple Resource";
+ public static final String SIMPLE_PAGE_MESSAGE = "Either manually or from RAML file";
- public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 1 of 3)";
- public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource";
+ public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 1 of 3)";
+ public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource";
- public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE = "Create Simple Resource(Step 2 of 3)";
- public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE = "Add attributes to the resource";
+ public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE = "Create Simple Resource(Step 2 of 3)";
+ public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE = "Add attributes to the resource";
- public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 3 of 3)";
- public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE = "Fill other details of the resource";
+ public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 3 of 3)";
+ public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE = "Fill other details of the resource";
- public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Collection Resource";
- public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource";
+ public static final String SINGLE_RESOURCE = "Single Resource";
+ public static final String INVALID_URI_MESSAGE = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'.";
+ public static final int TREE_EXPANSION_LEVEL = 10;
- public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE = "Create Collection Resource";
- public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE = "Add other resources to this collection resource";
+ public static final String BASELINE_INTERFACE = "oic.if.baseline";
+ public static final String LINKS_LIST_INTERFACE = "oic.if.ll";
+ public static final String BATCH_INTERFACE = "oic.if.b";
+ public static final String LINK_BATCH_INTERFACE = "oic.if.lb";
+ public static final String READ_ONLY_INTERFACE = "oic.if.r";
+ public static final String READ_WRITE_INTERFACE = "oic.if.rw";
+ public static final String ACTUATOR_INTERFACE = "oic.if.a";
+ public static final String SENSOR_INTERFACE = "oic.if.s";
- public static final String CREATE_DEVICE_PAGE_TITLE = "Create Device";
- public static final String CREATE_DEVICE_PAGE_MESSAGE = "Create a logical device which holds a group of resources";
+ public static final String DEFAULT_SINGLE_RESOURCE_INTERFACE = "oic.if.baseline";
- public static final String DEVICE = "Create Device";
- public static final String SINGLE_RESOURCE = "Single Resource";
- public static final String COLLECTION_RESOURCE = "Collection Resource";
- public static final String INVALID_URI_MESSAGE = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'.";
- public static final int TREE_EXPANSION_LEVEL = 10;
+ public static final int MAX_RESOURCE_COUNT = 200;
- public static final int MAX_RESOURCE_COUNT = 200;
}
\ No newline at end of file
import java.util.Comparator;
import java.util.Date;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.Vector;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
*/
public class Utility {
- public static String fileNameToDisplay(String fileName) {
- if (null == fileName || fileName.length() < 1) {
- return null;
- }
- // Remove the RAML file standard prefix
- int len = Constants.RAML_FILE_PREFIX.length();
- if (len > 0) {
- if (fileName.startsWith(Constants.RAML_FILE_PREFIX)) {
- fileName = fileName.substring(len);
- }
- }
-
- // Removing the file extension
- int index = fileName.lastIndexOf('.');
- fileName = fileName.substring(0, index);
- return fileName;
- }
-
- public static String displayToFileName(String displayName) {
- if (null == displayName || displayName.length() < 1) {
- return null;
- }
- String fileName;
- // Adding the prefix
- fileName = Constants.RAML_FILE_PREFIX + displayName;
-
- // Adding the file extension
- fileName = fileName + Constants.RAML_FILE_EXTENSION;
-
- return fileName;
- }
-
public static String getAutomationStatus(boolean status) {
if (status) {
return Constants.ENABLED;
return list;
}
- public static List<CollectionResource> getCollectionResourceListFromSet(
- Set<CollectionResource> resources) {
- if (null == resources) {
- return null;
- }
- List<CollectionResource> list = new ArrayList<CollectionResource>();
- Iterator<CollectionResource> typeItr = resources.iterator();
- while (typeItr.hasNext()) {
- list.add(typeItr.next());
- }
- return list;
- }
-
- public static List<Device> getDeviceListFromSet(Set<Device> devices) {
- if (null == devices) {
- return null;
- }
- List<Device> list = new ArrayList<Device>();
- Iterator<Device> typeItr = devices.iterator();
- while (typeItr.hasNext()) {
- list.add(typeItr.next());
- }
- return list;
- }
-
public static Set<String> convertVectorToSet(Vector<String> vector) {
if (null == vector || vector.isEmpty()) {
return null;
}
public static Vector<String> convertSetToVectorString(
- Set<Object> allowedValues) {
+ Set<String> allowedValues) {
if (null == allowedValues || allowedValues.size() < 1) {
return null;
}
Vector<String> resultVec = new Vector<String>();
- Iterator<Object> itr = allowedValues.iterator();
+ Iterator<String> itr = allowedValues.iterator();
try {
while (itr.hasNext()) {
resultVec.add((String) itr.next());
return resultSet;
}
- public static List<Resource> convertCollectionTypeResourceListToBaseType(
- List<CollectionResource> resources) {
- if (null == resources || resources.isEmpty()) {
- return null;
- }
- List<Resource> resultSet = new ArrayList<Resource>();
- Iterator<CollectionResource> itr = resources.iterator();
- while (itr.hasNext()) {
- resultSet.add(itr.next());
- }
- return resultSet;
- }
-
- public static Comparator<Resource> resourceComparator = new Comparator<Resource>() {
- public int compare(
- Resource res1,
- Resource res2) {
- String s1 = res1
- .getResourceName();
- String s2 = res2
- .getResourceName();
-
- String s1Part = s1
- .replaceAll(
- "\\d",
- "");
- String s2Part = s2
- .replaceAll(
- "\\d",
- "");
-
- if (s1Part
- .equalsIgnoreCase(s2Part)) {
- return extractInt(s1)
- - extractInt(s2);
- }
- return s1
- .compareTo(s2);
- }
-
- int extractInt(
- String s) {
- String num = s
- .replaceAll(
- "\\D",
- "");
- // return
- // 0
- // if
- // no
- // digits
- // found
- return num
- .isEmpty() ? 0
- : Integer
- .parseInt(num);
- }
- };
-
- public static Comparator<SingleResource> singleResourceComparator = new Comparator<SingleResource>() {
- public int compare(
- SingleResource res1,
- SingleResource res2) {
- String s1 = res1
- .getResourceName();
- String s2 = res2
- .getResourceName();
-
- String s1Part = s1
- .replaceAll(
- "\\d",
- "");
- String s2Part = s2
- .replaceAll(
- "\\d",
- "");
-
- if (s1Part
- .equalsIgnoreCase(s2Part)) {
- return extractInt(s1)
- - extractInt(s2);
- }
- return s1
- .compareTo(s2);
- }
-
- int extractInt(
- String s) {
- String num = s
- .replaceAll(
- "\\D",
- "");
- // return
- // 0
- // if
- // no
- // digits
- // found
- return num
- .isEmpty() ? 0
- : Integer
- .parseInt(num);
- }
- };
-
- public static Comparator<CollectionResource> collectionResourceComparator = new Comparator<CollectionResource>() {
- public int compare(
- CollectionResource res1,
- CollectionResource res2) {
- String s1 = res1
- .getResourceName();
- String s2 = res2
- .getResourceName();
-
- String s1Part = s1
- .replaceAll(
- "\\d",
- "");
- String s2Part = s2
- .replaceAll(
- "\\d",
- "");
-
- if (s1Part
- .equalsIgnoreCase(s2Part)) {
- return extractInt(s1)
- - extractInt(s2);
- }
- return s1
- .compareTo(s2);
- }
-
- int extractInt(
- String s) {
- String num = s
- .replaceAll(
- "\\D",
- "");
- // return
- // 0
- // if
- // no
- // digits
- // found
- return num
- .isEmpty() ? 0
- : Integer
- .parseInt(num);
- }
- };
-
- public static Comparator<Device> deviceComparator = new Comparator<Device>() {
- public int compare(
- Device res1,
- Device res2) {
- String s1 = res1
- .getDeviceName();
- String s2 = res2
- .getDeviceName();
-
- String s1Part = s1
- .replaceAll(
- "\\d",
- "");
- String s2Part = s2
- .replaceAll(
- "\\d",
- "");
-
- if (s1Part
- .equalsIgnoreCase(s2Part)) {
- return extractInt(s1)
- - extractInt(s2);
- }
- return s1
- .compareTo(s2);
- }
-
- int extractInt(
- String s) {
- String num = s
- .replaceAll(
- "\\D",
- "");
- // return
- // 0
- // if
- // no
- // digits
- // found
- return num
- .isEmpty() ? 0
- : Integer
- .parseInt(num);
- }
- };
+ public static Comparator<Resource> resourceComparator = new Comparator<Resource>() {
+ public int compare(
+ Resource res1,
+ Resource res2) {
+ String s1 = res1
+ .getResourceName();
+ String s2 = res2
+ .getResourceName();
+
+ String s1Part = s1
+ .replaceAll(
+ "\\d",
+ "");
+ String s2Part = s2
+ .replaceAll(
+ "\\d",
+ "");
+
+ if (s1Part
+ .equalsIgnoreCase(s2Part)) {
+ return extractInt(s1)
+ - extractInt(s2);
+ }
+ return s1
+ .compareTo(s2);
+ }
+
+ int extractInt(
+ String s) {
+ String num = s
+ .replaceAll(
+ "\\D",
+ "");
+ // return
+ // 0
+ // if
+ // no
+ // digits
+ // found
+ return num
+ .isEmpty() ? 0
+ : Integer
+ .parseInt(num);
+ }
+ };
+
+ public static Comparator<SingleResource> singleResourceComparator = new Comparator<SingleResource>() {
+ public int compare(
+ SingleResource res1,
+ SingleResource res2) {
+ String s1 = res1
+ .getResourceName();
+ String s2 = res2
+ .getResourceName();
+
+ String s1Part = s1
+ .replaceAll(
+ "\\d",
+ "");
+ String s2Part = s2
+ .replaceAll(
+ "\\d",
+ "");
+
+ if (s1Part
+ .equalsIgnoreCase(s2Part)) {
+ return extractInt(s1)
+ - extractInt(s2);
+ }
+ return s1
+ .compareTo(s2);
+ }
+
+ int extractInt(
+ String s) {
+ String num = s
+ .replaceAll(
+ "\\D",
+ "");
+ // return
+ // 0
+ // if
+ // no
+ // digits
+ // found
+ return num
+ .isEmpty() ? 0
+ : Integer
+ .parseInt(num);
+ }
+ };
// This method only works for attributes whose values are of type int,
// double, bool, string and 1-D array of primitive types
return true;
}
+ public static Map<String, String> getResourceInterfaces(
+ Class<? extends Resource> resourceClass) {
+ Map<String, String> ifTypes = null;
+ if (resourceClass == SingleResource.class) {
+ ifTypes = new HashMap<String, String>();
+ ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline");
+ ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only");
+ ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write");
+ ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator");
+ ifTypes.put(Constants.SENSOR_INTERFACE, "Sensor");
+ }
+ return ifTypes;
+ }
+
}
\ No newline at end of file
package oic.simulator.serviceprovider.view;
+import java.util.Date;
import java.util.List;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.model.AttributeElement;
import oic.simulator.serviceprovider.model.AutomationSettingHelper;
-import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceRepresentation;
import oic.simulator.serviceprovider.model.SingleResource;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPartReference;
import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.ILogger.Level;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
public AttributeValueEditor(TreeViewer viewer) {
super(viewer);
this.viewer = viewer;
+
+ // Using the part listener to refresh the viewer on various part
+ // events.
+ // If combo list is open, then click events on other parts of the
+ // view or outside the combo should hide the editor.
+ // Refreshing the viewer hides the combo and other editors which are
+ // active.
+ IPartListener2 partListener;
+ partListener = new IPartListener2() {
+
+ @Override
+ public void partVisible(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partOpened(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partInputChanged(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partHidden(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partDeactivated(IWorkbenchPartReference partRef) {
+ String viewId = partRef.getId();
+ if (viewId.equals(AttributeView.VIEW_ID)) {
+ refreshViewer();
+ }
+ }
+
+ @Override
+ public void partClosed(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {
+ }
+
+ @Override
+ public void partActivated(IWorkbenchPartReference partRef) {
+ String viewId = partRef.getId();
+ if (viewId.equals(AttributeView.VIEW_ID)) {
+ refreshViewer();
+ }
+ }
+ };
+
+ try {
+ Activator.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .addPartListener(partListener);
+ } catch (NullPointerException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while configuring the listener for UI.\n"
+ + Utility.getSimulatorErrorString(e,
+ null));
+ }
+ }
+
+ public void refreshViewer() {
+ if (null == viewer)
+ return;
+
+ Tree tree = viewer.getTree();
+ if (null == tree || tree.isDisposed())
+ return;
+
+ viewer.refresh();
}
@Override
return null;
}
- // If selected resource is a collection, then editor support is not
+ // If selected resource is not a single resource, then editor
+ // support is not
// required.
- if (res instanceof CollectionResource) {
+ if (!(res instanceof SingleResource)) {
return null;
}
return null;
}
- if (resource instanceof CollectionResource) {
+ if (!(resource instanceof SingleResource)) {
return null;
}
if (((SingleResource) resource).isResourceAutomationInProgress()) {
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceRepresentation;
import oic.simulator.serviceprovider.model.SingleResource;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
}
});
}
-
- @Override
- public void onDeviceSelectionChange(Device dev) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- if (null != attViewer) {
- Tree tree = attViewer.getTree();
- if (null != tree && !tree.isDisposed()) {
- // tbl.deselectAll();
- tree.removeAll();
- tree.setLinesVisible(false);
- }
- }
- }
- });
- }
};
dataChangeListener = new IDataChangeListener() {
TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
attValue.setWidth(attTblColWidth[1]);
attValue.setText(attTblHeaders[1]);
+
TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
attValue);
attValueVwrCol.setEditingSupport(attributeEditor
automation);
automationVwrCol.setEditingSupport(attributeEditor
.createAutomationEditor(attViewer));
+
+ addColumnListeners();
+ }
+
+ private void addColumnListeners() {
+ TreeColumn[] columns = attViewer.getTree().getColumns();
+ for (TreeColumn column : columns) {
+ column.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // Refreshing the viewer. If combo list is open,
+ // then click events on other parts of the view or outside
+ // the combo should hide the editor.
+ // Refreshing the viewer hides the combo and other editors
+ // which are active.
+ attViewer.refresh();
+ }
+ });
+ }
}
private void addManagerListeners() {
public Image getColumnImage(Object element, int col) {
if (col == 2) {
if (element instanceof AttributeElement) {
- // Ignore for collection resource
+ // Ignore for non-single resource
Resource res = resourceManager
.getCurrentResourceInSelection();
if (res instanceof SingleResource) {
}
case 2: {
- // Ignore for collection resource
+ // Ignore for non-single resource
Resource res = resourceManager
.getCurrentResourceInSelection();
if (res instanceof SingleResource) {
import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.MetaProperty;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.utils.Constants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
}
});
}
-
- @Override
- public void onDeviceSelectionChange(final Device dev) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- if (null != tableViewer) {
- properties = getData(dev);
- updateViewer(properties);
- }
- updateEditControls(dev);
- }
- });
- }
};
}
if (editBtn.getText().equals("Edit")) {
cancelBtn.setEnabled(true);
editBtn.setText("Save");
- enable_edit = true;
+ setEnableEdit(true);
} else {
boolean result = false;
Resource resourceInSelection = resourceManagerRef
boolean update = false;
boolean uriChange = false;
boolean nameChange = false;
+
if (resourceManagerRef.isPropValueChanged(
resourceInSelection, properties,
Constants.RESOURCE_NAME)) {
return;
}
- update = true;
- uriChange = true;
-
if (resourceManagerRef
.isResourceStarted(resourceInSelection)) {
update = MessageDialog.openQuestion(
return;
}
}
+
+ update = true;
+ uriChange = true;
}
if (update) {
try {
- result = Activator
- .getDefault()
- .getResourceManager()
- .updateResourceProperties(
- resourceManagerRef
- .getCurrentResourceInSelection(),
- properties, uriChange,
- nameChange);
+ if (uriChange || nameChange)
+ result = Activator
+ .getDefault()
+ .getResourceManager()
+ .updateResourceProperties(
+ resourceManagerRef
+ .getCurrentResourceInSelection(),
+ properties, uriChange,
+ nameChange);
} catch (SimulatorException ex) {
result = false;
}
updateViewer(properties);
}
}
- } else {
- Device dev = resourceManagerRef
- .getCurrentDeviceInSelection();
-
- // Null check
- result = resourceManagerRef.isPropertyValueInvalid(dev,
- properties, Constants.DEVICE_NAME);
- if (result) {
- MessageDialog.openError(parent.getShell(),
- "Invalid Input", "Device Name is invalid.");
- return;
- }
-
- if (resourceManagerRef.isPropValueChanged(dev,
- properties, Constants.DEVICE_NAME)) {
- resourceManagerRef.updateDeviceProperties(dev,
- properties);
- }
-
}
cancelBtn.setEnabled(false);
editBtn.setText("Edit");
- enable_edit = false;
+ setEnableEdit(false);
}
}
});
.getCurrentResourceInSelection();
if (null != res) {
properties = getData(res);
- } else {
- Device dev = resourceManagerRef
- .getCurrentDeviceInSelection();
- if (null != dev) {
- properties = getData(dev);
- }
}
updateViewer(properties);
cancelBtn.setEnabled(false);
editBtn.setText("Edit");
- enable_edit = false;
+ setEnableEdit(false);
}
});
if (editBtn.getText().equals("Save")) {
editBtn.setText("Edit");
- enable_edit = false;
+ setEnableEdit(false);
}
if (null == obj) {
}
}
- private List<MetaProperty> getData(Device dev) {
- if (null != dev) {
- List<MetaProperty> metaPropertyList = resourceManagerRef
- .getMetaProperties(dev);
- return metaPropertyList;
- } else {
- return null;
- }
- }
-
private void updateViewer(List<MetaProperty> metaPropertyList) {
if (null != tableViewer) {
Table tbl = tableViewer.getTable();
+ if (tbl.isDisposed()) {
+ return;
+ }
if (null != metaPropertyList) {
tableViewer.setInput(metaPropertyList.toArray());
- if (!tbl.isDisposed()) {
- tbl.setLinesVisible(true);
- }
+ tbl.setLinesVisible(true);
} else {
- if (!tbl.isDisposed()) {
- tbl.removeAll();
- tbl.setLinesVisible(false);
- }
+ tbl.removeAll();
+ tbl.setLinesVisible(false);
}
}
}
- public void createColumns(TableViewer tableViewer) {
+ public void createColumns(final TableViewer tableViewer) {
TableViewerColumn propName = new TableViewerColumn(tableViewer,
SWT.NONE);
propName.getColumn().setWidth(columnWidth[0]);
SWT.NONE);
propValue.getColumn().setWidth(columnWidth[1]);
propValue.getColumn().setText(columnHeaders[1]);
- propValue.setLabelProvider(new ColumnLabelProvider() {
+ propValue.setLabelProvider(new StyledCellLabelProvider() {
@Override
- public String getText(Object element) {
- MetaProperty prop = (MetaProperty) element;
- if (null != prop) {
- return prop.getPropValue();
- } else {
- return "";
- }
+ public void update(ViewerCell cell) {
+ MetaProperty prop = (MetaProperty) cell.getElement();
+ cell.setText(prop.getPropValue());
+ super.update(cell);
}
});
propValue.setEditingSupport(new PropValueEditor(tableViewer));
}
@Override
- protected CellEditor getCellEditor(Object element) {
- if (!enable_edit) {
+ protected CellEditor getCellEditor(final Object element) {
+ if (!getEnableEdit()) {
return null;
}
// Disabling edit for resource type
if (null != propName && propName.equals(Constants.RESOURCE_TYPE)) {
return null;
}
+
CellEditor editor = new TextCellEditor(viewer.getTable());
return editor;
}
@Override
protected void setValue(Object element, Object value) {
MetaProperty prop = (MetaProperty) element;
+ if (prop.getPropName().equals(Constants.INTERFACE_TYPES)) {
+ return;
+ }
prop.setPropValue(String.valueOf(value));
viewer.update(element, null);
}
+ }
+
+ private synchronized Boolean getEnableEdit() {
+ return enable_edit;
+ }
+ private synchronized void setEnableEdit(boolean value) {
+ enable_edit = value;
}
@Override
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.listener.IPropertiesChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AutomationSettingHelper;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.AddResourceToCollections;
-import oic.simulator.serviceprovider.view.dialogs.AddResourceToDevices;
-import oic.simulator.serviceprovider.view.dialogs.AddResources;
import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
-import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections;
-import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices;
-import oic.simulator.serviceprovider.view.dialogs.RemoveResources;
import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
private Button deleteButton;
private TreeViewer singleResTreeViewer;
- private TreeViewer collectionResTreeViewer;
- private TreeViewer deviceTreeViewer;
-
- private CTabFolder folder;
- private CTabItem singleResTab;
- private CTabItem collectionResTab;
- private CTabItem deviceTab;
private IResourceListChangedListener resourceListChangedListener;
if (null != singleResTreeViewer) {
singleResTreeViewer.refresh();
}
- } else if (type == ResourceType.COLLECTION) {
- if (null != collectionResTreeViewer) {
- collectionResTreeViewer.refresh();
- }
- } else {
- if (null != deviceTreeViewer) {
- deviceTreeViewer.refresh();
- }
}
// Trigger the visibility of delete button
@Override
public void run() {
- if (null != singleResTreeViewer
- && null != collectionResTreeViewer
- && null != deviceTreeViewer) {
- switch (type) {
- case SINGLE:
+ switch (type) {
+ case SINGLE:
+ if (null != singleResTreeViewer)
singleResTreeViewer.refresh();
- case COLLECTION:
- collectionResTreeViewer.refresh();
- default:
- deviceTreeViewer.refresh();
- }
+ break;
}
+
// Trigger the visibility of delete button
changeDeleteVisibility();
}
@Override
public void run() {
- if (null != singleResTreeViewer
- && null != collectionResTreeViewer
- && null != deviceTreeViewer) {
- switch (type) {
- case SINGLE:
+ switch (type) {
+ case SINGLE:
+ if (null != singleResTreeViewer)
singleResTreeViewer.refresh();
- case COLLECTION:
- collectionResTreeViewer.refresh();
- default:
- deviceTreeViewer.refresh();
- }
+ break;
}
}
});
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (null != singleResTreeViewer
- && null != collectionResTreeViewer
- && null != deviceTreeViewer) {
+ if (null != singleResTreeViewer)
singleResTreeViewer.refresh();
- collectionResTreeViewer.refresh();
- deviceTreeViewer.refresh();
- }
- }
- });
- }
-
- @Override
- public void onDevicePropertyChange() {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- if (null != deviceTreeViewer) {
- deviceTreeViewer.refresh();
- }
}
});
}
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
compContent.setLayoutData(gd);
- Composite buttonComp = new Composite(compContent, SWT.NONE);
- buttonComp.setLayout(new GridLayout(2, false));
-
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
-
- buttonComp.setLayoutData(gd);
-
- createButton = new Button(buttonComp, SWT.PUSH);
- createButton.setText("Create");
- createButton.setToolTipText("Create Simulator Resource(s)");
-
- gd = new GridData();
- gd.widthHint = 90;
- createButton.setLayoutData(gd);
-
- deleteButton = new Button(buttonComp, SWT.PUSH);
- deleteButton.setText("Delete");
- deleteButton.setToolTipText("Delete Simulator Resource(s)");
-
- gd = new GridData();
- gd.widthHint = 90;
- deleteButton.setLayoutData(gd);
-
- // Create a Tab Folder.
- folder = new CTabFolder(compContent, SWT.BORDER);
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- folder.setLayoutData(gd);
- folder.setSimple(false);
- folder.setUnselectedCloseVisible(false);
- folder.setUnselectedImageVisible(false);
- folder.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- // Tab is switched.
- singleResTreeViewer.setSelection(null);
- collectionResTreeViewer.setSelection(null);
- deviceTreeViewer.setSelection(null);
- resourceManager.resourceSelectionChanged(null);
- }
- });
-
- createSimpleResourcesArea();
-
- createCollectionResourcesArea();
-
- createDeviceArea();
-
- folder.setSelection(singleResTab);
-
- addUIListeners();
-
- addManagerListeners();
-
- // If there is at least one resource exist, then enable the delete
- // resource button
- changeDeleteVisibility();
- }
-
- private void createSimpleResourcesArea() {
- singleResTab = new CTabItem(folder, SWT.NULL);
- singleResTab.setText("Simple Resources");
-
- // Create a group to show all the discovered resources.
- // Adding the group to the folder.
- Group resourceGroup = new Group(folder, SWT.NONE);
- // resourceGroup.setText("Discovered Resources");
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
- resourceGroup.setBackground(color);
-
- resourceGroup.setLayout(new GridLayout(1, false));
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- resourceGroup.setLayoutData(gd);
-
- PatternFilter filter = new PatternFilter();
- FilteredTree filteredTree = new FilteredTree(resourceGroup,
- SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
- singleResTreeViewer = filteredTree.getViewer();
- singleResTreeViewer.getTree().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- singleResTreeViewer
- .setContentProvider(new SingleResourceContentProvider());
- singleResTreeViewer.setLabelProvider(new TreeLabelProvider());
- singleResTreeViewer.setInput(new Object());
-
- singleResTreeViewer
- .addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent e) {
- IStructuredSelection selection = (IStructuredSelection) e
- .getSelection();
- if (null == selection) {
- return;
- }
-
- Resource res = null;
- int size = selection.size();
- if (size == 1) {
- res = (Resource) selection.getFirstElement();
- }
- resourceManager.resourceSelectionChanged(res);
- }
- });
-
- // TODO: Add menu items
- addMenuToSimpleResources();
-
- singleResTab.setControl(resourceGroup);
- }
-
- private void addMenuToSimpleResources() {
- if (null != singleResTreeViewer) {
- final Tree resourceTreeHead = singleResTreeViewer.getTree();
- if (null != resourceTreeHead) {
- // Below code creates menu entries and shows them on right
- // clicking a resource
- final Menu menu = new Menu(resourceTreeHead);
- resourceTreeHead.setMenu(menu);
- menu.addMenuListener(new MenuAdapter() {
- @Override
- public void menuShown(MenuEvent e) {
- // Clear existing menu items
- MenuItem[] items = menu.getItems();
- for (int index = 0; index < items.length; index++) {
- items[index].dispose();
- }
-
- IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer
- .getSelection());
- final SingleResource resource = (SingleResource) selection
- .getFirstElement();
- if (null == resource) {
- return;
- }
-
- addAutomationMenu(menu, resource);
-
- // Menu to add resource to one or more collections.
- MenuItem addToCollection = new MenuItem(menu, SWT.NONE);
- addToCollection.setText("Add to Collection");
- addToCollection
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleCollections;
- possibleCollections = resourceManager
- .getCollectionsForAddingToSingleResource(resource);
- if (null == possibleCollections
- || possibleCollections
- .isEmpty()) {
- MessageDialog
- .openError(
- Display.getDefault()
- .getActiveShell(),
- "No possible candidates",
- "There are no possible collections to which the resource can be added.");
- return;
- }
-
- AddResourceToCollections addToCollectionsDlg = new AddResourceToCollections(
- Display.getDefault()
- .getActiveShell(),
- possibleCollections);
- if (addToCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<CollectionResource> resultSet = addToCollectionsDlg
- .getSelectedResourceList();
-
- int addedCount = resourceManager
- .addResourceToCollection(
- resultSet, resource);
- if (addedCount <= 0) {
- MessageDialog
- .openInformation(Display
- .getDefault()
- .getActiveShell(),
- "Operation failed",
- "Failed to add resources to the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(
- Display.getDefault()
- .getActiveShell(),
- "Added",
- "["
- + addedCount
- + "/"
- + resultSet.size()
- + "] added to selected collections");
- }
- });
-
- // Menu to remove resource from one or more collections
- // to which it is a member.
- MenuItem removeFromCollection = new MenuItem(menu,
- SWT.NONE);
- removeFromCollection.setText("Remove from Collection");
- removeFromCollection
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleCollectionstoRemoveFrom;
- possibleCollectionstoRemoveFrom = resourceManager
- .getResourceReferences(resource);
- if (null == possibleCollectionstoRemoveFrom
- || possibleCollectionstoRemoveFrom
- .isEmpty()) {
- MessageDialog
- .openError(
- Display.getDefault()
- .getActiveShell(),
- "No possible candidates",
- "Resource has not been added to any collections.");
- return;
- }
-
- RemoveResourceFromCollections removeFromCollectionsDlg = new RemoveResourceFromCollections(
- Display.getDefault()
- .getActiveShell(),
- possibleCollectionstoRemoveFrom);
- if (removeFromCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<CollectionResource> resultSet = removeFromCollectionsDlg
- .getSelectedResourceList();
-
- int removeCount = resourceManager
- .removeResourceFromCollection(
- resultSet, resource);
- if (removeCount <= 0) {
- MessageDialog
- .openInformation(Display
- .getDefault()
- .getActiveShell(),
- "Operation failed",
- "Failed to remove resources from the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(
- Display.getDefault()
- .getActiveShell(),
- "Removed",
- "["
- + removeCount
- + "/"
- + resultSet.size()
- + "] resource removed from selected collections");
- }
- });
-
- // Menu to add resource to one or more devices.
- MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
- addToDevice.setText("Add to Device");
- addToDevice
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Device> possibleDevices;
- possibleDevices = resourceManager
- .getDevicesForAddingToResource(resource);
- if (null == possibleDevices
- || possibleDevices.isEmpty()) {
- MessageDialog
- .openError(
- Display.getDefault()
- .getActiveShell(),
- "No possible candidates",
- "There are no possible devices to which the resource can be added.");
- return;
- }
-
- AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
- Display.getDefault()
- .getActiveShell(),
- possibleDevices);
- if (addToDevicesDlg.open() != Window.OK) {
- return;
- }
-
- Set<Device> resultSet = addToDevicesDlg
- .getSelectedDeviceList();
-
- resourceManager.addResourceToDevice(
- resultSet, resource);
-
- deviceTreeViewer.refresh();
-
- MessageDialog
- .openInformation(Display
- .getDefault()
- .getActiveShell(),
- "Added",
- "Resource added to selected devices.");
- }
- });
-
- // Menu to remove resource from one or more device to
- // which it is a member.
- MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
- removeFromDevice.setText("Remove from Device");
- removeFromDevice
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Device> possibleDevices;
- possibleDevices = resourceManager
- .getDeviceReferences(resource);
- if (null == possibleDevices
- || possibleDevices.isEmpty()) {
- MessageDialog
- .openError(
- Display.getDefault()
- .getActiveShell(),
- "No possible candidates",
- "Resource has not been added to any devices.");
- return;
- }
-
- RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
- Display.getDefault()
- .getActiveShell(),
- possibleDevices);
- if (removeFromDevicesDlg.open() != Window.OK) {
- return;
- }
-
- Set<Device> resultSet = removeFromDevicesDlg
- .getSelectedDeviceList();
-
- resourceManager
- .removeResourceFromDevice(
- resultSet, resource);
-
- deviceTreeViewer.refresh();
-
- MessageDialog
- .openInformation(Display
- .getDefault()
- .getActiveShell(),
- "Removed",
- "Resource removed from selected devices");
- }
- });
-
- // Menu to remove resource from one or more device to
- // which it is a member.
- MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
- deleteResource.setText("Delete");
- deleteResource
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- try {
- resourceManager
- .removeResource(resource);
- singleResTreeViewer.refresh();
- // if(refreshCollectionTree)
- collectionResTreeViewer.refresh();
- // if(refreshDeviceTree)
- deviceTreeViewer.refresh();
-
- resourceManager
- .resourceSelectionChanged(null);
-
- MessageDialog.openInformation(
- Display.getDefault()
- .getActiveShell(),
- "Deleted",
- "Resource deleted.");
- } catch (SimulatorException e1) {
- MessageDialog
- .openInformation(Display
- .getDefault()
- .getActiveShell(),
- "Deletion Failed",
- "Failed to delete the resource.");
- }
- changeDeleteVisibility();
- }
- });
- }
- });
- }
- }
- }
-
- private void createCollectionResourcesArea() {
- collectionResTab = new CTabItem(folder, SWT.NULL);
- collectionResTab.setText("Collection Resources");
-
- // Create a group to show all the discovered resources.
- // Adding the group to the folder.
- Group resourceGroup = new Group(folder, SWT.NONE);
- // resourceGroup.setText("Discovered Resources");
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
- resourceGroup.setBackground(color);
-
- resourceGroup.setLayout(new GridLayout(1, false));
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- resourceGroup.setLayoutData(gd);
-
- PatternFilter filter = new PatternFilter();
- FilteredTree filteredTree = new FilteredTree(resourceGroup,
- SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
- collectionResTreeViewer = filteredTree.getViewer();
- collectionResTreeViewer.getTree().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- collectionResTreeViewer
- .setContentProvider(new CollectionResourceContentProvider());
- collectionResTreeViewer.setLabelProvider(new TreeLabelProvider());
- collectionResTreeViewer.setInput(new Object());
-
- collectionResTreeViewer
- .addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent e) {
- IStructuredSelection selection = (IStructuredSelection) e
- .getSelection();
- if (null == selection) {
- return;
- }
-
- Resource res = null;
- int size = selection.size();
- if (size == 1) {
- res = (Resource) selection.getFirstElement();
- }
- resourceManager.resourceSelectionChanged(res);
- }
- });
-
- // TODO: Add menu items
- addMenuToCollectionResources();
-
- collectionResTab.setControl(resourceGroup);
- }
-
- private void addMenuToCollectionResources() {
- if (null != collectionResTreeViewer) {
- final Tree resourceTreeHead = collectionResTreeViewer.getTree();
- if (null != resourceTreeHead) {
- // Below code creates menu entries and shows them on right
- // clicking a resource
- final Menu menu = new Menu(resourceTreeHead);
- resourceTreeHead.setMenu(menu);
- menu.addMenuListener(new MenuAdapter() {
- @Override
- public void menuShown(MenuEvent e) {
- // Clear existing menu items
- MenuItem[] items = menu.getItems();
- for (int index = 0; index < items.length; index++) {
- items[index].dispose();
- }
-
- IStructuredSelection selection = ((IStructuredSelection) collectionResTreeViewer
- .getSelection());
- final Resource resource = (Resource) selection
- .getFirstElement();
- TreeItem[] treeItems = resourceTreeHead.getSelection();
- if (null == resource || null == treeItems) {
- return;
- }
-
- final TreeItem parent = treeItems[0].getParentItem();
- if (null == parent) {
- System.out.println("No parent exist");
- // Selected item is a top-level collection
- addMenuToTopLevelCollectionResources(menu,
- (CollectionResource) resource);
- } else {
- if (resource instanceof SingleResource)
- addAutomationMenu(menu,
- (SingleResource) resource);
-
- MenuItem remFromParent = new MenuItem(menu,
- SWT.NONE);
- remFromParent.setText("Remove from Parent");
- remFromParent
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(
- SelectionEvent e) {
- CollectionResource parentCollection = (CollectionResource) parent
- .getData();
- String status;
- try {
- resourceManager
- .removeResourceFromCollection(
- parentCollection,
- resource);
- collectionResTreeViewer
- .refresh();
- deviceTreeViewer.refresh();
-
- resourceManager
- .resourceSelectionChanged(null);
-
- status = "Resource removed from its parent";
- } catch (SimulatorException e1) {
- status = "Failed to remove the resource from its parent";
- }
- MessageDialog.openInformation(
- Display.getDefault()
- .getActiveShell(),
- "Status", status);
- }
- });
-
- if (resource instanceof SingleResource) {
- // Menu Items for single resource will be added
- // here.
- }
- }
- }
- });
- }
- }
- }
-
- private void addMenuToTopLevelCollectionResources(final Menu menu,
- final CollectionResource colRes) {
- // Menu to add one or more resources to the collection.
- MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
- addResources.setText("Add Resources");
-
- Menu addSubMenu = new Menu(menu);
- addResources.setMenu(addSubMenu);
-
- MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
- simpleResources.setText("Simple");
- simpleResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<SingleResource> possibleResources;
- possibleResources = resourceManager
- .getSingleTypeResourcesForAddingToCollectionResource(colRes);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible simple resources that can be added.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertSingleTypeResourceListToBaseType(possibleResources);
-
- AddResources addToCollectionsDlg = new AddResources(Display
- .getDefault().getActiveShell(), resources);
- if (addToCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = addToCollectionsDlg
- .getSelectedResourceList();
-
- int addedCount = resourceManager.addResourceToCollection(
- colRes, resultSet);
- if (addedCount <= 0) {
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Operation failed",
- "Failed to add resources to the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Added", "[" + addedCount + "/"
- + resultSet.size()
- + "] resources added to the collection");
- }
- });
-
- MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
- collectionResources.setText("Collection");
- collectionResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleResources;
- possibleResources = resourceManager
- .getCollectionTypeResourcesForAddingToCollectionResource(colRes);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible collections that can be added.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertCollectionTypeResourceListToBaseType(possibleResources);
-
- AddResources addToCollectionsDlg = new AddResources(Display
- .getDefault().getActiveShell(), resources);
- if (addToCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = addToCollectionsDlg
- .getSelectedResourceList();
-
- int addedCount = resourceManager.addResourceToCollection(
- colRes, resultSet);
- if (addedCount <= 0) {
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Operation failed",
- "Failed to add resources to the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Added", "[" + addedCount + "/"
- + resultSet.size()
- + "] resources added to the collection");
- }
- });
-
- // Menu to remove one or more resources from the collection.
- MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
- removeResources.setText("Remove Resources");
-
- Menu removeSubMenu = new Menu(menu);
- removeResources.setMenu(removeSubMenu);
-
- simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
- simpleResources.setText("Simple");
- simpleResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<SingleResource> possibleResources;
- possibleResources = resourceManager.getSingleTypeChilds(colRes);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible simple resources which can be removed.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertSingleTypeResourceListToBaseType(possibleResources);
-
- RemoveResources removeFromCollectionsDlg = new RemoveResources(
- Display.getDefault().getActiveShell(), resources);
- if (removeFromCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = removeFromCollectionsDlg
- .getSelectedResourceList();
-
- int removeCount = resourceManager
- .removeResourcesFromCollection(colRes, resultSet);
- if (removeCount <= 0) {
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Operation failed",
- "Failed to remove resources from the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Removed", "[" + removeCount + "/"
- + resultSet.size()
- + "] resources removed from the collection");
- }
- });
-
- collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
- collectionResources.setText("Collection");
- collectionResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleResources;
- possibleResources = resourceManager
- .getCollectionTypeChilds(colRes);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible collections which can be removed.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertCollectionTypeResourceListToBaseType(possibleResources);
-
- RemoveResources removeFromCollectionsDlg = new RemoveResources(
- Display.getDefault().getActiveShell(), resources);
- if (removeFromCollectionsDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = removeFromCollectionsDlg
- .getSelectedResourceList();
-
- int removeCount = resourceManager
- .removeResourcesFromCollection(colRes, resultSet);
- if (removeCount <= 0) {
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Operation failed",
- "Failed to remove resources from the collection.");
- return;
- }
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Removed", "[" + removeCount + "/"
- + resultSet.size()
- + "] resources removed from the collection");
- }
- });
-
- // Menu to add resource to one or more devices.
- MenuItem addToDevice = new MenuItem(menu, SWT.NONE);
- addToDevice.setText("Add to Device");
- addToDevice.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Device> possibleDevices;
- possibleDevices = resourceManager
- .getDevicesForAddingToResource(colRes);
- if (null == possibleDevices || possibleDevices.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible devices to which the resource can be added.");
- return;
- }
-
- AddResourceToDevices addToDevicesDlg = new AddResourceToDevices(
- Display.getDefault().getActiveShell(), possibleDevices);
- if (addToDevicesDlg.open() != Window.OK) {
- return;
- }
-
- Set<Device> resultSet = addToDevicesDlg.getSelectedDeviceList();
-
- resourceManager.addResourceToDevice(resultSet, colRes);
-
- deviceTreeViewer.refresh();
+ Composite buttonComp = new Composite(compContent, SWT.NONE);
+ buttonComp.setLayout(new GridLayout(2, false));
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Added",
- "Resource added to selected devices.");
- }
- });
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
- // Menu to remove resource from one or more device to which it is a
- // member.
- MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE);
- removeFromDevice.setText("Remove from Device");
- removeFromDevice.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<Device> possibleDevices;
- possibleDevices = resourceManager.getDeviceReferences(colRes);
- if (null == possibleDevices || possibleDevices.isEmpty()) {
- MessageDialog.openError(Display.getDefault()
- .getActiveShell(), "No possible candidates",
- "Resource has not been added to any devices.");
- return;
- }
+ buttonComp.setLayoutData(gd);
- RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices(
- Display.getDefault().getActiveShell(), possibleDevices);
- if (removeFromDevicesDlg.open() != Window.OK) {
- return;
- }
+ createButton = new Button(buttonComp, SWT.PUSH);
+ createButton.setText("Create");
+ createButton.setToolTipText("Create Simulator Resource(s)");
- Set<Device> resultSet = removeFromDevicesDlg
- .getSelectedDeviceList();
+ gd = new GridData();
+ gd.widthHint = 90;
+ createButton.setLayoutData(gd);
- resourceManager.removeResourceFromDevice(resultSet, colRes);
+ deleteButton = new Button(buttonComp, SWT.PUSH);
+ deleteButton.setText("Delete");
+ deleteButton.setToolTipText("Delete Simulator Resource(s)");
- deviceTreeViewer.refresh();
+ gd = new GridData();
+ gd.widthHint = 90;
+ deleteButton.setLayoutData(gd);
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Removed",
- "Resource removed from selected devices");
- }
- });
+ createSimpleResourcesArea(compContent);
- // Menu to remove resource from one or more device to which it is a
- // member.
- MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
- deleteResource.setText("Delete");
- deleteResource.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- /*
- * boolean refreshCollectionTree = false; boolean
- * refreshDeviceTree = false;
- * if(resource.isMemberOfAnyCollection()) {
- * refreshCollectionTree = true; }
- * if(resource.isMemberOfAnyDevice()) { refreshDeviceTree =
- * true; }
- */
- try {
- resourceManager.removeResource(colRes);
- // if(refreshCollectionTree)
- collectionResTreeViewer.refresh();
- // if(refreshDeviceTree)
- deviceTreeViewer.refresh();
-
- resourceManager.resourceSelectionChanged(null);
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Deleted", "Resource deleted.");
- } catch (SimulatorException e1) {
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Deletion Failed",
- "Failed to delete the resource.");
- }
+ addUIListeners();
- changeDeleteVisibility();
- }
- });
+ addManagerListeners();
+ // If there is at least one resource exist, then enable the delete
+ // resource button
+ changeDeleteVisibility();
}
- private void createDeviceArea() {
- deviceTab = new CTabItem(folder, SWT.NULL);
- deviceTab.setText("Devices");
-
+ private void createSimpleResourcesArea(Composite compContent) {
// Create a group to show all the discovered resources.
// Adding the group to the folder.
- Group resourceGroup = new Group(folder, SWT.NONE);
- // resourceGroup.setText("Discovered Resources");
+ Group resourceGroup = new Group(compContent, SWT.NONE);
Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
resourceGroup.setBackground(color);
PatternFilter filter = new PatternFilter();
FilteredTree filteredTree = new FilteredTree(resourceGroup,
SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
- deviceTreeViewer = filteredTree.getViewer();
- deviceTreeViewer.getTree().setLayoutData(
+ singleResTreeViewer = filteredTree.getViewer();
+ singleResTreeViewer.getTree().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
- deviceTreeViewer.setContentProvider(new DeviceContentProvider());
- deviceTreeViewer.setLabelProvider(new TreeLabelProvider());
- deviceTreeViewer.setInput(new Object());
+ singleResTreeViewer
+ .setContentProvider(new SingleResourceContentProvider());
+ singleResTreeViewer.setLabelProvider(new TreeLabelProvider());
+ singleResTreeViewer.setInput(new Object());
- deviceTreeViewer
+ singleResTreeViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent e) {
return;
}
+ Resource res = null;
int size = selection.size();
if (size == 1) {
- Object obj = selection.getFirstElement();
- if (obj instanceof Device) {
- resourceManager
- .deviceSelectionChanged((Device) obj);
- } else {
- resourceManager
- .resourceSelectionChanged((Resource) obj);
- }
- } else {
- resourceManager.deviceSelectionChanged(null);
+ res = (Resource) selection.getFirstElement();
}
+ resourceManager.resourceSelectionChanged(res);
}
});
- // TODO: Add menu items
- addMenuToDevices();
-
- deviceTab.setControl(resourceGroup);
+ addMenuToSimpleResources();
}
- private void addMenuToDevices() {
- if (null != deviceTreeViewer) {
- final Tree resourceTreeHead = deviceTreeViewer.getTree();
+ private void addMenuToSimpleResources() {
+ if (null != singleResTreeViewer) {
+ final Tree resourceTreeHead = singleResTreeViewer.getTree();
if (null != resourceTreeHead) {
// Below code creates menu entries and shows them on right
// clicking a resource
items[index].dispose();
}
- IStructuredSelection selection = ((IStructuredSelection) deviceTreeViewer
+ IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer
.getSelection());
- final Object element = selection.getFirstElement();
- if (element instanceof Device) {
- addMenuToDevices(menu, (Device) element);
- } else {
- final Resource resource = (Resource) element;
- TreeItem[] treeItems = resourceTreeHead
- .getSelection();
- if (null == resource || null == treeItems) {
- return;
- }
+ final SingleResource resource = (SingleResource) selection
+ .getFirstElement();
+ if (null == resource) {
+ return;
+ }
- if (resource instanceof SingleResource)
- addAutomationMenu(menu,
- (SingleResource) resource);
-
- final TreeItem parent = treeItems[0]
- .getParentItem();
- MenuItem remFromParent = new MenuItem(menu,
- SWT.NONE);
- remFromParent.setText("Remove from Parent");
- remFromParent
- .addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(
- SelectionEvent e) {
- String status = "Resource removed from its parent.";
- Object obj = parent.getData();
- if (obj instanceof Device) {
- resourceManager
- .removeResourceFromDevice(
- (Device) obj,
- resource);
- } else {
- try {
- resourceManager
- .removeResourceFromCollection(
- (CollectionResource) obj,
- resource);
- collectionResTreeViewer
- .refresh();
- status = "Resource removed from its parent";
- } catch (SimulatorException e1) {
- status = "Failed to remove the resource from its parent";
- }
- }
-
- deviceTreeViewer.refresh();
+ addAutomationMenu(menu, resource);
+
+ // Menu to remove the resource.
+ MenuItem deleteResource = new MenuItem(menu, SWT.NONE);
+ deleteResource.setText("Delete");
+ deleteResource
+ .addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ resourceManager
+ .removeResource(resource);
+ singleResTreeViewer.refresh();
+
+ resourceManager
+ .resourceSelectionChanged(null);
MessageDialog.openInformation(
Display.getDefault()
.getActiveShell(),
- "Status", status);
+ "Deleted",
+ "Resource deleted.");
+ } catch (SimulatorException e1) {
+ MessageDialog
+ .openInformation(Display
+ .getDefault()
+ .getActiveShell(),
+ "Deletion Failed",
+ "Failed to delete the resource.");
}
- });
-
- if (resource instanceof SingleResource) {
- // Menu Items for single resource will be added
- // here.
- }
- }
+ changeDeleteVisibility();
+ }
+ });
}
});
}
}
}
- private void addMenuToDevices(Menu menu, final Device dev) {
- // Menu to add one or more resources to the collection.
- MenuItem addResources = new MenuItem(menu, SWT.CASCADE);
- addResources.setText("Add Resources");
-
- Menu addSubMenu = new Menu(menu);
- addResources.setMenu(addSubMenu);
-
- MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE);
- simpleResources.setText("Simple");
- simpleResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<SingleResource> possibleResources;
- possibleResources = resourceManager
- .getSingleTypeResourcesForAddingToDevice(dev);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible simple resources that can be added.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertSingleTypeResourceListToBaseType(possibleResources);
-
- AddResources addDlg = new AddResources(Display.getDefault()
- .getActiveShell(), resources);
- if (addDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = addDlg.getSelectedResourceList();
-
- resourceManager.addResourceToDevice(dev, resultSet);
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Added",
- "Single Resources added to the device");
- }
- });
-
- MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE);
- collectionResources.setText("Collection");
- collectionResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleResources;
- possibleResources = resourceManager
- .getCollectionTypeResourcesForAddingToDevice(dev);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible collections that can be added.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertCollectionTypeResourceListToBaseType(possibleResources);
-
- AddResources addDlg = new AddResources(Display.getDefault()
- .getActiveShell(), resources);
- if (addDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = addDlg.getSelectedResourceList();
-
- resourceManager.addResourceToDevice(dev, resultSet);
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Added",
- "Collection Resources added to the device");
- }
- });
-
- // Menu to remove one or more resources from the collection.
- MenuItem removeResources = new MenuItem(menu, SWT.CASCADE);
- removeResources.setText("Remove Resources");
-
- Menu removeSubMenu = new Menu(menu);
- removeResources.setMenu(removeSubMenu);
-
- simpleResources = new MenuItem(removeSubMenu, SWT.NONE);
- simpleResources.setText("Simple");
- simpleResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<SingleResource> possibleResources;
- possibleResources = resourceManager.getSingleTypeChilds(dev);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible simple resources which can be removed.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertSingleTypeResourceListToBaseType(possibleResources);
-
- RemoveResources removeDlg = new RemoveResources(Display
- .getDefault().getActiveShell(), resources);
- if (removeDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = removeDlg.getSelectedResourceList();
-
- resourceManager.removeResourcesFromDevice(dev, resultSet);
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Removed",
- "Single Resources removed from the device");
- }
- });
-
- collectionResources = new MenuItem(removeSubMenu, SWT.NONE);
- collectionResources.setText("Collection");
- collectionResources.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- List<CollectionResource> possibleResources;
- possibleResources = resourceManager
- .getCollectionTypeChilds(dev);
- if (null == possibleResources || possibleResources.isEmpty()) {
- MessageDialog
- .openError(Display.getDefault().getActiveShell(),
- "No possible candidates",
- "There are no possible collections which can be removed.");
- return;
- }
-
- List<Resource> resources = Utility
- .convertCollectionTypeResourceListToBaseType(possibleResources);
-
- RemoveResources removeDlg = new RemoveResources(Display
- .getDefault().getActiveShell(), resources);
- if (removeDlg.open() != Window.OK) {
- return;
- }
-
- Set<Resource> resultSet = removeDlg.getSelectedResourceList();
-
- resourceManager.removeResourcesFromDevice(dev, resultSet);
-
- collectionResTreeViewer.refresh();
-
- deviceTreeViewer.refresh();
-
- MessageDialog.openInformation(Display.getDefault()
- .getActiveShell(), "Removed",
- "Collection Resources removed from the device");
- }
- });
-
- // Menu to remove the device.
- MenuItem deleteDevice = new MenuItem(menu, SWT.NONE);
- deleteDevice.setText("Delete");
- deleteDevice.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- resourceManager.removeDevice(dev);
- deviceTreeViewer.refresh();
- }
- });
- }
-
private void addAutomationMenu(final Menu menu,
final SingleResource selectedResource) {
MenuItem startItem = new MenuItem(menu, SWT.NONE);
public void run() {
CreateResourceWizard createWizard = new CreateResourceWizard();
ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
- PlatformUI.getWorkbench().getDisplay()
- .getActiveShell(), createWizard);
+ Display.getDefault().getActiveShell(),
+ createWizard);
createWizard.setWizardDialog(wizardDialog);
int open = wizardDialog.open();
if (open == WizardDialog.OK
Option option = createWizard.getMainPage()
.getOption();
- if (option == Option.DEVICE) {
- Device dev = createWizard.getCreatedDevice();
- if (null != dev) {
- folder.setSelection(deviceTab);
- deviceTreeViewer.setSelection(
- new StructuredSelection(dev), true);
- resourceManager.deviceSelectionChanged(dev);
- deviceTreeViewer.expandToLevel(dev,
- Constants.TREE_EXPANSION_LEVEL);
- }
- } else if (option == Option.SIMPLE_FROM_RAML
+ if (option == Option.SIMPLE_FROM_RAML
|| option == Option.SIMPLE) {
SingleResource res = (SingleResource) createWizard
.getCreatedResource();
if (null != res) {
- folder.setSelection(singleResTab);
boolean canSelect = true;
if (option == Option.SIMPLE_FROM_RAML
&& createWizard.getResourceCount() > 1) {
.resourceSelectionChanged(res);
}
}
- } else if (option == Option.COLLECTION_FROM_RAML
- || option == Option.COLLECTION) {
- CollectionResource res = (CollectionResource) createWizard
- .getCreatedResource();
- if (null != res) {
- folder.setSelection(collectionResTab);
- collectionResTreeViewer.setSelection(
- new StructuredSelection(res), true);
- resourceManager
- .resourceSelectionChanged(res);
- collectionResTreeViewer.expandToLevel(res,
- Constants.TREE_EXPANSION_LEVEL);
- }
}
MessageDialog.openInformation(Display.getDefault()
int open = wizardDialog.open();
if (open == Window.OK) {
singleResTreeViewer.refresh();
- collectionResTreeViewer.refresh();
- deviceTreeViewer.refresh();
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(),
"Resource Deletion Status", deleteWizard
}
}
-class CollectionResourceContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- if (parent instanceof CollectionResource) {
- CollectionResource cRes = (CollectionResource) parent;
- Set<Resource> childs = cRes.getChildResources();
- if (null == childs) {
- return null;
- }
- return childs.toArray();
- }
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- List<CollectionResource> resList;
- resList = Activator.getDefault().getResourceManager()
- .getCollectionResourceList();
- if (null == resList) {
- resList = new ArrayList<CollectionResource>();
- }
- return resList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- if (parent instanceof CollectionResource) {
- CollectionResource cRes = (CollectionResource) parent;
- Set<Resource> children = cRes.getChildResources();
- if (null != children && children.size() > 0) {
- return true;
- }
- }
- return false;
- }
-}
-
-class DeviceContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- if (parent instanceof Device) {
- Device dev = (Device) parent;
- Set<Resource> children = dev.getChildResources();
- if (null != children && children.size() > 0) {
- return children.toArray();
- }
- } else if (parent instanceof CollectionResource) {
- CollectionResource res = (CollectionResource) parent;
- Set<Resource> children = res.getChildResources();
- if (null != children && children.size() > 0) {
- return children.toArray();
- }
- }
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- List<Device> deviceList;
- deviceList = Activator.getDefault().getResourceManager()
- .getDeviceList();
- if (null == deviceList) {
- deviceList = new ArrayList<Device>();
- }
- return deviceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- if (parent instanceof Device) {
- Device dev = (Device) parent;
- Set<Resource> children = dev.getChildResources();
- if (null != children && children.size() > 0) {
- return true;
- }
- } else if (parent instanceof CollectionResource) {
- CollectionResource res = (CollectionResource) parent;
- Set<Resource> children = res.getChildResources();
- if (null != children && children.size() > 0) {
- return true;
- }
- }
- return false;
- }
-}
-
class TreeLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
if (element instanceof Resource) {
Resource res = (Resource) element;
return res.getResourceName();
- } else {
- Device dev = (Device) element;
- return dev.getDeviceName();
}
+ return null;
}
@Override
if (element instanceof SingleResource) {
return Activator.getDefault().getImageRegistry()
.get(Constants.SINGLE_RESOURCE);
- } else if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.DEVICE);
}
+ return null;
}
}
\ No newline at end of file
import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.ObserverDetail;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.utils.Constants;
}
});
}
-
- @Override
- public void onDeviceSelectionChange(Device dev) {
- // TODO Auto-generated method stub
-
- }
};
resourceObserverListChangedListener = new IObserverListChangedListener() {
createColumns(tblViewer);
- // make lines and header visible
+ // Make lines and header visible
final Table table = tblViewer.getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.view.dialogs;
import java.util.Iterator;
att = new AttributeHelper();
} else {
attClone = att.clone();
- System.out.println("Cloned attribute's data:" + attClone);
editOperation = true;
}
attHelper = att;
Composite container = new Composite(compLayout, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout layout = new GridLayout(5, false);
- /*
- * layout.verticalSpacing = 10; layout.marginTop = 10;
- */
container.setLayout(layout);
Label attNameLbl = new Label(container, SWT.NULL);
updateControls();
dflValueTxt.setText(attHelper.getAttributeDflValue());
Type valuesType = attHelper.getValidValuesType();
- /*
- * if (valuesType == Type.UNKNOWN) { noneBtn.setSelection(true); }
- * else
- */if (valuesType == Type.RANGE) {
+ if (valuesType == Type.RANGE) {
rangeBtn.setSelection(true);
noneBtn.setSelection(false);
rangeOptionSelected(true);
@Override
public void handleEvent(Event e) {
String string = e.text;
- System.out.println(string);
char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
}
}
}
- // attHelper.setMin(minRangeTxt.getText() + string);
}
});
}
}
}
- // attHelper.setMax(maxRangeTxt.getText() + string);
}
});
SingleTextInputDialog dialog = new SingleTextInputDialog(
getShell(), "Add Attribute Value", "Attribute Value");
if (dialog.open() == Window.OK) {
- System.out.println(dialog.getValue());
String value = dialog.getValue();
String type = attTypeCmb.getText();
if (!attHelper.isValueValid(value, type)) {
customValuesList.select(customValuesList.getItemCount() - 1);
customValuesList.showSelection();
remBtn.setEnabled(true);
- // attHelper.addValueToAllowedValues(value);
}
}
}
@Override
public void widgetSelected(SelectionEvent e) {
int[] selection = customValuesList.getSelectionIndices();
- // String[] selectionStr = customValuesList.getSelection();
if (null != selection && selection.length > 0) {
customValuesList.remove(selection);
- /*
- * for (String selected : selectionStr) {
- * attHelper.removeValueFromAllowedValues(selected); }
- */
}
changeRemBtnVisibility();
dflValueTxt.setText("");
String selected = attTypeCmb.getText();
- // attHelper.setAttributeType(selected);
if (selected.equals(Constants.INT)) {
enable(true);
customOptionSelected(false);
detail.setText(defaultMessage + msgForDoubleType);
} else if (selected.equals(Constants.BOOL)) {
- // noneBtn.setSelection(true);
enable(false);
rangeOptionSelected(false);
customOptionSelected(false);
rangeOptionSelected(false);
cusValuesBtn.setEnabled(true);
noneBtn.setEnabled(true);
- // cusValuesBtn.setSelection(true);
detail.setText(defaultMessage + msgForStringType);
} else {
- // noneBtn.setSelection(true);
enable(false);
rangeOptionSelected(false);
customOptionSelected(false);
return false;
}
- /*
- * @Override protected Point getInitialSize() { Point curSize =
- * super.getInitialSize(); return new Point(curSize.x, curSize.y + 200); }
- */
-
@Override
protected Point getInitialLocation(Point initialSize) {
Rectangle shellBounds = Display.getDefault().getActiveShell()
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class AddResourceToCollections extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<CollectionResource> sourceList;
-
- Set<CollectionResource> selectedResourceList;
-
- public AddResourceToCollections(Shell parentShell,
- List<CollectionResource> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedResourceList = new HashSet<CollectionResource>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Add To Collections");
- setMessage("Select one or more collection resources to which the single resource will be added.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- CollectionResource res = (CollectionResource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<CollectionResource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<CollectionResource>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- CollectionResource res = (CollectionResource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return null;
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedResourceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No resources are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class AddResourceToDevices extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<Device> sourceList;
-
- Set<Device> selectedDeviceList;
-
- public AddResourceToDevices(Shell parentShell, List<Device> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedDeviceList = new HashSet<Device>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Add To Devices");
- setMessage("Select one or more devices to which the single resource will be added.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Device dev = (Device) e.getElement();
- if (null != dev) {
- if (e.getChecked()) {
- selectedDeviceList.add(dev);
- System.out.println("Checked" + dev.getDeviceName());
- } else {
- selectedDeviceList.remove(dev);
- System.out.println("Unchecked:" + dev.getDeviceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<Device> getSelectedDeviceList() {
- return selectedDeviceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<Device>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Device dev = (Device) element;
- return dev.getDeviceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof Device) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.DEVICE);
- } else {
- return null;
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedDeviceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No devices are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class AddResources extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<Resource> sourceList;
-
- Set<Resource> selectedResourceList;
-
- public AddResources(Shell parentShell, List<Resource> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedResourceList = new HashSet<Resource>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Add Resources");
- setMessage("Select one or more resources to be added.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Resource res = (Resource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<Resource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<Resource>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Resource res = (Resource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.SINGLE_RESOURCE);
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedResourceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No resources are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
+++ /dev/null
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-
-public class AddResourcesToCollectionPage extends WizardPage {
-
- private CheckboxTreeViewer treeViewer;
-
- Set<Resource> selectedResourceList;
-
- protected AddResourcesToCollectionPage() {
- super("Add Resources To Collection");
- selectedResourceList = new HashSet<Resource>();
- }
-
- @Override
- public void createControl(Composite parent) {
- setPageComplete(false);
- setTitle(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE);
- setMessage(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE);
-
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout gridLayout = new GridLayout();
- container.setLayout(gridLayout);
- GridData gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- container.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Resource res = (Resource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- setControl(container);
- }
-
- @Override
- public IWizardPage getNextPage() {
- return null;
- }
-
- public Set<Resource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- System.out.println("getChildren()");
-
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- List<Resource> resList;
- resList = Activator.getDefault().getResourceManager()
- .getResourceList();
- if (null == resList) {
- resList = new ArrayList<Resource>();
- }
- return resList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Resource res = (Resource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof SingleResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.SINGLE_RESOURCE);
- } else if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.DEVICE);
- }
- }
- }
-}
+++ /dev/null
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Text;
-
-public class CollectionResourceBasicDetailsPage extends WizardPage {
-
- private Text resNameTxt;
- private Text resUriTxt;
- private List resTypeslist;
- private Button addToListBtn;
- private Button remFromListBtn;
- private Button observeBtn;
- // private Button startBtn;
-
- private String resName;
- private String resURI;
- private Set<String> resTypes;
- // private boolean start;
- private boolean observable;
- private boolean anyResourceExist;
-
- protected CollectionResourceBasicDetailsPage() {
- super("Basic Details");
- resTypes = new HashSet<String>();
- anyResourceExist = Activator.getDefault().getResourceManager()
- .isAnyResourceExist();
- }
-
- @Override
- public void createControl(Composite parent) {
- setPageComplete(false);
- setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE);
- setMessage(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE);
-
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout gridLayout = new GridLayout();
- container.setLayout(gridLayout);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- container.setLayoutData(gd);
-
- Group resDetGrp = new Group(container, SWT.NONE);
- resDetGrp.setText("Resource Details");
- gridLayout = new GridLayout(4, false);
- resDetGrp.setLayout(gridLayout);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- resDetGrp.setLayoutData(gd);
-
- Label resNameLbl = new Label(resDetGrp, SWT.NULL);
- resNameLbl.setText(Constants.RESOURCE_NAME);
- gd = new GridData();
- resNameLbl.setLayoutData(gd);
-
- resNameTxt = new Text(resDetGrp, SWT.BORDER);
- gd = new GridData();
- // gd.widthHint = 300;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalSpan = 3;
- resNameTxt.setLayoutData(gd);
- resNameTxt.setFocus();
-
- Label resUriLbl = new Label(resDetGrp, SWT.NULL);
- resUriLbl.setText(Constants.RESOURCE_URI);
-
- resUriTxt = new Text(resDetGrp, SWT.BORDER);
- gd = new GridData();
- // gd.widthHint = 300;
- gd.horizontalSpan = 3;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- resUriTxt.setLayoutData(gd);
- /*
- * Composite resTypesComp = new Composite(compContent, SWT.NONE);
- * gridLayout = new GridLayout(3, false);
- * resTypesComp.setLayout(gridLayout); gd = new GridData();
- * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
- * SWT.FILL; resTypesComp.setLayoutData(gd);
- */
-
- Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
- resTypesLbl.setText(Constants.RESOURCE_TYPES);
-
- resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
- | SWT.V_SCROLL);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.horizontalSpan = 2;
- gd.heightHint = 100;
- /* gd.widthHint = 200; */
- resTypeslist.setLayoutData(gd);
- // resTypeslist.setBackground(new Color());
-
- Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
- gridLayout = new GridLayout();
- resTypesActionsComp.setLayout(gridLayout);
- gd = new GridData();
- gd.verticalAlignment = SWT.TOP;
- /*
- * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
- * SWT.FILL;
- */
- resTypesActionsComp.setLayoutData(gd);
-
- addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
- addToListBtn.setText("Add");
- gd = new GridData();
- gd.widthHint = 70;
- addToListBtn.setLayoutData(gd);
-
- remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
- remFromListBtn.setText("Remove");
- gd = new GridData();
- gd.widthHint = 70;
- remFromListBtn.setLayoutData(gd);
- remFromListBtn.setEnabled(false);
-
- Group otherOptionsGrp = new Group(container, SWT.NONE);
- otherOptionsGrp.setText("Other options");
- gridLayout = new GridLayout();
- otherOptionsGrp.setLayout(gridLayout);
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- otherOptionsGrp.setLayoutData(gd);
-
- observeBtn = new Button(otherOptionsGrp, SWT.CHECK);
- observeBtn.setText("Observable");
- observeBtn.setSelection(true);
- observable = true;
-
- /*
- * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
- * startBtn.setText("Start the resource immediately after creation");
- * startBtn.setSelection(true);
- */
-
- addUiListeners();
-
- setControl(container);
- }
-
- private void addUiListeners() {
-
- resUriTxt.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent arg0) {
- resURI = resUriTxt.getText();
- if (null == resURI) {
- return;
- }
-
- if (anyResourceExist)
- getWizard().getContainer().updateButtons();
- else
- setPageComplete(isSelectionDone());
- }
- });
-
- resNameTxt.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent arg0) {
- resName = resNameTxt.getText();
- if (null == resName) {
- return;
- }
- if (anyResourceExist)
- getWizard().getContainer().updateButtons();
- else
- setPageComplete(isSelectionDone());
- }
- });
-
- addToListBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- SingleTextInputDialog dialog = new SingleTextInputDialog(
- getShell(), "Add Resource Type", "Resource Type");
- if (dialog.open() == Window.OK) {
- System.out.println(dialog.getValue());
- String resType = dialog.getValue();
- // Duplicate check.
- if (resTypes.contains(resType)) {
- MessageDialog.openError(Display.getDefault()
- .getActiveShell(), "Duplicate value",
- "value already exist.");
- return;
- }
- resTypeslist.add(resType);
- resTypeslist.deselectAll();
- resTypeslist.select(resTypeslist.getItemCount() - 1);
- resTypeslist.showSelection();
- remFromListBtn.setEnabled(true);
- resTypes.add(resType);
- if (anyResourceExist)
- getWizard().getContainer().updateButtons();
- else
- setPageComplete(isSelectionDone());
- }
- }
- });
-
- remFromListBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int[] selection = resTypeslist.getSelectionIndices();
- String[] selectionStr = resTypeslist.getSelection();
- if (null != selection && selection.length > 0) {
- resTypeslist.remove(selection);
- for (String selected : selectionStr) {
- resTypes.remove(selected);
- }
- }
- changeVisibility();
- if (anyResourceExist)
- getWizard().getContainer().updateButtons();
- else
- setPageComplete(isSelectionDone());
- }
- });
-
- resTypeslist.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- changeVisibility();
- }
- });
-
- observeBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- observable = observeBtn.getSelection();
- }
- });
-
- /*
- * startBtn.addSelectionListener(new SelectionAdapter() {
- *
- * @Override public void widgetSelected(SelectionEvent e) { start =
- * startBtn.getSelection(); } });
- */
- }
-
- private void changeVisibility() {
- int[] selection = resTypeslist.getSelectionIndices();
- if (null != selection && selection.length > 0) {
- remFromListBtn.setEnabled(true);
- } else {
- remFromListBtn.setEnabled(false);
- }
- }
-
- @Override
- public boolean canFlipToNextPage() {
- System.out.println("canFlipToNextPage()");
- if (!anyResourceExist) {
- return false;
- }
- return isSelectionDone();
- }
-
- public boolean isSelectionDone() {
- if (null == resName || resName.trim().length() < 1 || null == resURI
- || resURI.trim().length() < 1 || null == resTypes
- || resTypes.size() < 1) {
- return false;
- }
- return true;
- }
-
- @Override
- public IWizardPage getNextPage() {
- // Checking whether the uri is used by any other resource.
- if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
- MessageDialog
- .openError(getShell(), "Resource URI in use",
- "Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
- return null;
- }
-
- if (!Utility.isUriValid(resURI)) {
- MessageDialog.openError(Display.getDefault().getActiveShell(),
- "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
- return null;
- }
-
- if (anyResourceExist) {
- return ((CreateResourceWizard) getWizard())
- .getAddResourcesToCollectionPage();
- }
- return null;
- }
-
- public String getResName() {
- return resName;
- }
-
- public String getResURI() {
- return resURI;
- }
-
- public Set<String> getResTypes() {
- return resTypes;
- }
-
- /*
- * public boolean isStart() { return start; }
- */
-
- public boolean isObservable() {
- return observable;
- }
-
- public boolean isAnyResourceExist() {
- return anyResourceExist;
- }
-}
import java.util.Set;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AttributeHelper;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Device;
import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.ResourceType;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
*/
public class CreateResourceWizard extends Wizard {
- private MainPage mainPage;
- private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
- private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
- private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
- private CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage;
- private AddResourcesToCollectionPage addResourcesToCollectionPage;
- private LoadRamlPage loadRamlPage;
- private UpdatePropertiesPage updatePropPage;
- private DevicePage devicePage;
- private StartStopResourcePage startStopPage;
+ private MainPage mainPage;
+ private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage;
+ private SimpleResourceAddAttributePage simpleResourceAddAttributePage;
+ private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage;
+ private LoadRamlPage loadRamlPage;
+ private UpdatePropertiesPage updatePropPage;
+ private StartStopResourcePage startStopPage;
- // private SingleResource simResource;
- private String status;
+ private String status;
- private WizardDialog wizDialog;
- private boolean dlgForceClosed;
+ private WizardDialog wizDialog;
+ private boolean dlgForceClosed;
- private Resource createdResource;
- private Device createdDevice;
+ private Resource createdResource;
public CreateResourceWizard() {
setWindowTitle("Create resources");
simpleResourceBasicDetailsPage = new SimpleResourceBasicDetailsPage();
simpleResourceAddAttributePage = new SimpleResourceAddAttributePage();
simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage();
- collectionResourceBasicDetailsPage = new CollectionResourceBasicDetailsPage();
- addResourcesToCollectionPage = new AddResourcesToCollectionPage();
loadRamlPage = new LoadRamlPage();
updatePropPage = new UpdatePropertiesPage();
- devicePage = new DevicePage();
startStopPage = new StartStopResourcePage();
addPage(mainPage);
addPage(simpleResourceBasicDetailsPage);
addPage(simpleResourceAddAttributePage);
addPage(simpleResourceOtherDetailsPage);
- addPage(collectionResourceBasicDetailsPage);
- if (Activator.getDefault().getResourceManager().isAnyResourceExist())
- addPage(addResourcesToCollectionPage);
addPage(loadRamlPage);
addPage(updatePropPage);
- addPage(devicePage);
addPage(startStopPage);
}
return createdResource;
}
- public Device getCreatedDevice() {
- return createdDevice;
- }
-
@Override
public boolean canFinish() {
- System.out.println("canFinish()");
IWizardPage curPage = this.getContainer().getCurrentPage();
- System.out.println(curPage.getName());
if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator
.getDefault().getResourceManager().isAnyResourceExist()))
- || (curPage == collectionResourceBasicDetailsPage
- && !Activator.getDefault().getResourceManager()
- .isAnyResourceExist() && collectionResourceBasicDetailsPage
- .isSelectionDone())
- || curPage == addResourcesToCollectionPage
|| curPage == simpleResourceAddAttributePage
|| (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage
- .isMultiResourceCreation()) || curPage == devicePage) {
+ .isMultiResourceCreation())) {
return true;
}
return false;
@Override
public boolean performFinish() {
- System.out.println("performFinish()");
final IWizardPage curPage = this.getContainer().getCurrentPage();
- System.out.println(curPage.getClass().getSimpleName());
- if (curPage == simpleResourceAddAttributePage) { // Handling Simple
- // Resource Creation
- // without RAML
+ // Handling Simple Resource Creation without RAML
+ if (curPage == simpleResourceAddAttributePage) {
try {
- getContainer().run(true, true, new IRunnableWithProgress() {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
.log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == loadRamlPage) { // Handling multi-instance
- // creation of simple resource
- // with RAML
+ } else if (curPage == loadRamlPage) {
+ // Handling multiple instance creation of simple resource with RAML
if ((loadRamlPage.getResourceCount() + Activator.getDefault()
.getResourceManager().getResourceCount()) > Constants.MAX_RESOURCE_COUNT) {
MessageDialog
}
try {
- getContainer().run(true, true, new IRunnableWithProgress() {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
.log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == updatePropPage) { // Handling the single instance
+ } else if (curPage == updatePropPage) {
+ // Handling the single instance
String resName = updatePropPage.getResName();
String resURI = updatePropPage.getResURI();
if (null == resName || resName.trim().length() < 1) {
"Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
return false;
}
- // creation of simple resource
- // with RAML
- // Checking whether the uri is used by any other resource.
+ // Creation of simple resource with RAML
+ // Checking whether the URI is used by any other resource.
if (Activator.getDefault().getResourceManager()
.isResourceExist(updatePropPage.getResURI())) {
MessageDialog
}
try {
- getContainer().run(true, true, new IRunnableWithProgress() {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
.log(Level.ERROR.ordinal(), new Date(), e.getMessage());
e.printStackTrace();
}
- } else if (curPage == collectionResourceBasicDetailsPage
- || (curPage == addResourcesToCollectionPage && mainPage
- .getOption() == Option.COLLECTION)) {
- // Checking whether the uri is used by any other resource.
- if (Activator
- .getDefault()
- .getResourceManager()
- .isResourceExist(
- collectionResourceBasicDetailsPage.getResURI())) {
- MessageDialog
- .openError(getShell(), "Resource URI in use",
- "Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on
- // wizard
- // itself.
- return false;
- }
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask(
- "Collection Resource Creation Without RAML",
- 3);
- monitor.worked(1);
- createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true
- : false);
- monitor.worked(1);
- if (curPage == addResourcesToCollectionPage) {
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
- }
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- }
- } else if (curPage == addResourcesToCollectionPage) {
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask(
- "Completing Collection Resource Creation With RAML",
- 3);
- monitor.worked(1);
- completeResourceCreationWithRAML();
- monitor.worked(1);
-
- if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
- Resource res = loadRamlPage.getResource();
- if (null != res
- && res instanceof CollectionResource) {
- Set<Resource> selectedResources = addResourcesToCollectionPage
- .getSelectedResourceList();
- if (!selectedResources.isEmpty()) {
- int addedCount = Activator
- .getDefault()
- .getResourceManager()
- .addResourceToCollection(
- (CollectionResource) res,
- selectedResources);
- if (addedCount > 0) {
-
- status += " and ["
- + addedCount
- + "/"
- + selectedResources.size()
- + "] resources added to the collection";
-
- UiListenerHandler
- .getInstance()
- .resourceListUpdateUINotification(
- ResourceType.COLLECTION);
- } else {
- status += " but failed to add resources to the collection";
- }
- }
- }
- }
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- }
- } else if (curPage == devicePage) {
- final String devName = devicePage.getDeviceName();
- final Set<Resource> resourceList = devicePage
- .getSelectedResourceList();
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- monitor.beginTask("Device Creation", 3);
- monitor.worked(1);
- createdDevice = createDevice(devName, resourceList);
- monitor.worked(1);
- UiListenerHandler.getInstance()
- .resourceListUpdateUINotification(
- ResourceType.DEVICE);
- status = "Device Created.";
- monitor.worked(1);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- } catch (InterruptedException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- e.printStackTrace();
- }
}
return true;
}
return simpleResourceAddAttributePage;
}
- public CollectionResourceBasicDetailsPage getCollectionResourceBasicDetailsPage() {
- return collectionResourceBasicDetailsPage;
- }
-
public SimpleResourceOtherDetailsPage getSimpleResourceOtherDetailsPage() {
return simpleResourceOtherDetailsPage;
}
- public AddResourcesToCollectionPage getAddResourcesToCollectionPage() {
- return addResourcesToCollectionPage;
- }
-
public LoadRamlPage getLoadRamlPage() {
return loadRamlPage;
}
return updatePropPage;
}
- public DevicePage getDevicePage() {
- return devicePage;
- }
-
public StartStopResourcePage getStartStopPage() {
return startStopPage;
}
// Basic resource details
resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI());
resource.setResourceName(simpleResourceBasicDetailsPage.getResName());
- resource.setResourceTypes(simpleResourceBasicDetailsPage.getResTypes());
+ resource.setResourceType(simpleResourceBasicDetailsPage.getResType());
resource.setObservable(simpleResourceBasicDetailsPage.isObservable());
// Resource Attributes
private void completeResourceCreationWithRAML() {
try {
- boolean result;
+ boolean result = false;
Resource res = loadRamlPage.getResource();
if (res instanceof SingleResource) {
result = Activator
.completeSingleResourceCreationByRAML(res,
updatePropPage.getResURI(),
updatePropPage.getResName(), false);
- } else {
- result = Activator
- .getDefault()
- .getResourceManager()
- .completeCollectionResourceCreationByRAML(res,
- updatePropPage.getResURI(),
- updatePropPage.getResName());
}
if (result) {
+ Utility.getSimulatorErrorString(e, null);
}
}
-
- private void createCollectionResourceWithoutRAML(boolean childResExist) {
- CollectionResource resource = new CollectionResource();
- // Basic resource details
- resource.setResourceURI(collectionResourceBasicDetailsPage.getResURI());
- resource.setResourceName(collectionResourceBasicDetailsPage
- .getResName());
- resource.setResourceTypes(collectionResourceBasicDetailsPage
- .getResTypes());
- resource.setObservable(collectionResourceBasicDetailsPage
- .isObservable());
- // resource.setStarted(simpleResourceBasicDetailsPage.isStart());
-
- // Call method of ResourceManager and update the response in the status
- // string.
- try {
- boolean result = Activator.getDefault().getResourceManager()
- .createCollectionResource(resource);
- if (result) {
- status = "Resource created";
- // Adding child resources.
- if (childResExist) {
- Set<Resource> selectedResources = addResourcesToCollectionPage
- .getSelectedResourceList();
- if (!selectedResources.isEmpty()) {
- int addedCount = Activator
- .getDefault()
- .getResourceManager()
- .addResourceToCollection(resource,
- selectedResources);
- if (addedCount > 0) {
- status += " and [" + addedCount + "/"
- + selectedResources.size()
- + "] resources added to the collection";
- } else {
- status += " but failed to add resources to the collection.";
- }
- }
- }
- createdResource = resource;
- } else {
- status = "Failed to create resource.";
- createdResource = null;
- }
- } catch (SimulatorException e) {
- status = "Failed to create resource.\n"
- + Utility.getSimulatorErrorString(e, null);
- createdResource = null;
- }
- }
-
- private Device createDevice(String deviceName, Set<Resource> childs) {
- return Activator.getDefault().getResourceManager()
- .createDevice(deviceName, childs);
- }
-
}
\ No newline at end of file
import java.util.Set;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeNodeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
*/
public class DeleteResourcePage extends WizardPage {
- private CheckboxTreeViewer collectionTreeViewer;
- private CheckboxTreeViewer singleTreeViewer;
+ private CheckboxTreeViewer singleTreeViewer;
- private List<CollectionResource> collectionSourceList;
- private List<SingleResource> singleSourceList;
+ private List<SingleResource> singleSourceList;
- private TreeViewContentHelper singleTreeViewContentHelper;
- private TreeViewContentHelper collectionTreeViewContentHelper;
+ private TreeViewContentHelper singleTreeViewContentHelper;
protected DeleteResourcePage() {
super("Delete Resources");
singleSourceList = Activator.getDefault().getResourceManager()
.getSingleResourceList();
- collectionSourceList = Activator.getDefault().getResourceManager()
- .getCollectionResourceList();
}
@Override
public void createControl(Composite parent) {
setPageComplete(false);
setTitle("Delete Resources");
- setMessage("Select one or more single and/or collection resources for deletion.");
+ setMessage("Select one or more simple resources for deletion.");
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
createSingleResourcesArea(container);
- createCollectionResourcesArea(container);
-
setControl(container);
}
private void createSingleResourcesArea(Composite container) {
Composite singleContainer = new Composite(container, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- gd.horizontalSpan = 2;
+ gd.horizontalSpan = 4;
singleContainer.setLayoutData(gd);
GridLayout layout = new GridLayout();
singleContainer.setLayout(layout);
singleTreeViewer
.setContentProvider(new SingleResourceContentProvider());
singleTreeViewer.setLabelProvider(new TreeLabelProvider());
- singleTreeViewer.setInput(new TreeContentProvider());
+ singleTreeViewer.setInput(new TreeNodeContentProvider());
singleTreeViewer.addCheckStateListener(new ICheckStateListener() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
- * (org.eclipse.jface.viewers.CheckStateChangedEvent)
- */
@Override
public void checkStateChanged(CheckStateChangedEvent e) {
Object element = e.getElement();
}
- private void createCollectionResourcesArea(Composite container) {
- Composite collectionContainer = new Composite(container, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- gd.horizontalSpan = 2;
- collectionContainer.setLayoutData(gd);
- GridLayout layout = new GridLayout();
- collectionContainer.setLayout(layout);
-
- Label lbl = new Label(collectionContainer, SWT.NONE);
- lbl.setText("Collection Resources:");
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- // gd.grabExcessHorizontalSpace = true;
- // gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(collectionContainer, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- if (null == collectionSourceList || collectionSourceList.isEmpty()) {
- return;
- }
-
- collectionTreeViewer = new CheckboxTreeViewer(resourceGroup);
- collectionTreeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
-
- collectionTreeViewer.getTree().setLayoutData(gd);
- collectionTreeViewer
- .setContentProvider(new CollectionResourceContentProvider());
- collectionTreeViewer.setLabelProvider(new TreeLabelProvider());
- collectionTreeViewer.setInput(new TreeContentProvider());
- collectionTreeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Object element = e.getElement();
- if (element instanceof TreeViewContentHelper) {
- collectionTreeViewer.setGrayed(
- collectionTreeViewContentHelper, false);
- collectionTreeViewer.setChecked(
- collectionTreeViewContentHelper, e.getChecked());
- collectionTreeViewer.setSubtreeChecked(element,
- e.getChecked());
- } else {
- Object obj[] = collectionTreeViewer.getCheckedElements();
- if (null != obj && obj.length > 0) {
- int checkedCount = obj.length;
- boolean isParentGrayed = collectionTreeViewer
- .getChecked(collectionTreeViewContentHelper);
- boolean isParentChecked = collectionTreeViewer
- .getChecked(collectionTreeViewContentHelper);
- if (isParentChecked || isParentGrayed) {
- checkedCount--;
- }
- if (checkedCount == collectionSourceList.size()) {
- collectionTreeViewer.setGrayed(
- collectionTreeViewContentHelper, false);
- collectionTreeViewer.setChecked(
- collectionTreeViewContentHelper, true);
- } else {
- if (checkedCount > 0) {
- collectionTreeViewer.setGrayed(
- collectionTreeViewContentHelper, true);
- collectionTreeViewer.setChecked(
- collectionTreeViewContentHelper, true);
- } else {
- collectionTreeViewer.setGrayed(
- collectionTreeViewContentHelper, false);
- collectionTreeViewer.setChecked(
- collectionTreeViewContentHelper, false);
- }
- }
- }
- }
- setPageComplete(isSelectionDone());
- }
- });
- collectionTreeViewer.expandAll();
- }
-
public Set<SingleResource> getSelectedSingleResourcesList() {
final Set<SingleResource> singles = new HashSet<SingleResource>();
Display.getDefault().syncExec(new Runnable() {
return singles;
}
- public Set<CollectionResource> getSelectedCollectionResourcesList() {
- final Set<CollectionResource> collections = new HashSet<CollectionResource>();
- Display.getDefault().syncExec(new Runnable() {
-
- @Override
- public void run() {
- if (null == collectionTreeViewer) {
- return;
- }
- Object selection[] = collectionTreeViewer.getCheckedElements();
- if (null == selection || selection.length < 1) {
- return;
- }
- for (Object obj : selection) {
- if (obj instanceof Resource) {
- collections.add((CollectionResource) obj);
- }
- }
- }
- });
- return collections;
- }
-
class SingleResourceContentProvider implements ITreeContentProvider {
@Override
}
}
- class CollectionResourceContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- if (parent instanceof TreeViewContentHelper) {
- return ((TreeViewContentHelper) parent).getResources()
- .toArray();
- }
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- Object obj[] = new Object[1];
- collectionTreeViewContentHelper = new TreeViewContentHelper(
- collectionSourceList);
- obj[0] = collectionTreeViewContentHelper;
- return obj;
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- if (parent instanceof TreeViewContentHelper) {
- return true;
- }
- return false;
- }
- }
-
class TreeLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
@Override
public Image getImage(Object element) {
- if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else if (element instanceof SingleResource) {
+ if (element instanceof SingleResource) {
return Activator.getDefault().getImageRegistry()
.get(Constants.SINGLE_RESOURCE);
} else {
return true;
}
}
- if (null != collectionTreeViewer) {
- Object obj[] = collectionTreeViewer.getCheckedElements();
- if (null != obj && obj.length > 0) {
- return true;
- }
- }
return false;
}
}
\ No newline at end of file
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
null);
setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
+
+ setNeedsProgressMonitor(true);
}
@Override
return false;
}
try {
- getContainer().run(true, true, new IRunnableWithProgress() {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
.getResourceManager();
try {
monitor.beginTask("Resource Deletion", 2);
- Set<CollectionResource> collectionResources = page
- .getSelectedCollectionResourcesList();
- if (null != collectionResources
- && collectionResources.size() > 0) {
- Activator
- .getDefault()
- .getResourceManager()
- .removeCollectionResources(
- collectionResources);
-
- Resource res = resourceManager
- .getCurrentResourceInSelection();
- if (null != res
- && res instanceof CollectionResource) {
- if (collectionResources
- .contains((CollectionResource) res)) {
- resourceManager
- .resourceSelectionChanged(null);
- }
- }
- }
monitor.worked(1);
Set<SingleResource> singleResources = page
.getSelectedSingleResourcesList();
+++ /dev/null
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.model.SingleResource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-public class DevicePage extends WizardPage {
-
- private CheckboxTreeViewer treeViewer;
-
- private Text deviceNameTxt;
-
- private String deviceName;
-
- Set<Resource> selectedResourceList;
-
- protected DevicePage() {
- super("Devices");
- selectedResourceList = new HashSet<Resource>();
- }
-
- @Override
- public void createControl(Composite parent) {
- setPageComplete(false);
- setTitle(Constants.CREATE_DEVICE_PAGE_TITLE);
- setMessage(Constants.CREATE_DEVICE_PAGE_MESSAGE);
-
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout gridLayout = new GridLayout(2, false);
- container.setLayout(gridLayout);
- GridData gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- container.setLayoutData(gd);
-
- Label deviceNameLbl = new Label(container, SWT.NULL);
- deviceNameLbl.setText("Device Name");
-
- deviceNameTxt = new Text(container, SWT.BORDER);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- deviceNameTxt.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Resource res = (Resource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- setUiListeners();
-
- setControl(container);
- }
-
- private void setUiListeners() {
- deviceNameTxt.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent e) {
- deviceName = deviceNameTxt.getText();
- setPageComplete(isSelectionDone());
- }
- });
- }
-
- private boolean isSelectionDone() {
- if (null != deviceName) {
- deviceName = deviceName.trim();
- }
- if (deviceName.isEmpty()) {
- return false;
- }
- return true;
- }
-
- @Override
- public IWizardPage getNextPage() {
- return null;
- }
-
- public String getDeviceName() {
- return deviceName;
- }
-
- public Set<Resource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
-}
-
-class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- List<Resource> resList;
- resList = Activator.getDefault().getResourceManager().getResourceList();
- if (null == resList) {
- resList = new ArrayList<Resource>();
- }
- return resList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
-}
-
-class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Resource res = (Resource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof SingleResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.SINGLE_RESOURCE);
- } else {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- }
- }
-}
\ No newline at end of file
import java.util.Date;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
resourceCount = -1;
}
if (null != configFilePath && configFilePath.trim().length() > 0) {
- if (typeOfResource == Type.COLLECTION) {
+ if (resourceCount == 1) {
done = true;
- } else {
- if (resourceCount == 1) {
- done = true;
- }
}
}
return done;
resourceCount = -1;
}
if (null != configFilePath && configFilePath.trim().length() > 0) {
- if (typeOfResource == Type.COLLECTION) {
+ if (resourceCount >= 1) {
done = true;
- } else {
- if (resourceCount >= 1) {
- done = true;
- }
}
}
return done;
}
public boolean isMultiResourceCreation() {
- if (typeOfResource != Type.COLLECTION && resourceCount > 1) {
+ if (typeOfResource == Type.SINGLE && resourceCount > 1) {
return true;
}
return false;
final CreateResourceWizard wizard = ((CreateResourceWizard) getWizard());
try {
- getContainer().run(true, true, new IRunnableWithProgress() {
+ getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
wizard.getWizardDialog().close();
return null;
} else {
- // Checking whether the resource is single or collection.
+ // Checking whether the resource is of type single.
Option intendedResource = wizard.getMainPage().getOption();
- if ((intendedResource == Option.SIMPLE_FROM_RAML && resource instanceof CollectionResource)) {
+ if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) {
MessageDialog
.openError(
getShell(),
"Invalid RAML",
- "Uploaded RAML is of type collection. "
+ "Uploaded RAML is not of simple type. "
+ "Please upload the proper RAML of simple type.");
return null;
- } else if (intendedResource == Option.COLLECTION_FROM_RAML
- && resource instanceof SingleResource) {
- MessageDialog
- .openError(
- getShell(),
- "Invalid RAML",
- "Uploaded RAML is of type simple. "
- + "Please upload the proper RAML of collection type.");
- return null;
}
}
UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage();
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.view.dialogs;
import oic.simulator.serviceprovider.utils.Constants;
public class MainPage extends WizardPage {
private Button simpleBtn;
- private Button collectionBtn;
private Button simpleFromRamlBtn;
- private Button collectionFromRamlBtn;
- private Button deviceBtn;
private Text description;
public enum Option {
- SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE
+ SIMPLE, SIMPLE_FROM_RAML
}
private Option option;
simpleFromRamlBtn = new Button(compContent, SWT.RADIO);
simpleFromRamlBtn.setText("Simple resource(From RAML)");
- collectionBtn = new Button(compContent, SWT.RADIO);
- collectionBtn.setText("Collection resource");
-
- collectionFromRamlBtn = new Button(compContent, SWT.RADIO);
- collectionFromRamlBtn.setText("Collection resource(From RAML)");
-
- deviceBtn = new Button(compContent, SWT.RADIO);
- deviceBtn.setText("Device");
-
Label lbl = new Label(compContent, SWT.NULL);
lbl.setText("Details:");
gd = new GridData();
getWizard().getContainer().updateButtons();
}
});
-
- collectionBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- description
- .setText("Create a collection resource by manually entering all the details given below.\n"
- + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n"
- + "\t2. Start/stop the resource.\n"
- + "\t3. Adding existing simple resources to this collection.");
- option = Option.COLLECTION;
- getWizard().getContainer().updateButtons();
- }
- });
-
- collectionFromRamlBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- description
- .setText("Create a collection resource from RAML configuration file.\n"
- + "\t1. Resource details, attributes, and other properties will be read from RAML.\n"
- + "\t2. Supports multi-instance creation.\n"
- + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n"
- + "\t4. Allows to start or stop the resource(s).");
- option = Option.COLLECTION_FROM_RAML;
- getWizard().getContainer().updateButtons();
- }
- });
-
- deviceBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- description
- .setText("Create a logical device that acts as a top-level logical classification.\n"
- + "\t1. Takes a device name for identication.\n"
- + "\t2. One or more simple and collection resources can be added to it.");
- option = Option.DEVICE;
- getWizard().getContainer().updateButtons();
- }
- });
}
@Override
public boolean canFlipToNextPage() {
- if (option != Option.NONE) {
- return true;
- }
- return false;
+ return true;
}
@Override
page.initialSetup(Type.SINGLE);
return page;
}
- if (collectionBtn.getSelection()) {
- return createWizard.getCollectionResourceBasicDetailsPage();
- }
- if (collectionFromRamlBtn.getSelection()) {
- LoadRamlPage page = createWizard.getLoadRamlPage();
- page.initialSetup(Type.COLLECTION);
- return page;
- }
- if (deviceBtn.getSelection()) {
- DevicePage page = createWizard.getDevicePage();
- return page;
- }
return null;
}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class RemoveResourceFromCollections extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<CollectionResource> sourceList;
-
- Set<CollectionResource> selectedResourceList;
-
- public RemoveResourceFromCollections(Shell parentShell,
- List<CollectionResource> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedResourceList = new HashSet<CollectionResource>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Remove from Collections");
- setMessage("Select one or more collection resources from which the simple resource will be removed.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- CollectionResource res = (CollectionResource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<CollectionResource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<CollectionResource>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- CollectionResource res = (CollectionResource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return null;
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedResourceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No resources are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class RemoveResourceFromDevices extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<Device> sourceList;
-
- Set<Device> selectedDeviceList;
-
- public RemoveResourceFromDevices(Shell parentShell, List<Device> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedDeviceList = new HashSet<Device>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Remove from Device");
- setMessage("Select one or more devices from which the simple resource will be removed.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Device res = (Device) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedDeviceList.add(res);
- System.out.println("Checked" + res.getDeviceName());
- } else {
- selectedDeviceList.remove(res);
- System.out.println("Unchecked:" + res.getDeviceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<Device> getSelectedDeviceList() {
- return selectedDeviceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<Device>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Device res = (Device) element;
- return res.getDeviceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof Device) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.DEVICE);
- } else {
- return null;
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedDeviceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No devices are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package oic.simulator.serviceprovider.view.dialogs;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.model.CollectionResource;
-import oic.simulator.serviceprovider.model.Resource;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This dialog is used for loading the RAML file.
- */
-public class RemoveResources extends TitleAreaDialog {
-
- private CheckboxTreeViewer treeViewer;
-
- List<Resource> sourceList;
-
- Set<Resource> selectedResourceList;
-
- public RemoveResources(Shell parentShell, List<Resource> sourceList) {
- super(parentShell);
- this.sourceList = sourceList;
- selectedResourceList = new HashSet<Resource>();
- }
-
- @Override
- public void create() {
- super.create();
- setTitle("Remove Resources");
- setMessage("Select one or more resources to be removed.");
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite compLayout = (Composite) super.createDialogArea(parent);
- Composite container = new Composite(compLayout, SWT.NONE);
- container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout();
- layout.verticalSpacing = 10;
- layout.marginTop = 10;
- container.setLayout(layout);
-
- Label lbl = new Label(container, SWT.NONE);
- lbl.setText("Select Resources from:");
- GridData gd;
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- lbl.setLayoutData(gd);
-
- Group resourceGroup = new Group(container, SWT.NONE);
-
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-
- resourceGroup.setLayout(new GridLayout());
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.heightHint = 300;
- gd.horizontalSpan = 2;
- resourceGroup.setLayoutData(gd);
-
- treeViewer = new CheckboxTreeViewer(resourceGroup);
- treeViewer.getTree().setBackground(color);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessVerticalSpace = true;
- gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
- treeViewer.getTree().setLayoutData(gd);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new TreeLabelProvider());
- treeViewer.setInput(new Object());
- treeViewer.addCheckStateListener(new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent e) {
- Resource res = (Resource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedResourceList.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedResourceList.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
- }
- }
- }
- });
-
- return compLayout;
- }
-
- public Set<Resource> getSelectedResourceList() {
- return selectedResourceList;
- }
-
- class TreeContentProvider implements ITreeContentProvider {
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
- }
-
- @Override
- public Object[] getChildren(Object parent) {
- return null;
- }
-
- @Override
- public Object[] getElements(Object parent) {
- if (null == sourceList) {
- sourceList = new ArrayList<Resource>();
- }
- return sourceList.toArray();
- }
-
- @Override
- public Object getParent(Object child) {
- return null;
- }
-
- @Override
- public boolean hasChildren(Object parent) {
- return false;
- }
- }
-
- class TreeLabelProvider extends LabelProvider {
- @Override
- public String getText(Object element) {
- Resource res = (Resource) element;
- return res.getResourceName();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof CollectionResource) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.COLLECTION_RESOURCE);
- } else {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.SINGLE_RESOURCE);
- }
- }
- }
-
- @Override
- protected void okPressed() {
- if (selectedResourceList.isEmpty()) {
- MessageDialog.openInformation(
- Display.getDefault().getActiveShell(),
- "No selection done.", "No resources are selected.");
- return;
- }
- close();
- }
-
- @Override
- public boolean isHelpAvailable() {
- return false;
- }
-}
package oic.simulator.serviceprovider.view.dialogs;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
-
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
.getSimpleResourceOtherDetailsPage();
SimpleResourceAddAttributePage simpleResourceAddAttributesPage = createWizard
.getSimpleResourceAddAttributePage();
- CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage = createWizard
- .getCollectionResourceBasicDetailsPage();
- AddResourcesToCollectionPage addResourcesToCollectionPage = createWizard
- .getAddResourcesToCollectionPage();
LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage();
UpdatePropertiesPage updatePropPage = createWizard
.getUpdatePropPage();
- DevicePage devPage = createWizard.getDevicePage();
IWizardPage curPage = wizard.getContainer().getCurrentPage();
IWizardPage prevPage = null;
if (curPage == loadRamlPage
- || curPage == simpleResourceBasicDetailsPage
- || curPage == collectionResourceBasicDetailsPage
- || curPage == devPage) {
+ || curPage == simpleResourceBasicDetailsPage) {
prevPage = mainPage;
} else if (curPage == updatePropPage) {
loadRamlPage.setResource(null);
prevPage = loadRamlPage;
- } else if (curPage == addResourcesToCollectionPage) {
- if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) {
- prevPage = updatePropPage;
- } else {
- prevPage = collectionResourceBasicDetailsPage;
- }
} else if (curPage == simpleResourceAddAttributesPage) {
prevPage = simpleResourceBasicDetailsPage;
} else if (curPage == simpleResourceOtherDetailsPage) {
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.view.dialogs;
import java.util.ArrayList;
createAttributeColumns(attTblViewer);
- // make lines and header visible
+ // Make lines and header visible
Table table = attTblViewer.getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
return;
}
// Opening the dialog for edit operation.
- // Passing the attribute to pre-fill the UI controls.
+ // Passing the attribute to populate UI controls with data.
Set<String> rTypes = Utility.getAttributeTypes();
AddAttributeDialog dialog = new AddAttributeDialog(Display
.getDefault().getActiveShell(), att, rTypes, attributes);
att.setAllowedValues(newAtt.getAllowedValues());
}
attTblViewer.update(att, null);
- System.out.println("Attribute data after closing edit dialog: "
- + att);
}
});
IStructuredSelection selection = (IStructuredSelection) attTblViewer
.getSelection();
if (null != selection) {
- System.out.println(selection.size());
Iterator<?> itr = selection.iterator();
while (itr.hasNext()) {
AttributeHelper att = (AttributeHelper) itr.next();
- System.out.println(att.getAttributeName());
attTblViewer.remove(att);
attributes.remove(att);
AttributeContentProvider provider = (AttributeContentProvider) attTblViewer
@Override
public void selectionChanged(SelectionChangedEvent event) {
- System.out.println("table selection changed");
remBtn.setEnabled(true);
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
-package oic.simulator.serviceprovider.view.dialogs;
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
-import java.util.HashSet;
-import java.util.Set;
+package oic.simulator.serviceprovider.view.dialogs;
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
public class SimpleResourceBasicDetailsPage extends WizardPage {
- private Text resNameTxt;
- private Text resUriTxt;
- private List resTypeslist;
- private Button addToListBtn;
- private Button remFromListBtn;
- private Button observeBtn;
- // private Button startBtn;
+ private Text resNameTxt;
+ private Text resUriTxt;
+ private Text resTypeTxt;
+ private Button observeBtn;
- private String resName;
- private String resURI;
- private Set<String> resTypes;
- private boolean observable;
-
- // private boolean start;
+ private String resName;
+ private String resURI;
+ private String resType;
+ private boolean observable;
protected SimpleResourceBasicDetailsPage() {
super("Basic Details");
- resTypes = new HashSet<String>();
}
@Override
resNameTxt = new Text(resDetGrp, SWT.BORDER);
gd = new GridData();
- // gd.widthHint = 300;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 3;
resUriTxt = new Text(resDetGrp, SWT.BORDER);
gd = new GridData();
- // gd.widthHint = 300;
gd.horizontalSpan = 3;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
resUriTxt.setLayoutData(gd);
- /*
- * Composite resTypesComp = new Composite(compContent, SWT.NONE);
- * gridLayout = new GridLayout(3, false);
- * resTypesComp.setLayout(gridLayout); gd = new GridData();
- * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
- * SWT.FILL; resTypesComp.setLayoutData(gd);
- */
-
- Label resTypesLbl = new Label(resDetGrp, SWT.NULL);
- resTypesLbl.setText(Constants.RESOURCE_TYPES);
-
- resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI
- | SWT.V_SCROLL);
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- gd.horizontalSpan = 2;
- gd.heightHint = 100;
- /* gd.widthHint = 200; */
- resTypeslist.setLayoutData(gd);
- // resTypeslist.setBackground(new Color());
- Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE);
- gridLayout = new GridLayout();
- resTypesActionsComp.setLayout(gridLayout);
- gd = new GridData();
- gd.verticalAlignment = SWT.TOP;
- /*
- * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment =
- * SWT.FILL;
- */
- resTypesActionsComp.setLayoutData(gd);
-
- addToListBtn = new Button(resTypesActionsComp, SWT.PUSH);
- addToListBtn.setText("Add");
- gd = new GridData();
- gd.widthHint = 70;
- addToListBtn.setLayoutData(gd);
+ Label resTypeLbl = new Label(resDetGrp, SWT.NULL);
+ resTypeLbl.setText(Constants.RESOURCE_TYPE);
- remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH);
- remFromListBtn.setText("Remove");
+ resTypeTxt = new Text(resDetGrp, SWT.BORDER);
gd = new GridData();
- gd.widthHint = 70;
- remFromListBtn.setLayoutData(gd);
- remFromListBtn.setEnabled(false);
+ gd.horizontalSpan = 3;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ resTypeTxt.setLayoutData(gd);
Group otherOptionsGrp = new Group(container, SWT.NONE);
otherOptionsGrp.setText("Other options");
observeBtn.setSelection(true);
observable = true;
- /*
- * startBtn = new Button(otherOptionsGrp, SWT.CHECK);
- * startBtn.setText("Start the resource immediately after creation");
- * startBtn.setSelection(true);
- */
addUiListeners();
setControl(container);
}
});
- addToListBtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- SingleTextInputDialog dialog = new SingleTextInputDialog(
- getShell(), "Add Resource Type", "Resource Type");
- if (dialog.open() == Window.OK) {
- System.out.println(dialog.getValue());
- String resType = dialog.getValue();
- // Duplicate check.
- if (resTypes.contains(resType)) {
- MessageDialog.openError(Display.getDefault()
- .getActiveShell(), "Duplicate value",
- "value already exist.");
- return;
- }
- resTypeslist.add(resType);
- resTypeslist.deselectAll();
- resTypeslist.select(resTypeslist.getItemCount() - 1);
- resTypeslist.showSelection();
- remFromListBtn.setEnabled(true);
-
- resTypes.add(resType);
-
- getWizard().getContainer().updateButtons();
- }
- }
- });
-
- remFromListBtn.addSelectionListener(new SelectionAdapter() {
+ resTypeTxt.addModifyListener(new ModifyListener() {
@Override
- public void widgetSelected(SelectionEvent e) {
- int[] selection = resTypeslist.getSelectionIndices();
- String[] selectionStr = resTypeslist.getSelection();
- if (null != selection && selection.length > 0) {
- resTypeslist.remove(selection);
- for (String selected : selectionStr) {
- resTypes.remove(selected);
- }
- }
-
- changeVisibility();
+ public void modifyText(ModifyEvent arg0) {
+ resType = resTypeTxt.getText();
getWizard().getContainer().updateButtons();
}
});
- resTypeslist.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- changeVisibility();
- }
- });
-
observeBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
});
}
- private void changeVisibility() {
- int[] selection = resTypeslist.getSelectionIndices();
- if (null != selection && selection.length > 0) {
- remFromListBtn.setEnabled(true);
- } else {
- remFromListBtn.setEnabled(false);
- }
- }
-
@Override
public boolean canFlipToNextPage() {
- if (null == resName || null == resURI || resTypes.size() < 1) {
+ if (null == resName || null == resURI || null == resType) {
return false;
}
resName = resName.trim();
resURI = resURI.trim();
- if (resName.length() < 1 || resURI.length() < 1) {
+ resType = resType.trim();
+ if (resName.length() < 1 || resURI.length() < 1 || resType.length() < 1) {
return false;
}
return true;
return resURI;
}
- public Set<String> getResTypes() {
- return resTypes;
+ public String getResType() {
+ return resType;
}
public boolean isObservable() {
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.view.dialogs;
import oic.simulator.serviceprovider.utils.Constants;
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package oic.simulator.serviceprovider.view.dialogs;
import oic.simulator.serviceprovider.utils.Constants;
@Override
public IWizardPage getNextPage() {
- System.out.println(this.getClass().getName() + ": getNextPage");
return null;
}
}
package oic.simulator.serviceprovider.view.dialogs;
-import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
-import oic.simulator.serviceprovider.view.dialogs.MainPage.Option;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@Override
public boolean canFlipToNextPage() {
- CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
- if (isSelectionDone()
- && (createWizard.getMainPage().getOption() == Option.COLLECTION_FROM_RAML)
- && Activator.getDefault().getResourceManager()
- .isAnyResourceExist()) {
- return true;
- }
return false;
}
@Override
public IWizardPage getNextPage() {
- if (null == resName || resName.trim().length() < 1) {
- MessageDialog.openError(Display.getDefault().getActiveShell(),
- "Invalid Resource Name.", "Resource name is invalid.");
- return null;
- }
-
- if (!Utility.isUriValid(resURI)) {
- MessageDialog.openError(Display.getDefault().getActiveShell(),
- "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE);
- return null;
- }
-
- CreateResourceWizard createWizard = (CreateResourceWizard) getWizard();
- // Checking whether the uri is used by any other resource.
- if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) {
- MessageDialog
- .openError(getShell(), "Resource URI in use",
- "Entered resource URI is in use. Please try a different one.");
- // TODO: Instead of MessageDialog, errors may be shown on wizard
- // itself.
- return null;
- }
- return createWizard.getAddResourcesToCollectionPage();
+ return null;
}
public void setResName(String resName) {
--- /dev/null
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog for starting and stopping the automatic verifications.
+ */
+public class UpdateResourceInterfaceDialog extends TrayDialog {
+ private Map<String, Boolean> resourceIfStatus;
+
+ public UpdateResourceInterfaceDialog(Shell shell,
+ Map<String, Boolean> resourceIfStatus) {
+ super(shell);
+ this.resourceIfStatus = resourceIfStatus;
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ createAutomationGroup(composite);
+ getShell().setText("Resource Interfaces");
+ return composite;
+ }
+
+ /**
+ * Dynamically creates a check-box list for changing the resource interface
+ * selection.
+ */
+ private void createAutomationGroup(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout());
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint = 275;
+ group.setLayoutData(gd);
+ group.setText("Resource Interfaces");
+
+ Set<String> keySet = resourceIfStatus.keySet();
+ if (null == keySet) {
+ return;
+ }
+ ArrayList<String> list = new ArrayList<String>(keySet);
+ for (final String str : list) {
+ final Button checkbox = new Button(group, SWT.CHECK);
+ checkbox.setText(str);
+ checkbox.setSelection(resourceIfStatus.get(str));
+
+ // Disabling the check-box for baseline interface.
+ if (str.contains(Constants.DEFAULT_SINGLE_RESOURCE_INTERFACE)) {
+ checkbox.setEnabled(false);
+ }
+
+ checkbox.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Button btn = (Button) e.getSource();
+ if (null == btn) {
+ return;
+ }
+ String btnText = btn.getText();
+ resourceIfStatus.put(btnText, btn.getSelection());
+ }
+ });
+ }
+ }
+
+ @Override
+ protected Button createButton(Composite parent, int id, String label,
+ boolean defaultButton) {
+ if (id == IDialogConstants.CANCEL_ID) {
+ return null;
+ }
+ return super.createButton(parent, id, label, defaultButton);
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+
+ public Map<String, Boolean> getResourceInterfaceStatus() {
+ return resourceIfStatus;
+ }
+}