From 3229347efee98ba229c603cdcae415fe1215960c Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Tue, 13 Oct 2015 23:34:53 +0530 Subject: [PATCH] Simulator Service Provider plug-in changes: 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/3855 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../clientcontroller/view/ResourceManagerView.java | 5 +- .../ServiceProviderPlugin/build.properties | 4 +- .../resource/Light/simple-light-error.json | 23 ---- .../resource/Light/simple-light.json | 34 ----- .../resource/Light/simple-light.raml | 81 ------------ .../src/oic/simulator/logger/LogLabelProvider.java | 7 +- .../serviceprovider/manager/ImageManager.java | 4 - .../serviceprovider/manager/ResourceManager.java | 61 ++++++--- .../resource/LocalResourceAttribute.java | 10 +- .../resource/StandardConfiguration.java | 103 --------------- .../simulator/serviceprovider/utils/Constants.java | 4 +- .../view/AttributeEditingSupport.java | 12 ++ .../serviceprovider/view/AttributeView.java | 8 ++ .../serviceprovider/view/ResourceManagerView.java | 8 ++ .../view/dialogs/CreateResourcePage.java | 139 +-------------------- 15 files changed, 98 insertions(+), 405 deletions(-) delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light-error.json delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.json delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java index 8652adb..db5e91f 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java @@ -739,11 +739,12 @@ class TreeLabelProvider extends LabelProvider { 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 diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties index 3db1138..8940d85 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties @@ -4,6 +4,4 @@ bin.includes = META-INF/,\ .,\ icons/,\ plugin.xml,\ - libs/,\ - resource/ - + libs/,\ \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light-error.json b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light-error.json deleted file mode 100644 index ceea4eb..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light-error.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "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" - } - } - } - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.json b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.json deleted file mode 100644 index e850b70..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "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 diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml deleted file mode 100644 index 3725c6b..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/resource/Light/simple-light.raml +++ /dev/null @@ -1,81 +0,0 @@ -#%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" - } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java index f392bc8..9861d77 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java @@ -50,7 +50,12 @@ public class LogLabelProvider extends LabelProvider implements } 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; } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java index ee700d1..efdb577 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java @@ -55,10 +55,6 @@ public class ImageManager { 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"))); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index 2b48e82..2a0473b 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -37,7 +37,6 @@ import oic.simulator.serviceprovider.resource.LocalResourceAttribute; 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; @@ -71,8 +70,6 @@ public class ResourceManager { private Map displayNameMap; - private StandardConfiguration stdConfig; - private SimulatorResource currentResourceInSelection; private List resourceListChangedUIListeners; @@ -99,7 +96,6 @@ public class ResourceManager { resourceMap = new HashMap>(); orderedResourceUriMap = new HashMap>(); displayNameMap = new HashMap(); - stdConfig = new StandardConfiguration(); resourceListChangedUIListeners = new ArrayList(); resourceSelectionChangedUIListeners = new ArrayList(); @@ -277,15 +273,6 @@ public class ResourceManager { } } - // This method gives a list of available RAML resource configurations. - public Map getResourceConfigurationList() { - return stdConfig.getStandardResourceConfigurationList(); - } - - public String getConfigFilePath(String fileName) { - return stdConfig.getFilePath(fileName); - } - public void addResourceListChangedUIListener( IResourceListChangedUIListener resourceListChangedUIListener) { synchronized (resourceListChangedUIListeners) { @@ -1628,6 +1615,52 @@ public class ResourceManager { } } + 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 attributes = resource + .getResourceAttributesMap(); + if (null == attributes || attributes.size() < 1) { + return false; + } + Set keySet = attributes.keySet(); + Iterator 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; @@ -1643,4 +1676,4 @@ public class ResourceManager { public void shutdown() { threadHandle.interrupt(); } -} +} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java index c04b07e..b1c8de6 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java @@ -67,11 +67,17 @@ public class LocalResourceAttribute { } 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() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java deleted file mode 100644 index 974a87f..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 stdConfigFiles; - - public StandardConfiguration() { - stdConfigFiles = new HashMap(); - populateStandardConfigurationList(); - } - - private void populateStandardConfigurationList() { - Enumeration 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 getStandardResourceConfigurationList() { - return stdConfigFiles; - } - - public void setStandardResourceConfigurationList( - Map stdConfigFiles) { - this.stdConfigFiles = stdConfigFiles; - } - - public String getFilePath(String fileName) { - return stdConfigFiles.get(fileName); - } -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java index 09fecfc..7b8a6fd 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java @@ -91,7 +91,7 @@ public class Constants { 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"; @@ -102,6 +102,4 @@ public class Constants { 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 diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java index 5b8e299..21586d8 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java @@ -80,6 +80,13 @@ public class AttributeEditingSupport { 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; @@ -182,6 +189,11 @@ public class AttributeEditingSupport { // 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()) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java index d4443b4..5f76435 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -319,6 +319,10 @@ public class AttributeView extends ViewPart { @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; } @@ -328,6 +332,10 @@ public class AttributeView extends ViewPart { @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); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java index a9abf80..a09fa4a 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java @@ -304,8 +304,16 @@ public class ResourceManagerView extends ViewPart { 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() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java index dc44ad6..239818b 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java @@ -16,16 +16,10 @@ 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; @@ -49,13 +43,9 @@ import org.eclipse.ui.PlatformUI; */ 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; @@ -87,30 +77,7 @@ public class CreateResourcePage extends WizardPage { 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)); @@ -121,7 +88,6 @@ public class CreateResourcePage extends WizardPage { locationLbl = new Label(cusConfigComp, SWT.NONE); locationLbl.setText("Location:"); - locationLbl.setEnabled(false); locationTxt = new Text(cusConfigComp, SWT.BORDER); gd = new GridData(); @@ -129,7 +95,6 @@ public class CreateResourcePage extends WizardPage { gd.horizontalAlignment = SWT.FILL; gd.grabExcessHorizontalSpace = true; locationTxt.setLayoutData(gd); - locationTxt.setEnabled(false); btnBrowse = new Button(cusConfigComp, SWT.NONE); btnBrowse.setText("Browse"); @@ -137,7 +102,7 @@ public class CreateResourcePage extends WizardPage { 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)); @@ -158,74 +123,12 @@ public class CreateResourcePage extends WizardPage { // 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 configMap; - configMap = Activator.getDefault().getResourceManager() - .getResourceConfigurationList(); - if (null != configMap) { - Iterator 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 @@ -235,29 +138,8 @@ public class CreateResourcePage extends WizardPage { 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); } } }); @@ -293,16 +175,6 @@ public class CreateResourcePage extends WizardPage { }); } - 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 { @@ -310,9 +182,6 @@ public class CreateResourcePage extends WizardPage { } catch (Exception e) { resourceCount = -1; } - if (cusResourceRbtn.getSelection()) { - configFilePath = locationTxt.getText(); - } if (null != configFilePath && configFilePath.length() > 0 && resourceCount >= 1) { -- 2.7.4