1. Enhanced resource deletion UI.
2. Resolved minor issues.
3. Removed unnecessary code.
4. Added code to set the device and platform information from server linux sample.
Change-Id: I5eebd95614e0aefb221cd3b5bc9930d676b40c41
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4335
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
std::cout << "7. Stop Automation" << std::endl;
std::cout << "8. Get Observers of a resource" << std::endl;
std::cout << "9. Set Logger" << std::endl;
- std::cout << "10. Help" << std::endl;
+ std::cout << "10. Set Device Info" << std::endl;
+ std::cout << "11. Set Platform Info" << std::endl;
+ std::cout << "12. Help" << std::endl;
std::cout << "0. Exit" << std::endl;
std::cout << "######################################" << std::endl;
}
}
}
+void setDeviceInfo()
+{
+ SimulatorManager::getInstance()->setDeviceInfo("IoTivity Simulator Linux Sample");
+ std::cout << "Setting Device Info is successful" << std::endl;
+}
+
+void setPlatformInfo()
+{
+ PlatformInfo pInfo;
+ pInfo.setPlatformID("Samsung Platform Identifier");
+ pInfo.setFirmwareVersion("FirwareVersion01");
+ pInfo.setHardwareVersion("HardwareVersion01");
+ pInfo.setManufacturerName("Samsung");
+ pInfo.setManufacturerUrl("www.samsung.com");
+ pInfo.setModelNumber("Samsung Model Num01");
+ pInfo.setOSVersion("OSVersion01");
+ pInfo.setPlatformVersion("PlatformVersion01");
+ pInfo.setSupportUrl("http://www.samsung.com/support");
+ pInfo.setSystemTime("2015-09-10T11:10:30Z");
+ pInfo.setDateOfManfacture("2015-09-10T11:10:30Z");
+
+ SimulatorManager::getInstance()->setPlatformInfo(pInfo);
+ std::cout << "Setting Platform Info is successful" << std::endl;
+}
+
int main(int argc, char *argv[])
{
printMainMenu();
int choice = -1;
std::cout << "Enter your choice: ";
std::cin >> choice;
- if (choice < 0 || choice > 10)
+ if (choice < 0 || choice > 12)
{
std::cout << "Invaild choice !" << std::endl; continue;
}
case 6 : automateAttributeUpdate(); break;
case 7 : stopAutomation(); break;
case 8 : getObservers(); break;
- case 9: setLogger(); break;
- case 10: printMainMenu(); break;
+ case 9 : setLogger(); break;
+ case 10: setDeviceInfo(); break;
+ case 11: setPlatformInfo(); break;
+ case 12: printMainMenu(); break;
case 0: cont = false;
}
}
propValue = Utility.getObservableInString(resource
.getRemoteResourceRef().isObservable());
} else if (propName.equals(Constants.RESOURCE_TYPES)) {
- Vector<String> types = resource.getRemoteResourceRef()
+ Vector<String> resTypes = resource.getRemoteResourceRef()
.getResourceTypes();
- if (null != types) {
- propValue = types.toString();
+ if (null != resTypes && !resTypes.isEmpty()) {
+ propValue = "";
+ Iterator<String> itr = resTypes.iterator();
+ while (itr.hasNext()) {
+ propValue += itr.next();
+ if (itr.hasNext()) {
+ propValue += ", ";
+ }
+ }
} else {
propValue = Constants.NOT_AVAILABLE;
}
} else if (propName.equals(Constants.RESOURCE_INTERFACES)) {
Vector<String> interfaces = resource.getRemoteResourceRef()
.getResourceInterfaces();
- if (null != interfaces) {
- propValue = interfaces.toString();
+ if (null != interfaces && !interfaces.isEmpty()) {
+ propValue = "";
+ Iterator<String> itr = interfaces.iterator();
+ while (itr.hasNext()) {
+ propValue += itr.next();
+ if (itr.hasNext()) {
+ propValue += ", ";
+ }
+ }
} else {
propValue = Constants.NOT_AVAILABLE;
}
return dateFormat.format(entry.getDate());
} else {
String msg = entry.getMessage();
- int pos = msg.indexOf('\n');
- if (pos != -1) {
- msg = msg.substring(0, pos);
+ if (null != msg) {
+ int pos = msg.indexOf('\n');
+ if (pos != -1) {
+ msg = msg.substring(0, pos);
+ }
}
return msg;
}
return dateFormat.format(entry.getDate());
} else {
String msg = entry.getMessage();
- int pos = msg.indexOf('\n');
- if (pos != -1) {
- msg = msg.substring(0, pos);
+ if (null != msg) {
+ int pos = msg.indexOf('\n');
+ if (pos != -1) {
+ msg = msg.substring(0, pos);
+ }
}
return msg;
}
* Interface through which the automation events are notified to the UI
* listeners.
*/
-public interface IAutomationUIListener {
+public interface IAutomationListener {
public void onResourceAutomationStart(SingleResource resource);
public void onAutomationComplete(SingleResource resource, String attName);
-package oic.simulator.serviceprovider.model;
+package oic.simulator.serviceprovider.listener;
-public interface DataChangeListener {
+import oic.simulator.serviceprovider.model.AttributeElement;
+
+public interface IDataChangeListener {
public void add(AttributeElement attribute);
public void remove(AttributeElement attribute);
package oic.simulator.serviceprovider.listener;
-public interface IDeviceInfoUIListener {
+public interface IDeviceInfoListener {
public void onDeviceInfoFound();
}
/**
* Interface through which the log events are sent to the UI listeners.
*/
-public interface ILogUIListener {
+public interface ILogListener {
public void logAdded(LogEntry added);
public void logChanged(List<LogEntry> entry);
* Interface through which the resource observer events are sent to the UI
* listeners.
*/
-public interface IObserverListChangedUIListener {
+public interface IObserverListChangedListener {
public void onObserverListChanged(Resource resource);
}
* Interface through which the resource property change UI events are sent to
* the other UI listeners.
*/
-public interface IPropertiesChangedUIListener {
+public interface IPropertiesChangedListener {
public void onResourcePropertyChange();
public void onDevicePropertyChange();
* Interface through which the resource creation/deletion events are sent to the
* UI listeners.
*/
-public interface IResourceListChangedUIListener {
+public interface IResourceListChangedListener {
public void onResourceCreation(ResourceType type);
public void onResourceDeletion(ResourceType type);
+++ /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.listener;
-
-import oic.simulator.serviceprovider.model.Resource;
-
-/**
- * Interface through which the resource model change events are sent to the UI
- * listeners.
- */
-public interface IResourceModelChangedUIListener {
- public void onResourceModelChange(Resource resource);
-}
* Interface through which the resource selection UI event is sent to the other
* UI listeners.
*/
-public interface ISelectionChangedUIListener {
+public interface ISelectionChangedListener {
public void onResourceSelectionChange(Resource resource);
public void onDeviceSelectionChange(Device dev);
import oic.simulator.logger.LogEntry;
import oic.simulator.logger.LoggerCallback;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.ILogUIListener;
+import oic.simulator.serviceprovider.listener.ILogListener;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
*/
public class LogManager {
private LinkedList<LogEntry> entries = new LinkedList<LogEntry>();
- private ArrayList<ILogUIListener> listeners = new ArrayList<ILogUIListener>();
+ private ArrayList<ILogListener> listeners = new ArrayList<ILogListener>();
private LinkedList<LogEntry> visibleEntries = new LinkedList<LogEntry>();
private HashMap<Integer, Boolean> visibleSeverities = new HashMap<Integer, Boolean>();
}
private void notifyListeners() {
- for (ILogUIListener l : listeners) {
+ for (ILogListener l : listeners) {
l.logChanged(new ArrayList<LogEntry>(visibleEntries));
}
}
private void notifyListeners(LogEntry added) {
- for (ILogUIListener l : listeners) {
+ for (ILogListener l : listeners) {
l.logAdded(added);
}
}
}
}
- public void addLogListener(final ILogUIListener listener) {
+ public void addLogListener(final ILogListener listener) {
synchronizerThread.addToQueue(new Runnable() {
@Override
public void run() {
});
}
- public void removeLogListener(final ILogUIListener listener) {
+ public void removeLogListener(final ILogListener listener) {
synchronizerThread.addToQueue(new Runnable() {
@Override
public void run() {
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import oic.simulator.serviceprovider.model.AttributeElement;
import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.MetaProperty;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
-import oic.simulator.serviceprovider.model.SRMItem;
import oic.simulator.serviceprovider.model.SingleResource;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
Resource resource = data
.getResourceByURI(resourceURI);
if (null != resource) {
- resource.setResourceRepresentation(resourceModelN);
+ try {
+ resource.setResourceRepresentation(resourceModelN);
+ } catch (NumberFormatException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "Error while trying to update the attributes.\n"
+ + Utility
+ .getSimulatorErrorString(
+ e,
+ null));
+ }
}
}
});
final AttributeElement attribute = getAttributeWithGivenAutomationId(
resource, automationId);
if (null != attribute) {
- // Display.getDefault().asyncExec(new Runnable()
- // {
- // @Override
- // public void run() {
attribute.setAutoUpdateState(false);
- // }
- // });
resource.setAttributeAutomationInProgress(isAnyAttributeInAutomation(resource));
- // Notify the UI listeners
- /*
- * UiListenerHandler .getInstance()
- * .automationCompleteUINotification( resource,
- * attribute
- * .getSimulatorResourceAttribute().name());
- */
} else {
- // TODO: Temporarily reset the attribute
- // automation status to false for making
- // resource-level automation work after
- // attribute-level automations.
+ // Setting the attribute automation status to
+ // false.
resource.setAttributeAutomationInProgress(false);
}
}
return data.isAnyResourceExist();
}
- public boolean createSingleResource(SingleResource resource)
+ public boolean createSingleResource(SingleResource resource,
+ Map<String, SimulatorResourceAttribute> attributes)
throws SimulatorException {
if (null == resource) {
return false;
}
// 5. Add attributes.
- Map<String, LocalResourceAttribute> attributes = resource
- .getResourceAttributes();
if (null != attributes && !attributes.isEmpty()) {
- Set<String> keySet = attributes.keySet();
- Iterator<String> itr = keySet.iterator();
-
- String attName;
- LocalResourceAttribute localAtt;
- SimulatorResourceAttribute simResAtt;
-
- while (itr.hasNext()) {
- attName = itr.next();
- localAtt = attributes.get(attName);
- if (null == localAtt) {
- continue;
- }
- simResAtt = localAtt.getResourceAttributeRef();
- if (null == simResAtt) {
- continue;
- }
- jSimulatorSingleResource.addAttribute(simResAtt);
+ SimulatorResourceAttribute value;
+ for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
+ .entrySet()) {
+ value = entry.getValue();
+ if (null != value)
+ jSimulatorSingleResource.addAttribute(value);
}
// 6. Get the resource model java object reference.
resource.setResourceRepresentation(resource.getResourceModel());
}
- // 7. Register the resource with the platform.
+ // 6. Register the resource with the platform.
jSimulatorSingleResource.start();
resource.setStarted(true);
} catch (SimulatorException e) {
jSimulatorCollectionResource
.setResourceModelChangeListener(resourceModelChangeListener);
- // set resource model
+ // 5. Fetch the model and attributes.
resource.setResourceRepresentation(jSimulatorCollectionResource
- .getResourceModel());;
+ .getResourceModel());
- // 5. Register the resource with the platform.
+ // 6. Register the resource with the platform.
jSimulatorCollectionResource.start();
resource.setStarted(true);
} catch (SimulatorException e) {
.convertVectorToSet(jSimulatorSingleResource
.getInterface()));
- // 6. Register the resource with the platform.
- jSimulatorSingleResource.start();
- singleRes.setStarted(true);
-
+ // 6. Fetch the resource attributes.
singleRes.setResourceRepresentation(jResModel);
- // 7. Fetch the resource attributes.
- Map<String, LocalResourceAttribute> resourceAttributeMap;
- resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
- if (null != resourceAttributeMap) {
- singleRes.setResourceAttributes(resourceAttributeMap);
- }
+ // 7. Register the resource with the platform.
+ jSimulatorSingleResource.start();
+ singleRes.setStarted(true);
// 8. Add to local cache.
data.addResource(singleRes);
if (!multiInstance)
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.SINGLE);
- } catch (SimulatorException e) {
+ } catch (Exception e) {
Activator
.getDefault()
.getLogManager()
if (null == resource || !(resource instanceof CollectionResource)) {
return false;
}
- try {
- CollectionResource collectionRes = (CollectionResource) resource;
- SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) resource
+ CollectionResource collectionRes = (CollectionResource) resource;
+
+ SimulatorCollectionResource jSimulatorCollectionResource = null;
+
+ try {
+ jSimulatorCollectionResource = (SimulatorCollectionResource) resource
.getSimulatorResource();
if (null == jSimulatorCollectionResource) {
return false;
collectionRes.setObservable(true);
}
- // 6. Register the resource with the platform.
- jSimulatorCollectionResource.start();
- collectionRes.setStarted(true);
-
+ // 6. Fetch the resource attributes.
collectionRes.setResourceRepresentation(jResModel);
- // 7. Fetch the resource attributes.
- Map<String, LocalResourceAttribute> resourceAttributeMap;
- resourceAttributeMap = fetchResourceAttributesFromModel(jResModel);
- if (null != resourceAttributeMap) {
- collectionRes.setResourceAttributes(resourceAttributeMap);
- }
+ // 7. Register the resource with the platform.
+ jSimulatorCollectionResource.start();
+ collectionRes.setStarted(true);
- // 6. Add to local cache.
+ // 8. Add to local cache.
data.addResource(collectionRes);
- // 7. Update UI listeners for single instance creation
+ // 9. Update UI listeners for single instance creation
UiListenerHandler.getInstance().resourceCreatedUINotification(
ResourceType.COLLECTION);
- } catch (SimulatorException e) {
+ } catch (Exception e) {
Activator
.getDefault()
.getLogManager()
return dev;
}
- private Map<String, LocalResourceAttribute> fetchResourceAttributesFromModel(
- SimulatorResourceModel jResModel) throws SimulatorException {
- Map<String, LocalResourceAttribute> resourceAttributeMap = null;
- if (null != jResModel) {
- Map<String, SimulatorResourceAttribute> jAttributeMap;
- jAttributeMap = jResModel.getAttributes();
- if (null != jAttributeMap) {
- resourceAttributeMap = new HashMap<String, LocalResourceAttribute>();
- Iterator<String> itr = jAttributeMap.keySet().iterator();
- String attName;
- SimulatorResourceAttribute jResAtt;
- LocalResourceAttribute localAtt;
- while (itr.hasNext()) {
- attName = itr.next();
- if (null != attName) {
- jResAtt = jAttributeMap.get(attName);
- if (null != jResAtt) {
- localAtt = new LocalResourceAttribute();
-
- localAtt.setResourceAttributeRef(jResAtt);
-
- // Initially disabling the automation
- localAtt.setAutomationInProgress(false);
-
- // Assigning the default automation interval
- localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
-
- // Setting the default automation type
- localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
-
- resourceAttributeMap.put(attName, localAtt);
- }
- }
- }
- }
- }
- return resourceAttributeMap;
-
- }
-
public List<Resource> getResourceList() {
List<Resource> resourceList = data.getResources();
if (null == resourceList) {
} else if (propName.equals(Constants.RESOURCE_URI)) {
propValue = resource.getResourceURI();
} else if (propName.equals(Constants.RESOURCE_TYPE)) {
- propValue = resource.getResourceTypes().toString();
+ 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;
+ }
} else {
propValue = null;
}
return true;
}
- public List<LocalResourceAttribute> getAttributes(Resource resource) {
- List<LocalResourceAttribute> attList = null;
- if (null != resource) {
- Map<String, LocalResourceAttribute> attMap = resource
- .getResourceAttributes();
- if (null != attMap && attMap.size() > 0) {
- attList = new ArrayList<LocalResourceAttribute>();
- Set<String> attNameSet = attMap.keySet();
- String attName;
- LocalResourceAttribute attribute;
- Iterator<String> attNameItr = attNameSet.iterator();
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- attribute = attMap.get(attName);
- if (null != attribute) {
- attList.add(attribute);
- }
- }
- }
- }
- return attList;
- }
-
- public List<SimulatorResourceAttribute> getAttributes(
- SimulatorResourceModel model) {
- List<SimulatorResourceAttribute> attList = null;
- if (null != model) {
- Map<String, SimulatorResourceAttribute> attMap = model
- .getAttributes();
- if (null != attMap && attMap.size() > 0) {
- attList = new ArrayList<SimulatorResourceAttribute>();
- Set<String> attNameSet = attMap.keySet();
- String attName;
- SimulatorResourceAttribute attribute;
- Iterator<String> attNameItr = attNameSet.iterator();
- while (attNameItr.hasNext()) {
- attName = attNameItr.next();
- attribute = attMap.get(attName);
- if (null != attribute) {
- attList.add(attribute);
- }
- }
- }
- }
- return attList;
- }
-
- public List<SRMItem> getIndexedAttributes(SimulatorResourceModel[] model) {
- List<SRMItem> indexedAttList = null;
- if (null != model && model.length > 0) {
- indexedAttList = new ArrayList<SRMItem>();
- int i = 0;
- for (SimulatorResourceModel m : model) {
- indexedAttList.add(new SRMItem(i++, m));
- }
- }
- return indexedAttList;
- }
-
public void attributeValueUpdated(SingleResource resource,
String attributeName, AttributeValue value) {
if (null != resource && null != attributeName && null != value) {
return resource.isAttributeAutomationInProgress();
}
- public LocalResourceAttribute getAttributeByResourceURI(
- SingleResource resource, String attName) {
- if (null == resource || null == attName) {
- return null;
- }
- Map<String, LocalResourceAttribute> attMap = resource
- .getResourceAttributes();
- if (null == attMap) {
- return null;
- }
- return attMap.get(attName);
- }
-
public void notifyObserverRequest(Resource resource, int observerId) {
if (null == resource) {
return;
import java.util.Iterator;
import java.util.List;
-import oic.simulator.serviceprovider.listener.IAutomationUIListener;
-import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
-import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
-import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
-import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.IAutomationListener;
+import oic.simulator.serviceprovider.listener.IDataChangeListener;
+import oic.simulator.serviceprovider.listener.IDeviceInfoListener;
+import oic.simulator.serviceprovider.listener.IObserverListChangedListener;
+import oic.simulator.serviceprovider.listener.IPropertiesChangedListener;
+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;
public class UiListenerHandler {
- private static UiListenerHandler uiHandler;
+ private static UiListenerHandler uiHandler;
- private List<IResourceListChangedUIListener> resourceListChangedUIListeners;
+ private List<IResourceListChangedListener> resourceListChangedUIListeners;
- private List<ISelectionChangedUIListener> selectionChangedUIListeners;
+ private List<ISelectionChangedListener> selectionChangedUIListeners;
- private List<IResourceModelChangedUIListener> resourceModelChangedUIListeners;
+ private List<IAutomationListener> automationUIListeners;
- private List<IAutomationUIListener> automationUIListeners;
+ private List<IObserverListChangedListener> observerUIListeners;
- private List<IObserverListChangedUIListener> observerUIListeners;
+ private List<IPropertiesChangedListener> propertiesChangedUIListeners;
- private List<IPropertiesChangedUIListener> propertiesChangedUIListeners;
+ private List<IDeviceInfoListener> deviceInfoUIListeners;
- private List<IDeviceInfoUIListener> deviceInfoUIListeners;
+ private List<IDataChangeListener> dataChangeListeners;
private UiListenerHandler() {
- resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
- selectionChangedUIListeners = new ArrayList<ISelectionChangedUIListener>();
- resourceModelChangedUIListeners = new ArrayList<IResourceModelChangedUIListener>();
- automationUIListeners = new ArrayList<IAutomationUIListener>();
- observerUIListeners = new ArrayList<IObserverListChangedUIListener>();
- propertiesChangedUIListeners = new ArrayList<IPropertiesChangedUIListener>();
- deviceInfoUIListeners = new ArrayList<IDeviceInfoUIListener>();
+ resourceListChangedUIListeners = new ArrayList<IResourceListChangedListener>();
+ selectionChangedUIListeners = new ArrayList<ISelectionChangedListener>();
+ automationUIListeners = new ArrayList<IAutomationListener>();
+ observerUIListeners = new ArrayList<IObserverListChangedListener>();
+ propertiesChangedUIListeners = new ArrayList<IPropertiesChangedListener>();
+ deviceInfoUIListeners = new ArrayList<IDeviceInfoListener>();
+ dataChangeListeners = new ArrayList<IDataChangeListener>();
}
public static UiListenerHandler getInstance() {
}
public void addResourceListChangedUIListener(
- IResourceListChangedUIListener resourceListChangedUIListener) {
+ IResourceListChangedListener resourceListChangedUIListener) {
synchronized (resourceListChangedUIListeners) {
resourceListChangedUIListeners.add(resourceListChangedUIListener);
}
}
public void addResourceSelectionChangedUIListener(
- ISelectionChangedUIListener resourceSelectionChangedUIListener) {
+ ISelectionChangedListener resourceSelectionChangedUIListener) {
synchronized (selectionChangedUIListeners) {
selectionChangedUIListeners.add(resourceSelectionChangedUIListener);
}
}
- public void addResourceModelChangedUIListener(
- IResourceModelChangedUIListener resourceModelChangedUIListener) {
- synchronized (resourceModelChangedUIListeners) {
- resourceModelChangedUIListeners.add(resourceModelChangedUIListener);
- }
- }
-
- public void addAutomationUIListener(
- IAutomationUIListener automationUIListener) {
+ public void addAutomationUIListener(IAutomationListener automationUIListener) {
synchronized (automationUIListeners) {
automationUIListeners.add(automationUIListener);
}
}
public void addObserverListChangedUIListener(
- IObserverListChangedUIListener observerListChangedUIListener) {
+ IObserverListChangedListener observerListChangedUIListener) {
synchronized (observerUIListeners) {
observerUIListeners.add(observerListChangedUIListener);
}
}
public void addResourcePropertiesChangedUIListener(
- IPropertiesChangedUIListener resourcePropertiesChangedUIListener) {
+ IPropertiesChangedListener resourcePropertiesChangedUIListener) {
synchronized (propertiesChangedUIListeners) {
propertiesChangedUIListeners
.add(resourcePropertiesChangedUIListener);
}
}
+ public void addDataChangeListener(IDataChangeListener dataChangeListener) {
+ synchronized (dataChangeListeners) {
+ dataChangeListeners.add(dataChangeListener);
+ }
+ }
+
public void removeResourceListChangedUIListener(
- IResourceListChangedUIListener listener) {
+ IResourceListChangedListener listener) {
synchronized (resourceListChangedUIListeners) {
if (null != listener && resourceListChangedUIListeners.size() > 0) {
resourceListChangedUIListeners.remove(listener);
}
public void removeResourceSelectionChangedUIListener(
- ISelectionChangedUIListener listener) {
+ ISelectionChangedListener listener) {
synchronized (selectionChangedUIListeners) {
if (null != listener && selectionChangedUIListeners.size() > 0) {
selectionChangedUIListeners.remove(listener);
}
}
- public void removeResourceModelChangedUIListener(
- IResourceModelChangedUIListener listener) {
- synchronized (resourceModelChangedUIListeners) {
- if (null != listener && resourceModelChangedUIListeners.size() > 0) {
- resourceModelChangedUIListeners.remove(listener);
- }
- }
- }
-
- public void removeAutomationUIListener(IAutomationUIListener listener) {
+ public void removeAutomationUIListener(IAutomationListener listener) {
synchronized (automationUIListeners) {
if (null != listener && automationUIListeners.size() > 0) {
automationUIListeners.remove(listener);
}
public void removeObserverListChangedUIListener(
- IObserverListChangedUIListener listener) {
+ IObserverListChangedListener listener) {
synchronized (observerUIListeners) {
if (null != listener && observerUIListeners.size() > 0) {
observerUIListeners.remove(listener);
}
public void removeResourcePropertiesChangedUIListener(
- IPropertiesChangedUIListener resourcePropertiesChangedUIListener) {
+ IPropertiesChangedListener resourcePropertiesChangedUIListener) {
synchronized (propertiesChangedUIListeners) {
propertiesChangedUIListeners
.remove(resourcePropertiesChangedUIListener);
}
}
- public void addDeviceInfoUIListener(IDeviceInfoUIListener deviceUIListener) {
+ public void removeDataChangeListener(IDataChangeListener dataChangeListener) {
+ synchronized (dataChangeListeners) {
+ dataChangeListeners.remove(dataChangeListener);
+ }
+ }
+
+ public void addDeviceInfoUIListener(IDeviceInfoListener deviceUIListener) {
synchronized (deviceInfoUIListeners) {
deviceInfoUIListeners.add(deviceUIListener);
}
}
public void removeDeviceInfoUIListener(
- IDeviceInfoUIListener platformUIListener) {
+ IDeviceInfoListener platformUIListener) {
synchronized (deviceInfoUIListeners) {
deviceInfoUIListeners.remove(platformUIListener);
}
public void resourceCreatedUINotification(ResourceType type) {
synchronized (resourceListChangedUIListeners) {
if (resourceListChangedUIListeners.size() > 0) {
- IResourceListChangedUIListener listener;
- Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+ IResourceListChangedListener listener;
+ Iterator<IResourceListChangedListener> listenerItr = resourceListChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void resourceDeletedUINotification(ResourceType type) {
synchronized (resourceListChangedUIListeners) {
if (resourceListChangedUIListeners.size() > 0) {
- IResourceListChangedUIListener listener;
- Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+ IResourceListChangedListener listener;
+ Iterator<IResourceListChangedListener> listenerItr = resourceListChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void resourceListUpdateUINotification(ResourceType type) {
synchronized (resourceListChangedUIListeners) {
if (resourceListChangedUIListeners.size() > 0) {
- IResourceListChangedUIListener listener;
- Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+ IResourceListChangedListener listener;
+ Iterator<IResourceListChangedListener> listenerItr = resourceListChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void resourceSelectionChangedUINotification(Resource resource) {
synchronized (selectionChangedUIListeners) {
if (selectionChangedUIListeners.size() > 0) {
- ISelectionChangedUIListener listener;
- Iterator<ISelectionChangedUIListener> listenerItr = selectionChangedUIListeners
+ ISelectionChangedListener listener;
+ Iterator<ISelectionChangedListener> listenerItr = selectionChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void deviceSelectionChangedUINotification(Device dev) {
synchronized (selectionChangedUIListeners) {
if (selectionChangedUIListeners.size() > 0) {
- ISelectionChangedUIListener listener;
- Iterator<ISelectionChangedUIListener> listenerItr = selectionChangedUIListeners
+ ISelectionChangedListener listener;
+ Iterator<ISelectionChangedListener> listenerItr = selectionChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
}
}
- public void resourceModelChangedUINotification(Resource resource) {
- synchronized (resourceModelChangedUIListeners) {
- if (resourceModelChangedUIListeners.size() > 0 && null != resource) {
- IResourceModelChangedUIListener listener;
- Iterator<IResourceModelChangedUIListener> listenerItr = resourceModelChangedUIListeners
+ public void attributeUpdatedUINotification(AttributeElement attribute) {
+ synchronized (dataChangeListeners) {
+ if (dataChangeListeners.size() > 0 && null != attribute) {
+ IDataChangeListener listener;
+ Iterator<IDataChangeListener> listenerItr = dataChangeListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.update(attribute);
+ }
+ }
+ }
+ }
+ }
+
+ public void attributeAddedUINotification(AttributeElement attribute) {
+ synchronized (dataChangeListeners) {
+ if (dataChangeListeners.size() > 0 && null != attribute) {
+ IDataChangeListener listener;
+ Iterator<IDataChangeListener> listenerItr = dataChangeListeners
+ .iterator();
+ while (listenerItr.hasNext()) {
+ listener = listenerItr.next();
+ if (null != listener) {
+ listener.add(attribute);
+ }
+ }
+ }
+ }
+ }
+
+ public void attributeRemovedUINotification(AttributeElement attribute) {
+ synchronized (dataChangeListeners) {
+ if (dataChangeListeners.size() > 0 && null != attribute) {
+ IDataChangeListener listener;
+ Iterator<IDataChangeListener> listenerItr = dataChangeListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
if (null != listener) {
- listener.onResourceModelChange(resource);
+ listener.remove(attribute);
}
}
}
public void resourceAutomationStartedUINotification(SingleResource resource) {
synchronized (automationUIListeners) {
if (automationUIListeners.size() > 0 && null != resource) {
- IAutomationUIListener listener;
- Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+ IAutomationListener listener;
+ Iterator<IAutomationListener> listenerItr = automationUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
String attName) {
synchronized (automationUIListeners) {
if (automationUIListeners.size() > 0 && null != resource) {
- IAutomationUIListener listener;
- Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+ IAutomationListener listener;
+ Iterator<IAutomationListener> listenerItr = automationUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void observerListChangedUINotification(Resource resource) {
synchronized (observerUIListeners) {
if (observerUIListeners.size() > 0 && null != resource) {
- IObserverListChangedUIListener listener;
- Iterator<IObserverListChangedUIListener> listenerItr = observerUIListeners
+ IObserverListChangedListener listener;
+ Iterator<IObserverListChangedListener> listenerItr = observerUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void propertiesChangedUINotification(Class<?> targetClass) {
synchronized (propertiesChangedUIListeners) {
if (propertiesChangedUIListeners.size() > 0) {
- IPropertiesChangedUIListener listener;
- Iterator<IPropertiesChangedUIListener> listenerItr = propertiesChangedUIListeners
+ IPropertiesChangedListener listener;
+ Iterator<IPropertiesChangedListener> listenerItr = propertiesChangedUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
public void deviceInfoReceivedNotification() {
synchronized (deviceInfoUIListeners) {
if (deviceInfoUIListeners.size() > 0) {
- IDeviceInfoUIListener listener;
- Iterator<IDeviceInfoUIListener> listenerItr = deviceInfoUIListeners
+ IDeviceInfoListener listener;
+ Iterator<IDeviceInfoListener> listenerItr = deviceInfoUIListeners
.iterator();
while (listenerItr.hasNext()) {
listener = listenerItr.next();
import java.util.HashMap;
import java.util.Map;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
+import oic.simulator.serviceprovider.utils.Constants;
+
import org.oic.simulator.AttributeValue;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
-import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
-import oic.simulator.serviceprovider.utils.Constants;
-
public class AttributeElement {
private Object mParent = null;
private SimulatorResourceAttribute mAttribute = null;
private Map<String, AttributeElement> mChildAttributes = new HashMap<String, AttributeElement>();
- private DataChangeListener mListener = null;
private boolean mAutoUpdateSupport = false;
private int mAutoUpdateId = -1;
private boolean mAutoUpdateState = false;
private AutoUpdateType mAutoUpdateType = Constants.DEFAULT_AUTOMATION_TYPE;
public AttributeElement(Object parent,
- SimulatorResourceAttribute attribute, boolean autoUpdateSupport) {
+ SimulatorResourceAttribute attribute, boolean autoUpdateSupport)
+ throws NullPointerException {
mParent = parent;
mAttribute = attribute;
mAutoUpdateSupport = autoUpdateSupport;
SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
.value().get();
for (Map.Entry<String, SimulatorResourceAttribute> entrySet : resModel
- .getAttributes().entrySet())
+ .getAttributes().entrySet()) {
mChildAttributes.put(entrySet.getKey(), new AttributeElement(
this, entrySet.getValue(), false));
+ }
} else if (typeInfo.mType == AttributeValue.ValueType.ARRAY) {
mAutoUpdateSupport = false;
if (typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
public void setAutoUpdateState(boolean state) {
if (mAutoUpdateState != state) {
mAutoUpdateState = state;
- if (mListener != null)
- mListener.update(this);
+
+ UiListenerHandler.getInstance()
+ .attributeUpdatedUINotification(this);
}
}
return (null == mAttribute.property());
}
- public void setListener(DataChangeListener listener) {
- mListener = listener;
- for (Map.Entry<String, AttributeElement> entry : mChildAttributes
- .entrySet())
- entry.getValue().setListener(listener);
- }
-
- public DataChangeListener getListener() {
- return mListener;
- }
-
public void update(SimulatorResourceAttribute attribute) {
if (attribute == null)
return;
AttributeElement newAttribute = new AttributeElement(this,
entry.getValue(), false);
mChildAttributes.put(entry.getKey(), newAttribute);
- if (mListener != null)
- mListener.add(newAttribute);
+
+ UiListenerHandler.getInstance()
+ .attributeAddedUINotification(newAttribute);
}
}
} else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
newAttribute);
- if (mListener != null)
- mListener.add(newAttribute);
+ UiListenerHandler.getInstance()
+ .attributeAddedUINotification(newAttribute);
}
}
}
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
newAttribute);
- if (mListener != null)
- mListener.add(newAttribute);
+ UiListenerHandler.getInstance()
+ .attributeAddedUINotification(newAttribute);
}
}
}
this, indexAttribute, false);
mChildAttributes.put("[" + Integer.toString(i) + "]",
newAttribute);
- if (mListener != null)
- mListener.add(newAttribute);
+ UiListenerHandler.getInstance()
+ .attributeAddedUINotification(newAttribute);
}
}
}
attribute.value()).toString();
if (!currentValue.equals(newValue)) {
mAttribute = attribute;
- if (mListener != null)
- mListener.update(this);
+ UiListenerHandler.getInstance().attributeUpdatedUINotification(
+ this);
}
}
}
return false;
}
- public LocalResourceAttribute convertToLocalResourceAttribute() {
- LocalResourceAttribute attribute = new LocalResourceAttribute();
-
- // Initially disabling the automation
- attribute.setAutomationInProgress(false);
-
- // Assigning the default automation interval
- attribute
- .setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
-
- // Setting the default automation type
- attribute.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
-
+ public SimulatorResourceAttribute convertToSimulatorResourceAttribute() {
AttributeValue attValue = null;
AttributeProperty attProperty = null;
SimulatorResourceAttribute simResAtt;
}
simResAtt = new SimulatorResourceAttribute(attributeName, attValue,
attProperty);
- attribute.setResourceAttributeRef(simResAtt);
- return attribute;
+ return simResAtt;
}
}
\ 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 org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.server.SimulatorResource.AutoUpdateType;
-
-/**
- * This class represents an attribute in the simulated resource.
- */
-public class LocalResourceAttribute {
-
- // Java SDK object reference
- private SimulatorResourceAttribute resourceAttributeRef;
-
- private int automationId;
-
- private boolean automationInProgress;
-
- private int automationUpdateInterval;
-
- private AutoUpdateType automationType;
-
- public SimulatorResourceAttribute getResourceAttributeRef() {
- return resourceAttributeRef;
- }
-
- public void setResourceAttributeRef(
- SimulatorResourceAttribute resourceAttribute) {
- this.resourceAttributeRef = resourceAttribute;
- }
-
- public int getAutomationId() {
- return automationId;
- }
-
- public void setAutomationId(int automationId) {
- this.automationId = automationId;
- }
-
- public boolean isAutomationInProgress() {
- return automationInProgress;
- }
-
- public void setAutomationInProgress(boolean automationInProgress) {
- this.automationInProgress = automationInProgress;
- }
-
- public int getAutomationUpdateInterval() {
- return automationUpdateInterval;
- }
-
- public void setAutomationUpdateInterval(int automationUpdateInterval) {
- this.automationUpdateInterval = automationUpdateInterval;
- }
-
- public AutoUpdateType getAutomationType() {
- return automationType;
- }
-
- public void setAutomationType(AutoUpdateType automationType) {
- this.automationType = automationType;
- }
-}
\ No newline at end of file
public abstract class Resource {
// Java SDK object reference
- SimulatorResource simulatorResource;
- private SimulatorResourceModel resourceModel;
- private ResourceRepresentation mResourceRepresentation;
+ SimulatorResource simulatorResource;
+ private SimulatorResourceModel resourceModel;
+ private ResourceRepresentation mResourceRepresentation;
- private String resourceURI;
- private String resourceName;
- private Set<String> resourceTypes;
- private Set<String> resourceInterfaces;
- private boolean started;
- private boolean observable;
+ private String resourceURI;
+ private String resourceName;
+ private Set<String> resourceTypes;
+ private Set<String> resourceInterfaces;
+ private boolean started;
+ private boolean observable;
- private Set<Device> deviceMembership;
+ private Set<Device> deviceMembership;
- private Map<String, LocalResourceAttribute> attributes;
-
- private Map<Integer, ObserverDetail> observers;
+ private Map<Integer, ObserverDetail> observers;
public Resource() {
resourceTypes = new HashSet<String>();
return true;
}
- public Map<String, LocalResourceAttribute> getResourceAttributes() {
- return attributes;
- }
-
- public void setResourceAttributes(
- Map<String, LocalResourceAttribute> attributes) {
- this.attributes = attributes;
- }
-
- public void setResourceRepresentation(SimulatorResourceModel resModel) {
+ public void setResourceRepresentation(SimulatorResourceModel resModel)
+ throws NullPointerException {
if (mResourceRepresentation == null)
mResourceRepresentation = new ResourceRepresentation(resModel);
else
import java.util.HashMap;
import java.util.Map;
+import oic.simulator.serviceprovider.manager.UiListenerHandler;
+
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
public class ResourceRepresentation {
- private DataChangeListener mListener = null;
private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
- public ResourceRepresentation(SimulatorResourceModel resourceModel) {
+ public ResourceRepresentation(SimulatorResourceModel resourceModel)
+ throws NullPointerException {
if (resourceModel != null && resourceModel.size() > 0) {
for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
- .getAttributes().entrySet())
+ .getAttributes().entrySet()) {
mAttributes.put(entry.getKey(), new AttributeElement(this,
entry.getValue(), true));
+ }
}
}
return mAttributes;
}
- public void setListener(DataChangeListener listener) {
- mListener = listener;
- for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet())
- entry.getValue().setListener(listener);
- }
-
- public DataChangeListener getListener() {
- return mListener;
- }
-
public void update(SimulatorResourceModel resourceModel) {
if (null == resourceModel)
return;
AttributeElement newAttribute = new AttributeElement(this,
entry.getValue(), true);
mAttributes.put(entry.getKey(), newAttribute);
- if (mListener != null)
- mListener.add(newAttribute);
+
+ UiListenerHandler.getInstance().attributeAddedUINotification(
+ newAttribute);
}
}
}
+++ /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 org.oic.simulator.SimulatorResourceModel;
-
-public class SRMItem {
- private int index;
- private SimulatorResourceModel model;
-
- public SRMItem(int index, SimulatorResourceModel model) {
- this.index = index;
- this.model = model;
- }
-
- public int getIndex() {
- return index;
- }
-
- public void setIndex(int index) {
- this.index = index;
- }
-
- public SimulatorResourceModel getModel() {
- return model;
- }
-
- public void setModel(SimulatorResourceModel model) {
- this.model = model;
- }
-}
this.m_resourceAttributesMap = resourceAttributesMap;
}
- public void serialize(String filePath) throws SimulatorPluginException {
- try {
- FileOutputStream fileOut = new FileOutputStream(filePath);
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(this);
- out.close();
- fileOut.close();
- } catch (IOException i) {
- throw new SimulatorPluginException(
- "Failed to Serialize data : IOException");
- }
+ public void serialize(String filePath) throws IOException {
+ FileOutputStream fileOut = new FileOutputStream(filePath);
+ ObjectOutputStream out = new ObjectOutputStream(fileOut);
+ out.writeObject(this);
+ out.close();
+ fileOut.close();
}
public static SerializedServiceProvider deSerialize(String filePath)
- throws SimulatorPluginException {
+ throws Exception {
SerializedServiceProvider r = null;
- try {
- FileInputStream fileIn = new FileInputStream(filePath);
- ObjectInputStream in = new ObjectInputStream(fileIn);
- r = (SerializedServiceProvider) in.readObject();
- in.close();
- fileIn.close();
- } catch (IOException i) {
- throw new SimulatorPluginException(
- "Failed to DeSerialize data : IOException");
- } catch (ClassNotFoundException c) {
- throw new SimulatorPluginException(
- "Failed to DeSerialize data : ClassNotFound");
- }
+ FileInputStream fileIn = new FileInputStream(filePath);
+ ObjectInputStream in = new ObjectInputStream(fileIn);
+ r = (SerializedServiceProvider) in.readObject();
+ in.close();
+ fileIn.close();
return r;
}
+++ /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;
-
-/**
- * This class represents the plug-in level exceptions.
- */
-@SuppressWarnings("serial")
-public class SimulatorPluginException extends Exception {
- String msg;
-
- public SimulatorPluginException(String msg) {
- this.msg = msg;
- }
-
- public String toString() {
- return msg;
- }
-}
import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.SingleResource;
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.SimulatorException;
-import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
/**
* This class has common utility methods.
if (null == e) {
return null;
}
- String detail;
+ String detail = "";
if (e instanceof SimulatorException) {
SimulatorException simEx = (SimulatorException) e;
detail = simEx.message() + "\n";
+ "\n";
detail += "Error code: " + simEx.code().toString();
} else {
- detail = info + "\n";
+ if (null != info && !info.isEmpty())
+ detail = info + "\n";
+ else
+ detail = "Description not available\n";
detail += "Exception Type: " + e.getClass().getSimpleName() + "\n";
- detail += "Message: " + e.getMessage();
+ String msg = e.getMessage();
+ if (null != msg && !msg.isEmpty()) {
+ detail += "Message: " + e.getMessage();
+ }
}
return detail;
}
}
}
- public static List<LocalResourceAttribute> getDummyAttributes() {
- List<LocalResourceAttribute> attributes = null;
- attributes = new ArrayList<LocalResourceAttribute>();
-
- // Integer attribute
- SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
- "integer", new AttributeValue(2), null);
- attributes.add(addAttribute(attribute));
-
- // Boolean attribute
- attribute = new SimulatorResourceAttribute("boolean",
- new AttributeValue(false), null);
- attributes.add(addAttribute(attribute));
-
- // String attribute
- attribute = new SimulatorResourceAttribute("string",
- new AttributeValue("india"), null);
- attributes.add(addAttribute(attribute));
-
- // Integer array attribute
- int iarr[] = { 1, 2, 3 };
- attribute = new SimulatorResourceAttribute("integerArr",
- new AttributeValue(iarr), null);
- attributes.add(addAttribute(attribute));
-
- // Double array attribute
- double darr[] = { 1.5, 2.51, 3.15 };
- attribute = new SimulatorResourceAttribute("doubleArr",
- new AttributeValue(darr), null);
- attributes.add(addAttribute(attribute));
-
- // Boolean array attribute
- boolean barr[] = { false, true, false };
- attribute = new SimulatorResourceAttribute("boolArr",
- new AttributeValue(barr), null);
- attributes.add(addAttribute(attribute));
-
- // String array attribute
- String sarr[] = { "senthil", "muruga", "sriram" };
- attribute = new SimulatorResourceAttribute("stringArr",
- new AttributeValue(sarr), null);
- attributes.add(addAttribute(attribute));
-
- // Model type complex attribute
- attribute = new SimulatorResourceAttribute("subAtt1",
- new AttributeValue("chennai"), null);
- SimulatorResourceModel model = new SimulatorResourceModel();
- try {
- model.addAttribute(attribute);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- attribute = new SimulatorResourceAttribute("subAtt2",
- new AttributeValue("madurai"), null);
- try {
- model.addAttribute(attribute);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- SimulatorResourceModel subModel = new SimulatorResourceModel();
- try {
- subModel.addAttribute(attribute);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- attribute = new SimulatorResourceAttribute("modelsubAtt3",
- new AttributeValue(subModel), null);
- try {
- model.addAttribute(attribute);
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- SimulatorResourceAttribute modelAtt = new SimulatorResourceAttribute(
- "modelAtt1", new AttributeValue(model));
- attributes.add(addAttribute(modelAtt));
-
- // 1-D array of model
- attribute = new SimulatorResourceAttribute("subAtt1",
- new AttributeValue("chennai"), null);
- SimulatorResourceModel[] modelArr = new SimulatorResourceModel[2];
- model = new SimulatorResourceModel();
- try {
- model.addAttribute(attribute);
- modelArr[0] = model;
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- attribute = new SimulatorResourceAttribute("subAtt2",
- new AttributeValue("madurai"), null);
- model = new SimulatorResourceModel();
- try {
- model.addAttribute(attribute);
- modelArr[1] = model;
- } catch (InvalidArgsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- modelAtt = new SimulatorResourceAttribute("modelAtt2",
- new AttributeValue(modelArr));
- attributes.add(addAttribute(modelAtt));
-
- return attributes;
- }
-
- private static LocalResourceAttribute addAttribute(
- SimulatorResourceAttribute att) {
- LocalResourceAttribute localAtt = new LocalResourceAttribute();
-
- localAtt = new LocalResourceAttribute();
-
- localAtt.setResourceAttributeRef(att);
-
- // Initially disabling the automation
- localAtt.setAutomationInProgress(false);
-
- // Assigning the default automation interval
- localAtt.setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
-
- // Setting the default automation type
- localAtt.setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
-
- return localAtt;
- }
-
public static boolean isUriValid(String resURI) {
if (null == resURI || resURI.length() < 2 || !resURI.startsWith("/")
|| resURI.contains("//") || resURI.contains("?")
package oic.simulator.serviceprovider.view;
-import java.util.List;
-
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IAutomationUIListener;
-import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
-import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.IAutomationListener;
+import oic.simulator.serviceprovider.listener.IDataChangeListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AttributeElement;
-import oic.simulator.serviceprovider.model.DataChangeListener;
import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceRepresentation;
import oic.simulator.serviceprovider.model.SingleResource;
*/
public class AttributeView extends ViewPart {
- public static final String VIEW_ID = "oic.simulator.serviceprovider.view.attribute";
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.attribute";
- private TreeViewer attViewer;
+ private TreeViewer attViewer;
- private AttributeEditingSupport attributeEditor;
+ private AttributeEditingSupport attributeEditor;
- private ISelectionChangedUIListener resourceSelectionChangedListener;
- private IResourceModelChangedUIListener resourceModelChangedUIListener;
- private IAutomationUIListener automationUIListener;
+ private ISelectionChangedListener resourceSelectionChangedListener;
+ private IAutomationListener automationUIListener;
+ private IDataChangeListener dataChangeListener;
- private final String[] attTblHeaders = { "Name", "Value",
- "Automation" };
- private final Integer[] attTblColWidth = { 150, 190, 150 };
+ private final String[] attTblHeaders = { "Name", "Value",
+ "Automation" };
+ private final Integer[] attTblColWidth = { 150, 190, 150 };
- private ResourceManager resourceManager;
+ private ResourceManager resourceManager;
public AttributeView() {
resourceManager = Activator.getDefault().getResourceManager();
- resourceSelectionChangedListener = new ISelectionChangedUIListener() {
+ resourceSelectionChangedListener = new ISelectionChangedListener() {
@Override
public void onResourceSelectionChange(final Resource resource) {
}
};
- resourceModelChangedUIListener = new IResourceModelChangedUIListener() {
+ dataChangeListener = new IDataChangeListener() {
@Override
- public void onResourceModelChange(final Resource resource) {
+ public void add(final AttributeElement attribute) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- // Handle the notification only if it is for the current
- // resource in selection
- Resource resourceInSelection = resourceManager
- .getCurrentResourceInSelection();
- if (null == resourceInSelection) {
- return;
- }
+ attViewer.refresh(attribute.getParent());
+ attViewer.expandAll();
+ }
+ });
+ }
+
+ @Override
+ public void remove(final AttributeElement attribute) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ attViewer.refresh(attribute.getParent());
+ attViewer.expandAll();
+ }
+ });
+ }
+
+ @Override
+ public void update(final AttributeElement attribute) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ attViewer.update(attribute, null);
+ attViewer.expandAll();
}
});
}
};
- automationUIListener = new IAutomationUIListener() {
+ automationUIListener = new IAutomationListener() {
@Override
public void onResourceAutomationStart(final SingleResource resource) {
Tree tree;
tree = attViewer.getTree();
if (!tree.isDisposed()) {
- if (null != attName) {
- // Attribute level automation has stopped
- LocalResourceAttribute att = resourceManager
- .getAttributeByResourceURI(resource,
- attName);
- if (null == att) {
- return;
- } else {
- attViewer.update(att, null);
- }
- } else {
- // Resource level automation has stopped
- // Enabling the table which was disabled at the
- // beginning of automation
- tree.setEnabled(true);
- attViewer.refresh();
- }
+ tree.setEnabled(true);
+ attViewer.refresh();
}
}
});
private void addManagerListeners() {
UiListenerHandler.getInstance().addResourceSelectionChangedUIListener(
resourceSelectionChangedListener);
- UiListenerHandler.getInstance().addResourceModelChangedUIListener(
- resourceModelChangedUIListener);
+ UiListenerHandler.getInstance().addDataChangeListener(
+ dataChangeListener);
UiListenerHandler.getInstance().addAutomationUIListener(
automationUIListener);
}
- class AttributeContentProvider implements ITreeContentProvider,
- DataChangeListener {
-
- private TreeViewer mTreeViewer;
+ class AttributeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
@Override
public void inputChanged(Viewer viewer, Object oldAttribute,
Object newAttribute) {
- mTreeViewer = (TreeViewer) viewer;
}
@Override
@Override
public Object[] getElements(Object resourceModel) {
if (resourceModel instanceof ResourceRepresentation) {
- ((ResourceRepresentation) resourceModel).setListener(this);
return ((ResourceRepresentation) resourceModel).getAttributes()
.values().toArray();
}
return new Object[0];
}
-
- @Override
- public void add(final AttributeElement attribute) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- mTreeViewer.refresh(attribute.getParent());
- mTreeViewer.expandAll();
- }
- });
- }
-
- @Override
- public void remove(final AttributeElement attribute) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- mTreeViewer.refresh(attribute.getParent());
- mTreeViewer.expandAll();
- }
- });
- }
-
- @Override
- public void update(final AttributeElement attribute) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- mTreeViewer.update(attribute, null);
- mTreeViewer.expandAll();
- }
- });
- }
}
class AttributeLabelProvider implements ITableLabelProvider {
.getCurrentResourceInSelection();
if (res instanceof SingleResource) {
AttributeElement attrElement = (AttributeElement) element;
- SimulatorResourceAttribute attribute = attrElement
- .getSimulatorResourceAttribute();
- TypeInfo type = attribute.value().typeInfo();
if (attrElement.isAutoUpdateSupport()
&& !attrElement.isReadOnly()) {
if (attrElement.isAutoUpdateInProgress()) {
resourceSelectionChangedListener);
}
- // Unregister the model change listener
- if (null != resourceModelChangedUIListener) {
- UiListenerHandler.getInstance()
- .removeResourceModelChangedUIListener(
- resourceModelChangedUIListener);
+ // Unregister the data model change listener
+ if (null != dataChangeListener) {
+ UiListenerHandler.getInstance().removeDataChangeListener(
+ dataChangeListener);
}
// Unregister the automation complete listener
import java.util.List;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IDeviceInfoUIListener;
+import oic.simulator.serviceprovider.listener.IDeviceInfoListener;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.MetaProperty;
import oic.simulator.serviceprovider.utils.Constants;
DEVICE, PLATFORM
}
- private List<MetaProperty> deviceProperties;
- private List<MetaProperty> platformProperties;
+ private List<MetaProperty> deviceProperties;
+ private List<MetaProperty> platformProperties;
- private boolean enableDeviceEdit;
- private boolean enablePlatformEdit;
+ private boolean enableDeviceEdit;
+ private boolean enablePlatformEdit;
- private Button devEditBtn;
- private Button devCancelBtn;
- private Button platEditBtn;
- private Button platCancelBtn;
+ private Button devEditBtn;
+ private Button devCancelBtn;
+ private Button platEditBtn;
+ private Button platCancelBtn;
- private TableViewer platformTblViewer;
- private TableViewer deviceTblViewer;
+ private TableViewer platformTblViewer;
+ private TableViewer deviceTblViewer;
- private CTabFolder folder;
- private CTabItem devicePropTab;
- private CTabItem platformPropTab;
+ private CTabFolder folder;
+ private CTabItem devicePropTab;
+ private CTabItem platformPropTab;
- private IDeviceInfoUIListener deviceInfoUIListener;
+ private IDeviceInfoListener deviceInfoUIListener;
public DevicePlatformInfoView() {
- deviceInfoUIListener = new IDeviceInfoUIListener() {
+ deviceInfoUIListener = new IDeviceInfoListener() {
@Override
public void onDeviceInfoFound() {
import oic.simulator.logger.LogEntry;
import oic.simulator.logger.LogLabelProvider;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.ILogUIListener;
+import oic.simulator.serviceprovider.listener.ILogListener;
import oic.simulator.serviceprovider.manager.LogManager;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.view.dialogs.FilterDialog;
public static final String VIEW_ID = "oic.simulator.serviceprovider.view.log";
private LogManager logManager;
- private ILogUIListener logListener;
+ private ILogListener logListener;
private LogContentProvider treeContentProvider;
public LogView() {
- logListener = new ILogUIListener() {
+ logListener = new ILogListener() {
@Override
public void logChanged(final List<LogEntry> entry) {
import java.util.List;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.Device;
*/
public class MetaPropertiesView extends ViewPart {
- public static final String VIEW_ID = "oic.simulator.serviceprovider.view.metaproperties";
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.metaproperties";
- private TableViewer tableViewer;
+ private TableViewer tableViewer;
- private final String[] columnHeaders = { "Property", "Value" };
+ private final String[] columnHeaders = { "Property", "Value" };
- private final Integer[] columnWidth = { 150, 150 };
+ private final Integer[] columnWidth = { 150, 150 };
- private ISelectionChangedUIListener resourceSelectionChangedListener;
+ private ISelectionChangedListener resourceSelectionChangedListener;
- private ResourceManager resourceManagerRef;
+ private ResourceManager resourceManagerRef;
- private List<MetaProperty> properties;
+ private List<MetaProperty> properties;
- private boolean enable_edit;
- private Button editBtn;
- private Button cancelBtn;
+ private boolean enable_edit;
+ private Button editBtn;
+ private Button cancelBtn;
public MetaPropertiesView() {
resourceManagerRef = Activator.getDefault().getResourceManager();
- resourceSelectionChangedListener = new ISelectionChangedUIListener() {
+ resourceSelectionChangedListener = new ISelectionChangedListener() {
@Override
public void onResourceSelectionChange(final Resource resource) {
import java.util.Set;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IPropertiesChangedUIListener;
-import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
+import oic.simulator.serviceprovider.listener.IPropertiesChangedListener;
+import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.AutomationSettingHelper;
*/
public class ResourceManagerView extends ViewPart {
- public static final String VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
- private Button createButton;
- private Button deleteButton;
+ private Button createButton;
+ private Button deleteButton;
- private TreeViewer singleResTreeViewer;
- private TreeViewer collectionResTreeViewer;
- private TreeViewer deviceTreeViewer;
+ private TreeViewer singleResTreeViewer;
+ private TreeViewer collectionResTreeViewer;
+ private TreeViewer deviceTreeViewer;
- private CTabFolder folder;
- private CTabItem singleResTab;
- private CTabItem collectionResTab;
- private CTabItem deviceTab;
+ private CTabFolder folder;
+ private CTabItem singleResTab;
+ private CTabItem collectionResTab;
+ private CTabItem deviceTab;
- private IResourceListChangedUIListener resourceListChangedListener;
+ private IResourceListChangedListener resourceListChangedListener;
- private IPropertiesChangedUIListener resourcePropertiesChangedListener;
+ private IPropertiesChangedListener resourcePropertiesChangedListener;
- private ResourceManager resourceManager;
+ private ResourceManager resourceManager;
public ResourceManagerView() {
resourceManager = Activator.getDefault().getResourceManager();
- resourceListChangedListener = new IResourceListChangedUIListener() {
+ resourceListChangedListener = new IResourceListChangedListener() {
@Override
public void onResourceCreation(final ResourceType type) {
}
};
- resourcePropertiesChangedListener = new IPropertiesChangedUIListener() {
+ resourcePropertiesChangedListener = new IPropertiesChangedListener() {
@Override
public void onResourcePropertyChange() {
.getOption();
if (option == Option.DEVICE) {
Device dev = createWizard.getCreatedDevice();
- folder.setSelection(deviceTab);
- deviceTreeViewer.setSelection(
- new StructuredSelection(dev), true);
- resourceManager.deviceSelectionChanged(dev);
- deviceTreeViewer.expandToLevel(dev,
- Constants.TREE_EXPANSION_LEVEL);
+ 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
|| option == Option.SIMPLE) {
SingleResource res = (SingleResource) createWizard
.getCreatedResource();
- folder.setSelection(singleResTab);
- boolean canSelect = true;
- if (option == Option.SIMPLE_FROM_RAML
- && createWizard.getResourceCount() > 1) {
- canSelect = false;
- }
- if (canSelect) {
- singleResTreeViewer.setSelection(
- new StructuredSelection(res), true);
- resourceManager
- .resourceSelectionChanged(res);
+ if (null != res) {
+ folder.setSelection(singleResTab);
+ boolean canSelect = true;
+ if (option == Option.SIMPLE_FROM_RAML
+ && createWizard.getResourceCount() > 1) {
+ canSelect = false;
+ }
+ if (canSelect) {
+ singleResTreeViewer.setSelection(
+ new StructuredSelection(res),
+ true);
+ resourceManager
+ .resourceSelectionChanged(res);
+ }
}
} else if (option == Option.COLLECTION_FROM_RAML
|| option == Option.COLLECTION) {
CollectionResource res = (CollectionResource) createWizard
.getCreatedResource();
- folder.setSelection(collectionResTab);
- collectionResTreeViewer.setSelection(
- new StructuredSelection(res), true);
- resourceManager.resourceSelectionChanged(res);
- collectionResTreeViewer.expandToLevel(res,
- Constants.TREE_EXPANSION_LEVEL);
+ 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()
import java.util.Set;
import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IObserverListChangedUIListener;
-import oic.simulator.serviceprovider.listener.ISelectionChangedUIListener;
+import oic.simulator.serviceprovider.listener.IObserverListChangedListener;
+import oic.simulator.serviceprovider.listener.ISelectionChangedListener;
import oic.simulator.serviceprovider.manager.ResourceManager;
import oic.simulator.serviceprovider.manager.UiListenerHandler;
import oic.simulator.serviceprovider.model.Device;
* This class manages and shows the resource observer view in the perspective.
*/
public class ResourceObserverView extends ViewPart {
- public static final String VIEW_ID = "oic.simulator.serviceprovider.view.observer";
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.observer";
- private TableViewer tblViewer;
+ private TableViewer tblViewer;
- private final String[] columnHeaders = { "Client Address",
- "Port", "Notify" };
+ private final String[] columnHeaders = { "Client Address",
+ "Port", "Notify" };
- private final Integer[] columnWidth = { 150, 75, 50 };
+ private final Integer[] columnWidth = { 150, 75, 50 };
- private ISelectionChangedUIListener resourceSelectionChangedListener;
+ private ISelectionChangedListener resourceSelectionChangedListener;
- private IObserverListChangedUIListener resourceObserverListChangedListener;
+ private IObserverListChangedListener resourceObserverListChangedListener;
- private ResourceManager resourceManagerRef;
+ private ResourceManager resourceManagerRef;
public ResourceObserverView() {
resourceManagerRef = Activator.getDefault().getResourceManager();
- resourceSelectionChangedListener = new ISelectionChangedUIListener() {
+ resourceSelectionChangedListener = new ISelectionChangedListener() {
@Override
public void onResourceSelectionChange(final Resource resource) {
}
};
- resourceObserverListChangedListener = new IObserverListChangedUIListener() {
+ resourceObserverListChangedListener = new IObserverListChangedListener() {
@Override
public void onObserverListChanged(final Resource resource) {
import oic.simulator.serviceprovider.model.AttributeHelper;
import oic.simulator.serviceprovider.model.CollectionResource;
import oic.simulator.serviceprovider.model.Device;
-import oic.simulator.serviceprovider.model.LocalResourceAttribute;
import oic.simulator.serviceprovider.model.Resource;
import oic.simulator.serviceprovider.model.ResourceType;
import oic.simulator.serviceprovider.model.SingleResource;
import org.eclipse.swt.widgets.Display;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.SimulatorException;
+import org.oic.simulator.SimulatorResourceAttribute;
/**
* This class creates a UI wizard for create resource operation.
monitor.beginTask(
"Single Resource Creation Without RAML", 2);
monitor.worked(1);
- createdResource = createSingleResourceWithoutRAML();
+ createSingleResourceWithoutRAML();
} finally {
monitor.done();
}
}
// creation of simple resource
// with RAML
- // String resURI = updatePropPage.getResURI();
// Checking whether the uri is used by any other resource.
if (Activator.getDefault().getResourceManager()
.isResourceExist(updatePropPage.getResURI())) {
// itself.
return false;
}
- // Resource resource = loadRamlPage.getResource();
- // resource.setResourceName(updatePropPage.getResName());
+
try {
getContainer().run(true, true, new IRunnableWithProgress() {
return startStopPage;
}
- /*
- * public SingleResource getSimResource() { return simResource; }
- *
- * public void setSimResource(SingleResource simResource) { this.simResource
- * = simResource; }
- */
-
public void setStatus(String status) {
this.status = status;
}
return status;
}
- /*
- * public SingleResource getCreatedResource() { return simResource; }
- */
-
- private SingleResource createSingleResourceWithoutRAML() {
+ private void createSingleResourceWithoutRAML() {
SingleResource resource = new SingleResource();
// Basic resource details
resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI());
resource.setResourceName(simpleResourceBasicDetailsPage.getResName());
resource.setResourceTypes(simpleResourceBasicDetailsPage.getResTypes());
resource.setObservable(simpleResourceBasicDetailsPage.isObservable());
- // resource.setStarted(simpleResourceBasicDetailsPage.isStart());
// Resource Attributes
- Map<String, LocalResourceAttribute> attributes = new HashMap<String, LocalResourceAttribute>();
+ Map<String, SimulatorResourceAttribute> attributes = new HashMap<String, SimulatorResourceAttribute>();
Set<AttributeHelper> attributeSet = simpleResourceAddAttributePage
.getAttributes();
if (null != attributeSet && !attributeSet.isEmpty()) {
Iterator<AttributeHelper> itr = attributeSet.iterator();
AttributeHelper attHelper;
- LocalResourceAttribute localResAtt;
- // List<String> attValues;
+ SimulatorResourceAttribute attribute;
while (itr.hasNext()) {
attHelper = itr.next();
if (null != attHelper) {
- localResAtt = attHelper.convertToLocalResourceAttribute();
-
- // Set the attribute value list.
- /*
- * attValues =
- * Activator.getDefault().getResourceManager().getValueList
- * (localResAtt); localResAtt.setAttValues(attValues);
- */
- attributes.put(
- localResAtt.getResourceAttributeRef().name(),
- localResAtt);
+ attribute = attHelper.convertToSimulatorResourceAttribute();
+ attributes.put(attribute.name(), attribute);
}
}
- resource.setResourceAttributes(attributes);
}
// Request types
// string.
try {
boolean result = Activator.getDefault().getResourceManager()
- .createSingleResource(resource);
+ .createSingleResource(resource, attributes);
if (result) {
status = "Resource created.";
} else {
status = "Failed to create resource.";
resource = null;
}
- } catch (SimulatorException e) {
+ } catch (Exception e) {
status = "Failed to create resource.\n"
+ Utility.getSimulatorErrorString(e, null);
resource = null;
}
- return resource;
}
private void completeResourceCreationWithRAML() {
status = "Failed to create resource.";
createdResource = null;
}
- } catch (SimulatorException e) {
+ } catch (Exception e) {
status = "Failed to create resource.\n"
+ Utility.getSimulatorErrorString(e, null);
createdResource = null;
package oic.simulator.serviceprovider.view.dialogs;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
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;
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.Tree;
-import org.eclipse.swt.widgets.TreeItem;
/**
* This class shows UI for deleting resources.
private CheckboxTreeViewer collectionTreeViewer;
private CheckboxTreeViewer singleTreeViewer;
- private Button selectAllSingle;
- private Button selectAllCollection;
- private Button deselectAllSingle;
- private Button deselectAllCollection;
-
private List<CollectionResource> collectionSourceList;
private List<SingleResource> singleSourceList;
- private Set<CollectionResource> selectedCollections;
- private Set<SingleResource> selectedSingles;
+ private TreeViewContentHelper singleTreeViewContentHelper;
+ private TreeViewContentHelper collectionTreeViewContentHelper;
protected DeleteResourcePage() {
super("Delete Resources");
.getSingleResourceList();
collectionSourceList = Activator.getDefault().getResourceManager()
.getCollectionResourceList();
-
- selectedCollections = new HashSet<CollectionResource>();
- selectedSingles = new HashSet<SingleResource>();
}
@Override
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout layout = new GridLayout(5, true);
+ GridLayout layout = new GridLayout(4, true);
container.setLayout(layout);
createSingleResourcesArea(container);
createCollectionResourcesArea(container);
- createSelectionControls(container);
-
setControl(container);
}
Label lbl = new Label(singleContainer, SWT.NONE);
lbl.setText("Simple Resources:");
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- // gd.grabExcessHorizontalSpace = true;
- // gd.horizontalAlignment = SWT.FILL;
lbl.setLayoutData(gd);
Group resourceGroup = new Group(singleContainer, SWT.NONE);
gd.horizontalSpan = 2;
resourceGroup.setLayoutData(gd);
+ if (null == singleSourceList || singleSourceList.isEmpty()) {
+ return;
+ }
+
singleTreeViewer = new CheckboxTreeViewer(resourceGroup);
singleTreeViewer.getTree().setBackground(color);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
+
singleTreeViewer.getTree().setLayoutData(gd);
singleTreeViewer
.setContentProvider(new SingleResourceContentProvider());
singleTreeViewer.setLabelProvider(new TreeLabelProvider());
- singleTreeViewer.setInput(new Object());
+ singleTreeViewer.setInput(new TreeContentProvider());
singleTreeViewer.addCheckStateListener(new ICheckStateListener() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
+ * (org.eclipse.jface.viewers.CheckStateChangedEvent)
+ */
@Override
public void checkStateChanged(CheckStateChangedEvent e) {
- SingleResource res = (SingleResource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedSingles.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedSingles.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
+ Object element = e.getElement();
+ if (element instanceof TreeViewContentHelper) {
+ singleTreeViewer.setGrayed(singleTreeViewContentHelper,
+ false);
+ singleTreeViewer.setChecked(singleTreeViewContentHelper,
+ e.getChecked());
+ singleTreeViewer.setSubtreeChecked(element, e.getChecked());
+ } else {
+ Object obj[] = singleTreeViewer.getCheckedElements();
+ if (null != obj && obj.length > 0) {
+ int checkedCount = obj.length;
+ boolean isParentGrayed = singleTreeViewer
+ .getChecked(singleTreeViewContentHelper);
+ boolean isParentChecked = singleTreeViewer
+ .getChecked(singleTreeViewContentHelper);
+ if (isParentChecked || isParentGrayed) {
+ checkedCount--;
+ }
+ if (checkedCount == singleSourceList.size()) {
+ singleTreeViewer.setGrayed(
+ singleTreeViewContentHelper, false);
+ singleTreeViewer.setChecked(
+ singleTreeViewContentHelper, true);
+ } else {
+ if (checkedCount > 0) {
+ singleTreeViewer.setGrayed(
+ singleTreeViewContentHelper, true);
+ singleTreeViewer.setChecked(
+ singleTreeViewContentHelper, true);
+ } else {
+ singleTreeViewer.setGrayed(
+ singleTreeViewContentHelper, false);
+ singleTreeViewer.setChecked(
+ singleTreeViewContentHelper, false);
+ }
+ }
}
- setPageComplete(isSelectionDone());
}
+ setPageComplete(isSelectionDone());
}
});
+ singleTreeViewer.expandAll();
+
}
private void createCollectionResourcesArea(Composite container) {
gd.horizontalSpan = 2;
resourceGroup.setLayoutData(gd);
+ if (null == collectionSourceList || collectionSourceList.isEmpty()) {
+ return;
+ }
+
collectionTreeViewer = new CheckboxTreeViewer(resourceGroup);
collectionTreeViewer.getTree().setBackground(color);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
- // gd.heightHint = 300;
+
collectionTreeViewer.getTree().setLayoutData(gd);
collectionTreeViewer
.setContentProvider(new CollectionResourceContentProvider());
collectionTreeViewer.setLabelProvider(new TreeLabelProvider());
- collectionTreeViewer.setInput(new Object());
+ collectionTreeViewer.setInput(new TreeContentProvider());
collectionTreeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent e) {
- CollectionResource res = (CollectionResource) e.getElement();
- if (null != res) {
- if (e.getChecked()) {
- selectedCollections.add(res);
- System.out.println("Checked" + res.getResourceName());
- } else {
- selectedCollections.remove(res);
- System.out.println("Unchecked:" + res.getResourceName());
+ 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());
}
+ setPageComplete(isSelectionDone());
}
});
+ collectionTreeViewer.expandAll();
}
- private void createSelectionControls(Composite container) {
- Composite innerComp = new Composite(container, SWT.NULL);
- GridLayout layout = new GridLayout();
- // layout.verticalSpacing = 10;
- layout.marginTop = 15;
- innerComp.setLayout(layout);
- GridData gd = new GridData();
- gd.verticalAlignment = SWT.TOP;
- innerComp.setLayoutData(gd);
-
- selectAllSingle = new Button(innerComp, SWT.PUSH);
- selectAllSingle.setText("Select All Simple");
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- // gd.widthHint = 70;
- selectAllSingle.setLayoutData(gd);
- selectAllSingle.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- check(singleTreeViewer, true);
- }
- });
-
- selectAllCollection = new Button(innerComp, SWT.PUSH);
- selectAllCollection.setText("Select All Collection");
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- // gd.widthHint = 70;
- selectAllCollection.setLayoutData(gd);
- selectAllCollection.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- check(collectionTreeViewer, true);
- }
- });
+ public Set<SingleResource> getSelectedSingleResourcesList() {
+ final Set<SingleResource> singles = new HashSet<SingleResource>();
+ Display.getDefault().syncExec(new Runnable() {
- deselectAllSingle = new Button(innerComp, SWT.PUSH);
- deselectAllSingle.setText("Deselect All Simple");
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- // gd.widthHint = 70;
- deselectAllSingle.setLayoutData(gd);
- deselectAllSingle.addSelectionListener(new SelectionAdapter() {
@Override
- public void widgetSelected(SelectionEvent e) {
- check(singleTreeViewer, false);
+ public void run() {
+ if (null == singleTreeViewer) {
+ return;
+ }
+ Object selection[] = singleTreeViewer.getCheckedElements();
+ if (null == selection || selection.length < 1) {
+ return;
+ }
+ for (Object obj : selection) {
+ if (obj instanceof Resource) {
+ singles.add((SingleResource) obj);
+ }
+ }
}
});
+ return singles;
+ }
- deselectAllCollection = new Button(innerComp, SWT.PUSH);
- deselectAllCollection.setText("Deselect All Collection");
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- // gd.widthHint = 70;
- deselectAllCollection.setLayoutData(gd);
+ public Set<CollectionResource> getSelectedCollectionResourcesList() {
+ final Set<CollectionResource> collections = new HashSet<CollectionResource>();
+ Display.getDefault().syncExec(new Runnable() {
- deselectAllCollection.addSelectionListener(new SelectionAdapter() {
@Override
- public void widgetSelected(SelectionEvent e) {
- check(collectionTreeViewer, false);
- }
- });
- }
-
- private void check(CheckboxTreeViewer viewer, boolean toCheck) {
- Tree tree = viewer.getTree();
- if (null != tree) {
- TreeItem[] items = tree.getItems();
- if (null != items && items.length > 0) {
- Object obj;
- for (TreeItem item : items) {
- obj = item.getData();
- if (null != obj) {
- viewer.setChecked(obj, toCheck);
- updateSelectionList((Resource) obj, toCheck);
+ 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);
}
}
- setPageComplete(isSelectionDone());
}
- }
- }
-
- private void updateSelectionList(Resource res, boolean isChecked) {
- if (res instanceof SingleResource) {
- if (isChecked) {
- selectedSingles.add((SingleResource) res);
- } else {
- selectedSingles.remove((SingleResource) res);
- }
- } else {
- if (isChecked) {
- selectedCollections.add((CollectionResource) res);
- } else {
- selectedCollections.remove((CollectionResource) res);
- }
- }
- }
-
- public Set<SingleResource> getSelectedSingleResourcesList() {
- return selectedSingles;
- }
-
- public Set<CollectionResource> getSelectedCollectionResourcesList() {
- return selectedCollections;
+ });
+ return collections;
}
class SingleResourceContentProvider implements ITreeContentProvider {
@Override
public Object[] getChildren(Object parent) {
+ if (parent instanceof TreeViewContentHelper) {
+ return ((TreeViewContentHelper) parent).getResources()
+ .toArray();
+ }
return null;
}
@Override
public Object[] getElements(Object parent) {
- if (null == singleSourceList) {
- singleSourceList = new ArrayList<SingleResource>();
- }
- return singleSourceList.toArray();
+ Object obj[] = new Object[1];
+ singleTreeViewContentHelper = new TreeViewContentHelper(
+ singleSourceList);
+ obj[0] = singleTreeViewContentHelper;
+ return obj;
}
@Override
@Override
public boolean hasChildren(Object parent) {
+ if (parent instanceof TreeViewContentHelper) {
+ return true;
+ }
return false;
}
}
@Override
public Object[] getChildren(Object parent) {
+ if (parent instanceof TreeViewContentHelper) {
+ return ((TreeViewContentHelper) parent).getResources()
+ .toArray();
+ }
return null;
}
@Override
public Object[] getElements(Object parent) {
- if (null == collectionSourceList) {
- collectionSourceList = new ArrayList<CollectionResource>();
- }
- return collectionSourceList.toArray();
+ Object obj[] = new Object[1];
+ collectionTreeViewContentHelper = new TreeViewContentHelper(
+ collectionSourceList);
+ obj[0] = collectionTreeViewContentHelper;
+ return obj;
}
@Override
@Override
public boolean hasChildren(Object parent) {
+ if (parent instanceof TreeViewContentHelper) {
+ return true;
+ }
return false;
}
}
class TreeLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
+ if (element instanceof TreeViewContentHelper) {
+ return "All";
+ }
Resource res = (Resource) element;
- return res.getResourceName();
+ return res.getResourceName() + " (" + res.getResourceURI() + ")";
}
@Override
if (element instanceof CollectionResource) {
return Activator.getDefault().getImageRegistry()
.get(Constants.COLLECTION_RESOURCE);
- } else {
+ } else if (element instanceof SingleResource) {
return Activator.getDefault().getImageRegistry()
.get(Constants.SINGLE_RESOURCE);
+ } else {
+ return null;
}
}
}
+ class TreeViewContentHelper {
+ List<? extends Resource> resources;
+
+ public TreeViewContentHelper(List<? extends Resource> resources) {
+ this.resources = resources;
+ }
+
+ public void setResources(List<? extends Resource> resources) {
+ this.resources = resources;
+ }
+
+ public List<? extends Resource> getResources() {
+ return resources;
+ }
+ }
+
public boolean isSelectionDone() {
- boolean done = true;
- Object obj[] = singleTreeViewer.getCheckedElements();
- if (null == obj || obj.length < 1) {
- obj = collectionTreeViewer.getCheckedElements();
- if (null == obj || obj.length < 1) {
- done = false;
+ if (null != singleTreeViewer) {
+ Object obj[] = singleTreeViewer.getCheckedElements();
+ if (null != obj && obj.length > 0) {
+ return true;
+ }
+ }
+ if (null != collectionTreeViewer) {
+ Object obj[] = collectionTreeViewer.getCheckedElements();
+ if (null != obj && obj.length > 0) {
+ return true;
}
}
- return done;
+ return false;
}
}
\ No newline at end of file
* corresponding {@link SimulatorResourceAttribute} as value.
*/
public Map<String, SimulatorResourceAttribute> getAttributes() {
- if (mValues.size() == 0)
- return null;
-
Map<String, SimulatorResourceAttribute> attributes = new HashMap<>();
for (Map.Entry<String, AttributeValue> entry : mValues.entrySet()) {
SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(