1. Updated UI for creating resources: Removed standard/custom option.
2. Updated the log view to show single line entries.
3. Removed unnecessary code.
4. Added code to disable manual and automatic value change operations on
read-only attributes.
Change-Id: Ie5ed0a9f9b5005de63475965859b9fb71085dde2
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3855
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
return resource.getResourceURI();
}
- @Override
+ // TODO: Commenting temporarily until resource icons are finalized.
+ /*@Override
public Image getImage(Object element) {
RemoteResource resource = (RemoteResource) element;
ResourceManager resourceManager = Activator.getDefault()
.getResourceManager();
return resourceManager.getImage(resource.getResourceURI());
- }
+ }*/
}
\ No newline at end of file
.,\
icons/,\
plugin.xml,\
- libs/,\
- resource/
-
+ libs/,\
\ No newline at end of file
+++ /dev/null
-{
- "id": "simple.light#",
- "$schema": "http://json-schema.org/draft-04/schema#",
- "title": "Simple Light",
- "$ref": "#/definitions/light",
- "definitions": {
- "light": {
- "type": "object",
- "properties": {
- "resourceType": {
- "type": "string",
- "description": "Description about resource type",
- "default": "sample.light"
- },
- "intensity": {
- "type": "string",
- "description": "ReadOnly, Comma separated min,max values for intensity on this device",
- "default": "1,20"
- }
- }
- }
- }
-}
+++ /dev/null
-{
- "id": "simple.light#",
- "$schema": "http://json-schema.org/schema#",
- "title": "Simple Light",
- "$ref": "#/definitions/light",
- "definitions": {
- "light": {
- "type": "object",
- "properties": {
- "resourceType": {
- "type": "string",
- "description": "Description about resource type",
- "default": "sample.light"
- },
- "power": {
- "type": "string",
- "description": "Light status",
- "default": "on",
- "enum": ["on","off"],
- "update_frequency": 1000
- },
- "intensity": {
- "type": "integer",
- "description": "brightness of the light",
- "default": 1,
- "minimum": 1,
- "maximum": 20,
- "update_frequency": 1001
- }
- }
- }
- },
- "required": [ "resourceType", "power" ]
-}
\ No newline at end of file
+++ /dev/null
-#%RAML 0.8
-title: Simple Light
-version: v1.0-20150910
-schemas:
- - LightSchema: !include simple-light.json
- LightSchemaError: !include simple-light-error.json
-
-/sample/light:
- description: Resource to be exposed by any Simple Device that can act as Light.
- displayName: Simple Light
- get:
- responses:
- 200:
- body:
- application/json:
- schema: LightSchema
- example: |
- {
- "resourceType": "sample.light",
- "power": "off"
- }
- put:
- body:
- application/json:
- schema: LightSchema
- example: |
- {
- "power": "off",
- "intensity": 5
- }
- responses:
- 200:
- body:
- application/json:
- schema: LightSchema
- example: |
- {
- "power": "off",
- "intensity": 5
- }
- 403:
- description: |
- This response is generated by the Server when the client sends:
- An update with an out of range property value for intensity.
- The server responds with the range property illustrating the error.
- body:
- application/json:
- schema: LightSchemaError
- example: |
- {
- "range": "1,20"
- }
- post:
- body:
- application/json:
- schema: LightSchema
- example: |
- {
- "power": "off"
- }
- responses:
- 200:
- body:
- application/json:
- schema: LightSchema
- example: |
- {
- "power": "off"
- }
- 403:
- description: |
- This response is generated by the Server when the client sends:
- An update with an out of range property value for intensity.
- The server responds with the range property illustrating the error.
- body:
- application/json:
- schema: LightSchemaError
- example: |
- {
- "range": "1,20"
- }
} else if (columnIndex == 1) {
return dateFormat.format(entry.getDate());
} else {
- return entry.getMessage();
+ String msg = entry.getMessage();
+ int pos = msg.indexOf('\n');
+ if (pos != -1) {
+ msg = msg.substring(0, pos);
+ }
+ return msg;
}
}
r.put(Constants.NOTIFY_BUTTON_SELECTED, ImageDescriptor
.createFromURL(bundle.getEntry("icons/button_pressed.PNG")));
- // Resource icons based on the resource type
- r.put(Constants.SAMPLE_LIGHT, ImageDescriptor.createFromURL(bundle
- .getEntry("/icons/light_16x16.png")));
-
// Log View related icons
r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
.getEntry("/icons/debug_log.gif")));
import oic.simulator.serviceprovider.resource.MetaProperty;
import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
import oic.simulator.serviceprovider.resource.SimulatorResource;
-import oic.simulator.serviceprovider.resource.StandardConfiguration;
import oic.simulator.serviceprovider.utils.Constants;
import oic.simulator.serviceprovider.utils.Utility;
private Map<String, String> displayNameMap;
- private StandardConfiguration stdConfig;
-
private SimulatorResource currentResourceInSelection;
private List<IResourceListChangedUIListener> resourceListChangedUIListeners;
resourceMap = new HashMap<String, Map<String, SimulatorResource>>();
orderedResourceUriMap = new HashMap<String, ArrayList<String>>();
displayNameMap = new HashMap<String, String>();
- stdConfig = new StandardConfiguration();
resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
}
}
- // This method gives a list of available RAML resource configurations.
- public Map<String, String> getResourceConfigurationList() {
- return stdConfig.getStandardResourceConfigurationList();
- }
-
- public String getConfigFilePath(String fileName) {
- return stdConfig.getFilePath(fileName);
- }
-
public void addResourceListChangedUIListener(
IResourceListChangedUIListener resourceListChangedUIListener) {
synchronized (resourceListChangedUIListeners) {
}
}
+ public boolean isAttHasRangeOrAllowedValues(LocalResourceAttribute att) {
+ if (null == att) {
+ return false;
+ }
+ Object[] obj = att.getAllowedValues();
+ if (null != obj && obj.length > 0) {
+ return true;
+ }
+ Object min = att.getMinValue();
+ Object max = att.getMaxValue();
+ if (null != min && null != max) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isResourceAutomationAllowed(String resourceURI) {
+ if (null == resourceURI) {
+ return false;
+ }
+ SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+ if (null == resource) {
+ return false;
+ }
+ Map<String, LocalResourceAttribute> attributes = resource
+ .getResourceAttributesMap();
+ if (null == attributes || attributes.size() < 1) {
+ return false;
+ }
+ Set<String> keySet = attributes.keySet();
+ Iterator<String> itr = keySet.iterator();
+ String attName;
+ boolean allowed = false;
+ LocalResourceAttribute att;
+ while (itr.hasNext()) {
+ attName = itr.next();
+ if (null != attName) {
+ att = attributes.get(attName);
+ if (null != att) {
+ allowed = allowed | isAttHasRangeOrAllowedValues(att);
+ }
+ }
+ }
+ return allowed;
+ }
+
public Image getImage(String resourceURI) {
if (null == resourceURI) {
return null;
public void shutdown() {
threadHandle.interrupt();
}
-}
+}
\ No newline at end of file
}
public Object getMinValue() {
- return resourceAttribute.getRange().getMin();
+ Range range = resourceAttribute.getRange();
+ if (null == range)
+ return null;
+ return range.getMin();
}
public Object getMaxValue() {
- return resourceAttribute.getRange().getMax();
+ Range range = resourceAttribute.getRange();
+ if (null == range)
+ return null;
+ return range.getMax();
}
public boolean isAutomationInProgress() {
+++ /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.resource;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.utils.Constants;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.oic.simulator.ILogger.Level;
-
-/**
- * Class which loads and maintains the standard RAML configuration file list.
- */
-public class StandardConfiguration {
-
- // A map of filename of standard resources as the key and the complete
- // location of the file(including the filename) as the value.
- Map<String, String> stdConfigFiles;
-
- public StandardConfiguration() {
- stdConfigFiles = new HashMap<String, String>();
- populateStandardConfigurationList();
- }
-
- private void populateStandardConfigurationList() {
- Enumeration<URL> fileList = Activator.getDefault().getBundle()
- .findEntries(Constants.CONFIG_DIRECTORY_PATH, "*", true);
- if (null == fileList) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- "No configuration files exist.");
- return;
- }
- URL url;
- URL resolvedURL;
- URI resolvedURI;
- File file;
- String relPath;
- String absPath;
- while (fileList.hasMoreElements()) {
- url = (URL) fileList.nextElement();
- relPath = url.getPath();
- System.out.println(url.getPath());
- try {
- resolvedURL = FileLocator.toFileURL(url);
- if (relPath.toLowerCase().endsWith(
- Constants.RAML_FILE_EXTENSION)) {
- resolvedURI = new URI(resolvedURL.getProtocol(),
- resolvedURL.getPath(), null);
- file = new File(resolvedURI);
- absPath = file.getAbsolutePath();
- stdConfigFiles.put(relPath, absPath);
- System.out.println("File path:" + absPath);
- }
- } catch (URISyntaxException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- } catch (IOException e) {
- Activator.getDefault().getLogManager()
- .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
- }
- }
- }
-
- public Map<String, String> getStandardResourceConfigurationList() {
- return stdConfigFiles;
- }
-
- public void setStandardResourceConfigurationList(
- Map<String, String> stdConfigFiles) {
- this.stdConfigFiles = stdConfigFiles;
- }
-
- public String getFilePath(String fileName) {
- return stdConfigFiles.get(fileName);
- }
-}
\ No newline at end of file
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 = "Select a standard resource or custom resource to be created";
+ public static final String CREATE_PAGE_MESSAGE = "Create one or more resources from RAML configuration 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 JSON_FILE_EXTENSION = ".json";
public static final String SPLIT_BY_DOT_PATTERN = "\\.";
-
- public static final String SAMPLE_LIGHT = "sample.light";
}
\ No newline at end of file
protected CellEditor getCellEditor(Object element) {
attributeInSelection = (LocalResourceAttribute) element;
+ ResourceManager resourceManager = Activator.getDefault()
+ .getResourceManager();
+ if (!resourceManager
+ .isAttHasRangeOrAllowedValues(attributeInSelection)) {
+ return null;
+ }
+
// CellEditor is not required as the automation is in progress.
if (attributeInSelection.isAutomationInProgress()) {
return null;
// CellEditor is not required as the automation is in progress.
ResourceManager resourceManager = Activator.getDefault()
.getResourceManager();
+ LocalResourceAttribute att = (LocalResourceAttribute) element;
+ if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+ return null;
+ }
+
SimulatorResource resource = resourceManager
.getCurrentResourceInSelection();
if (null != resource && resource.isResourceAutomationInProgress()) {
@Override
public String getText(Object element) {
LocalResourceAttribute att = (LocalResourceAttribute) element;
+ if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+ System.out.println("No range or allowed values");
+ return "Read Only";
+ }
if (att.isAutomationInProgress()) {
return Constants.ENABLED;
}
@Override
public Image getImage(Object element) {
LocalResourceAttribute att = (LocalResourceAttribute) element;
+ if (!resourceManager.isAttHasRangeOrAllowedValues(att)) {
+ System.out.println("No range or allowed values");
+ return null;
+ }
if (att.isAutomationInProgress()) {
return Activator.getDefault().getImageRegistry()
.get(Constants.CHECKED);
for (int index = 0; index < items.length; index++) {
items[index].dispose();
}
+
final String selectedItem = resourceTreeHead
.getSelection()[0].getText();
+ // Check whether automation can be done on this
+ // resource.
+ if (!resourceManager.isResourceAutomationAllowed(resourceManager
+ .getCompleteUriFromDisplayName(selectedItem))) {
+ return;
+ }
+
MenuItem startItem = new MenuItem(menu, SWT.NONE);
startItem.setText(Constants.START_RESOURCE_AUTOMATION);
startItem.addSelectionListener(new SelectionAdapter() {
package oic.simulator.serviceprovider.view.dialogs;
-import java.util.Iterator;
-import java.util.Map;
-
-import oic.simulator.serviceprovider.Activator;
import oic.simulator.serviceprovider.utils.Constants;
-import oic.simulator.serviceprovider.utils.Utility;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
*/
public class CreateResourcePage extends WizardPage {
- private Button stdResourceRbtn;
- private CCombo resourceTypeCmb;
- private Button cusResourceRbtn;
private Text locationTxt;
private Button btnBrowse;
private Text noOfInstancesText;
- private Label resourceTypeLbl;
private Label noOfInstancesLbl;
private Label locationLbl;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
configGroup.setLayoutData(gd);
- configGroup.setText("Configuration File Type");
-
- stdResourceRbtn = new Button(configGroup, SWT.RADIO);
- stdResourceRbtn.setText("Standard Configuration");
-
- Composite stdConfigComp = new Composite(configGroup, SWT.NONE);
- stdConfigComp.setLayout(new GridLayout(2, false));
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- stdConfigComp.setLayoutData(gd);
-
- resourceTypeLbl = new Label(stdConfigComp, SWT.NONE);
- resourceTypeLbl.setText("ResourceType:");
- resourceTypeLbl.setEnabled(false);
-
- resourceTypeCmb = new CCombo(stdConfigComp, SWT.READ_ONLY | SWT.BORDER);
- gd = new GridData();
- gd.widthHint = 150;
- resourceTypeCmb.setLayoutData(gd);
- resourceTypeCmb.setEnabled(false);
-
- cusResourceRbtn = new Button(configGroup, SWT.RADIO);
- cusResourceRbtn.setText("Custom Configuration");
+ configGroup.setText("Load RAML File");
Composite cusConfigComp = new Composite(configGroup, SWT.NONE);
cusConfigComp.setLayout(new GridLayout(3, false));
locationLbl = new Label(cusConfigComp, SWT.NONE);
locationLbl.setText("Location:");
- locationLbl.setEnabled(false);
locationTxt = new Text(cusConfigComp, SWT.BORDER);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
locationTxt.setLayoutData(gd);
- locationTxt.setEnabled(false);
btnBrowse = new Button(cusConfigComp, SWT.NONE);
btnBrowse.setText("Browse");
gd.widthHint = 80;
gd.horizontalAlignment = SWT.FILL;
btnBrowse.setLayoutData(gd);
- btnBrowse.setEnabled(false);
+ btnBrowse.setFocus();
Composite instanceComp = new Composite(compContent, SWT.NONE);
instanceComp.setLayout(new GridLayout(2, false));
// Adding the default value. It can be changed by the user.
noOfInstancesText.setText("1");
- populateDataInUI();
-
addUIListeners();
setControl(compContent);
}
- private void populateDataInUI() {
- // Populate Resource-type in Combo
- populateResourceTypeCombo();
- }
-
- private void populateResourceTypeCombo() {
- Map<String, String> configMap;
- configMap = Activator.getDefault().getResourceManager()
- .getResourceConfigurationList();
- if (null != configMap) {
- Iterator<String> itr = configMap.keySet().iterator();
- String fileName;
- String shortName;
- while (itr.hasNext()) {
- fileName = itr.next();
- shortName = Utility.fileNameToDisplay(fileName);
- if (null == shortName) {
- continue;
- }
- resourceTypeCmb.add(shortName);
- }
- }
-
- // By default, selecting the first item in the resourceType combo
- selectInitialItem();
- }
-
private void addUIListeners() {
- stdResourceRbtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
-
- // Set the configFilePath to the first item in the combo
- selectInitialItem();
-
- setPageComplete(isSelectionDone());
-
- // Change the visibility of widgets
- resourceTypeLbl.setEnabled(true);
- resourceTypeCmb.setEnabled(true);
- locationLbl.setEnabled(false);
- locationTxt.setEnabled(false);
- btnBrowse.setEnabled(false);
-
- }
- });
-
- cusResourceRbtn.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- setPageComplete(isSelectionDone());
-
- // Change the visibility of widgets
- locationLbl.setEnabled(true);
- locationTxt.setEnabled(true);
- btnBrowse.setEnabled(true);
- resourceTypeLbl.setEnabled(false);
- resourceTypeCmb.setEnabled(false);
-
- }
- });
btnBrowse.addSelectionListener(new SelectionAdapter() {
@Override
fileDialog
.setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
String configFileAbsolutePath = fileDialog.open();
- locationTxt.setText(configFileAbsolutePath);
- }
- });
-
- resourceTypeCmb.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int index = resourceTypeCmb.getSelectionIndex();
- if (index >= 0) {
- String selectedItem = resourceTypeCmb.getItem(index);
- if (null != selectedItem) {
- // Convert the selectedItem to the fully qualified file
- // name.
- selectedItem = Utility.displayToFileName(selectedItem);
-
- // Get the RAML configuration file path of the selected
- // resource
- configFilePath = Activator.getDefault()
- .getResourceManager()
- .getConfigFilePath(selectedItem);
-
- setPageComplete(isSelectionDone());
- }
+ if (null != configFileAbsolutePath) {
+ locationTxt.setText(configFileAbsolutePath);
}
}
});
});
}
- private void selectInitialItem() {
- if (resourceTypeCmb.getItemCount() > 0) {
- resourceTypeCmb.select(0);
- String fileName = Utility.displayToFileName(resourceTypeCmb
- .getText());
- configFilePath = Activator.getDefault().getResourceManager()
- .getConfigFilePath(fileName);
- }
- }
-
private boolean isSelectionDone() {
boolean done = false;
try {
} catch (Exception e) {
resourceCount = -1;
}
- if (cusResourceRbtn.getSelection()) {
- configFilePath = locationTxt.getText();
- }
if (null != configFilePath && configFilePath.length() > 0
&& resourceCount >= 1) {