// Notify the UI listener
newResourceFoundNotification(resource);
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.INFO.ordinal(),
+ new Date(),
+ "Resource Found ["
+ + resource.getResourceURI()
+ + "].");
+
// Send an initial GET request to get the resource
// attributes
try {
.getLogManager()
.log(Level.ERROR.ordinal(),
new Date(),
- "[" + e.getClass().getSimpleName()
- + "]" + e.code().toString()
- + "-" + e.message());
+ Utility.getSimulatorErrorString(e,
+ null));
}
}
});
resource.setResourceModel(resourceModelN);
Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
-
- // TODO: For debugging
+ resource.setResourceAttributesMap(attributeMap);
+ // TODO: Printing the values for debugging
if (null != attributeMap) {
RemoteResourceAttribute.printAttributes(attributeMap);
- System.out.println("Attributes found: " + (null != attributeMap));
- System.out.println("No of attributes: " + attributeMap.size());
-
- resource.setResourceAttributesMap(attributeMap);
}
return resource;
}
resource.setFavorite(true);
synchronized (favoriteResources) {
favoriteResources.add(resource);
- favoriteURIList.add(resource.getResourceURI());
}
}
}
}
+ public void addResourceURItoFavorites(RemoteResource resource) {
+ if (null == resource) {
+ return;
+ }
+ synchronized (favoriteURIList) {
+ favoriteURIList.add(resource.getResourceURI());
+ }
+ }
+
public void removeResourceURIFromFavorites(RemoteResource resource) {
if (null == resource) {
return;
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
return null;
}
if (null != attributeMapN) {
}
attribute.setAllowedValues(valueList);
}
- /*
- * Type baseType = attribute.getAttValBaseType();
- *
- * if(baseType == Type.INT) { //int[] values =
- * attributeN.getAllowedValues();
- * attribute.setAllowedValues
- * (attributeN.getAllowedValues()); } else
- * if(baseType == Type.DOUBLE) { double[] values =
- * attributeN.getAllowedValues();
- * attribute.setAllowedValues
- * (Utility.converArrayToList(values)); } else
- * if(baseType == Type.BOOL) { //boolean[] values =
- * attributeN.getAllowedValues(); List<Object> obj =
- * new ArrayList<Object>(); obj.add(true);
- * obj.add(false); attribute.setAllowedValues(obj);
- * } else if(baseType == Type.STRING) { String[]
- * values = attributeN.getAllowedValues();
- * attribute.
- * setAllowedValues(Utility.converArrayToList
- * (values)); }
- */
}
resourceAttributeMap.put(attName, attribute);
}
}
}
- // TODO: Temporarily used to display the resource in the UI
- public List<String> getURIList() {
- List<String> list = new ArrayList<String>();
- synchronized (resourceMap) {
- /*
- * Set<String> idSet = resourceMap.keySet(); Iterator<String> idItr
- * = idSet.iterator(); String sId; RemoteResource resource;
- * while(idItr.hasNext()) { sId = idItr.next(); resource =
- * resourceMap.get(sId); if(null == resource) { continue; }
- * list.add(resource.getResourceURI()); }
- */
- Set<String> uriSet = resourceMap.keySet();
- Iterator<String> uriItr = uriSet.iterator();
- String uri;
- while (uriItr.hasNext()) {
- uri = uriItr.next();
- if (null != uri) {
- list.add(uri);
- }
- }
-
- // Sort the types
- Collections.sort(list);
- }
- return list;
- }
-
public synchronized Set<String> getLastKnownSearchTypes() {
return lastKnownSearchTypes;
}
}
public boolean findResourceRequest(Set<String> searchTypes) {
- if (null == searchTypes || searchTypes.size() < 1) {
- return false;
- }
boolean result = false;
- Iterator<String> searchItr = searchTypes.iterator();
- String rType;
- while (searchItr.hasNext()) {
- rType = searchItr.next();
+ if (null == searchTypes || searchTypes.size() < 1) {
try {
- SimulatorManager.findResource(rType, findResourceListener);
+ SimulatorManager.findResource(findResourceListener);
result = true;
} catch (SimulatorException e) {
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
+ }
+ } else {
+ Iterator<String> searchItr = searchTypes.iterator();
+ String rType;
+ while (searchItr.hasNext()) {
+ rType = searchItr.next();
+ try {
+ SimulatorManager.findResource(rType, findResourceListener);
+ result = true;
+ } catch (SimulatorException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
+ }
}
}
return result;
}
public void deleteResources(final Set<String> searchTypes) {
- if (null == searchTypes || searchTypes.size() < 1) {
- return;
- }
new Thread() {
public void run() {
- Iterator<String> typeItr = searchTypes.iterator();
- String resType;
- while (typeItr.hasNext()) {
- resType = typeItr.next();
- deleteResourcesByType(resType);
+ if (null == searchTypes || searchTypes.size() < 1) {
+ // Delete all cached details of resources
+ resourceMap.clear();
+ favoriteResources.clear();
// Change the current resource in selection
- updateCurrentResourceInSelection(searchTypes);
+ setCurrentResourceInSelection(null);
+ resourceSelectionChangedUINotification(null);
+ } else {
+ Iterator<String> typeItr = searchTypes.iterator();
+ String resType;
+ while (typeItr.hasNext()) {
+ resType = typeItr.next();
+ deleteResourcesByType(resType);
+
+ // Change the current resource in selection
+ updateCurrentResourceInSelection(searchTypes);
+ }
}
}
}.start();
if (null != types) {
exist = types.contains(resourceType);
if (exist) {
- // Remove the resource
- keyItr.remove();
// Remove the resource from favorites list.
removeResourceFromFavorites(resource);
+ // Remove the resource
+ keyItr.remove();
}
}
}
return autoStatus;
}
- public Map<String, String> getDummyAttributes() {
- Map<String, String> attributes = new HashMap<String, String>();
- attributes.put("intensity", "1");
- attributes.put("power", "off");
- return attributes;
- }
-
public List<RemoteResource> getResourceList() {
List<RemoteResource> resourceList = new ArrayList<RemoteResource>();
synchronized (resourceMap) {
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
System.out.println("ResourceManager: called native put");
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ Utility.getSimulatorErrorString(e,
+ "Failed to convert the attribute value."));
} catch (SimulatorException e) {
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
} else if (attType == Type.DOUBLE) {
double attValue;
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(), new Date(),
- e.getMessage());
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ Utility.getSimulatorErrorString(e,
+ "Failed to convert the attribute value."));
} catch (SimulatorException e) {
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
} else if (attType == Type.BOOL) {
boolean attValue;
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
} else if (attType == Type.STRING) {
String attValue;
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-"
- + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
System.out.println("Observer called.");
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
}
}
Activator
.getDefault()
.getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "[" + e.getClass().getSimpleName() + "]"
- + e.code().toString() + "-" + e.message());
+ .log(Level.ERROR.ordinal(), new Date(),
+ Utility.getSimulatorErrorString(e, null));
return;
}
// Update the status
return valueList;
}
+ // Method added for debugging purpose
public static void printAttributes(
Map<String, RemoteResourceAttribute> attributeMap) {
Iterator<String> itr = attributeMap.keySet().iterator();
public static final String GET = "Get";
public static final String PUT = "Put";
public static final String POST = "Post";
+ public static final String OBSERVE = "Observe";
+ public static final String STOP_OBSERVE = "Stop Observe";
public static final String ENABLE = "Enable";
public static final String DISABLE = "Disable";
package oic.simulator.clientcontroller.utils;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.oic.simulator.SimulatorException;
+
/**
* This class has common utility methods.
*/
return strArr;
}
- /*
- * public static List<Object> converArrayToList(int[] arr) { if(null == arr
- * || arr.length < 1) { return null; } List<Object> valueList = new
- * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
- * valueList; }
- *
- * public static List<Object> converArrayToList(double[] arr) { if(null ==
- * arr || arr.length < 1) { return null; } List<Object> valueList = new
- * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
- * valueList; }
- *
- * public static List<Object> converArrayToList(boolean[] arr) { if(null ==
- * arr || arr.length < 1) { return null; } List<Object> valueList = new
- * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
- * valueList; }
- *
- * public static List<Object> converArrayToList(String[] arr) { if(null ==
- * arr || arr.length < 1) { return null; } List<Object> valueList = new
- * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
- * valueList; }
- */
+ public static Set<String> splitStringByComma(String text) {
+ Set<String> tokenSet = null;
+ if (null != text) {
+ String[] token = text.split(",");
+ if (null != token) {
+ tokenSet = new HashSet<String>();
+ for (String tok : token) {
+ tok = tok.trim();
+ if (tok.length() > 0) {
+ tokenSet.add(tok);
+ }
+ }
+ }
+ }
+ return tokenSet;
+ }
+
+ public static String getSimulatorErrorString(Exception e, String info) {
+ if (null == e) {
+ return null;
+ }
+ String detail;
+ if (e instanceof SimulatorException) {
+ SimulatorException simEx = (SimulatorException) e;
+ detail = simEx.message() + "\n";
+ detail += "Exception Type: " + simEx.getClass().getSimpleName()
+ + "\n";
+ detail += "Error code: " + simEx.code().toString();
+ } else {
+ detail = info + "\n";
+ detail += "Exception Type: " + e.getClass().getSimpleName() + "\n";
+ detail += "Message: " + e.getMessage();
+ }
+ return detail;
+ }
}
\ No newline at end of file
@Override
public void run() {
- changeReqBtnVisibility(autoType, false);
+ // changeReqBtnVisibility(autoType, false);
}
});
}
@Override
public void run() {
- changeReqBtnVisibility(autoType, true);
+ // changeReqBtnVisibility(autoType, true);
}
});
}
@Override
public void run() {
- changeReqBtnVisibility(autoType, true);
+ // changeReqBtnVisibility(autoType, true);
}
});
}
}
private void updateObserve(RemoteResource resource) {
- if (null == resource) {
+ if (null == resource || observeResButton.isDisposed()) {
return;
}
boolean observed = resource.isObserved();
- if (!observeResButton.isDisposed()) {
- observeResButton.setSelection(observed);
+ if (observed) {
+ observeResButton.setText(Constants.STOP_OBSERVE);
+ } else {
+ observeResButton.setText(Constants.OBSERVE);
}
}
public void createPartControl(Composite parent) {
Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
- parent.setLayout(new GridLayout(2, false));
+ parent.setLayout(new GridLayout());
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
parent.setLayoutData(gd);
setupAttributeTable(attGroup);
- setupMessageArea(parent);
-
- setupResourceLevelOpsArea(parent);
+ setupRequestControls(parent);
setUIListeners();
}
}
- private void setupMessageArea(Composite parent) {
+ private void setupRequestControls(Composite parent) {
GridData gd;
Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
- Group msgTypesGrp = new Group(parent, SWT.NONE);
+ Composite opsComp = new Composite(parent, SWT.NONE);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
- msgTypesGrp.setLayoutData(gd);
- GridLayout grid = new GridLayout(3, false);
- msgTypesGrp.setLayout(grid);
- msgTypesGrp.setText("Request Types");
- msgTypesGrp.setBackground(color);
+ opsComp.setLayoutData(gd);
+ GridLayout grid = new GridLayout(5, false);
+ opsComp.setLayout(grid);
+ opsComp.setBackground(color);
- getButton = new Button(msgTypesGrp, SWT.PUSH);
+ getButton = new Button(opsComp, SWT.PUSH);
getButton.setText("GET");
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.widthHint = 50;
getButton.setLayoutData(gd);
- putButton = new Button(msgTypesGrp, SWT.PUSH);
+ putButton = new Button(opsComp, SWT.PUSH);
putButton.setText("PUT");
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.widthHint = 50;
putButton.setLayoutData(gd);
- postButton = new Button(msgTypesGrp, SWT.PUSH);
+ postButton = new Button(opsComp, SWT.PUSH);
postButton.setText("POST");
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.widthHint = 50;
postButton.setLayoutData(gd);
- }
- private void setupResourceLevelOpsArea(Composite parent) {
- GridData gd;
- Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
- Group resOpsGrp = new Group(parent, SWT.NONE);
+ observeResButton = new Button(opsComp, SWT.PUSH);
+ observeResButton.setText(Constants.OBSERVE);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
- resOpsGrp.setLayoutData(gd);
- GridLayout grid = new GridLayout(2, false);
- resOpsGrp.setLayout(grid);
- resOpsGrp.setText("Resource-Level Operations");
- resOpsGrp.setBackground(color);
+ observeResButton.setLayoutData(gd);
- automateButton = new Button(resOpsGrp, SWT.PUSH);
+ automateButton = new Button(opsComp, SWT.PUSH);
automateButton.setText("Automation");
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
automateButton.setLayoutData(gd);
-
- observeResButton = new Button(resOpsGrp, SWT.CHECK);
- observeResButton.setText("Observe");
- gd = new GridData();
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalAlignment = SWT.FILL;
- observeResButton.setLayoutData(gd);
}
private void setupAttributeTable(Group attGroup) {
observeResButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- boolean checked = observeResButton.getSelection();
- if (checked) {
+ if (observeResButton.getText().equals(Constants.OBSERVE)) {
resourceManager.sendObserveRequest(resourceInSelection);
+ observeResButton.setText(Constants.STOP_OBSERVE);
} else {
resourceManager
.sendCancelObserveRequest(resourceInSelection);
+ observeResButton.setText(Constants.OBSERVE);
}
}
});
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
out.close();
}
} catch (IOException e) {
- System.out.println("Error occurred during close.");
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "[" + e.getClass().getSimpleName()
+ + "]" + e.getMessage());
}
}
}
@Override
public void onNewResourceFound(final RemoteResource resource) {
- System.out.println("View: onNewResourceFound");
if (null == resource) {
return;
}
// Close the find dialog
if (null != findDialog) {
- boolean status = findDialog.close();
- System.out
- .println("dialog close status: " + status);
+ findDialog.close();
}
// Close the refresh dialog
if (null != refreshDialog) {
- boolean status = refreshDialog.close();
- System.out
- .println("dialog close status: " + status);
+ refreshDialog.close();
}
}
});
folder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- /*
- * CTabItem selectedTab = folder.getSelection(); if(selectedTab
- * == foundResTab) { System.out.println("Found resources tab");
- * } else { System.out.println("Favorite resources tab"); }
- */
// Tab is switched.
treeViewer.setSelection(null);
favTreeViewer.setSelection(null);
if (null == resource) {
return;
}
- System.out.println("Selected resource:"
- + resource.getResourceURI());
if (!resource.isFavorite()) {
resourceManager
.addResourcetoFavorites(resource);
+ resourceManager
+ .addResourceURItoFavorites(resource);
} else {
resourceManager
.removeResourceFromFavorites(resource);
Set<String> searchTypes = findWizard
.getSearchTypes();
- if (null != searchTypes) {
- System.out.println(searchTypes);
- // Call native method to clear existing
- // resources of
- // the given search types.
- resourceManager.deleteResources(searchTypes);
-
- // Update the tree
- treeViewer.refresh();
- favTreeViewer.refresh();
-
- // Call native method to find Resources
- boolean result = resourceManager
- .findResourceRequest(searchTypes);
- if (result) {
- searchUIOperation(false);
- } else {
- MessageDialog
- .openError(Display.getDefault()
- .getActiveShell(),
- "Find Resource status",
- "Operation failed due to some problems in core layer.");
- }
-
- // Store this information for refresh
- // functionality
- resourceManager
- .setLastKnownSearchTypes(searchTypes);
+ // Delete cached details of resources based on the
+ // given search types.
+ // If there are no resource types to search, then
+ // all resources
+ // will be deleted.
+ resourceManager.deleteResources(searchTypes);
+
+ // Update the tree
+ treeViewer.refresh();
+ favTreeViewer.refresh();
- // Change the refresh visibility
- refreshButton.setEnabled(true);
+ // Call native method to find Resources
+ boolean result = resourceManager
+ .findResourceRequest(searchTypes);
+ if (result) {
+ searchUIOperation(false);
+ } else {
+ MessageDialog
+ .openError(Display.getDefault()
+ .getActiveShell(),
+ "Find Resource status",
+ "Operation failed due to some problems in core layer.");
}
+
+ // Store this information for refresh
+ // functionality
+ resourceManager
+ .setLastKnownSearchTypes(searchTypes);
+
+ // Change the refresh visibility
+ refreshButton.setEnabled(true);
}
}
});
public void widgetSelected(SelectionEvent e) {
Set<String> searchTypes = resourceManager
.getLastKnownSearchTypes();
- if (null == searchTypes) {
- return;
- }
setFoundResource(false);
- // Call native method to clear existing resources of the given
- // search types.
+ // Delete cached details of resources based on the given search
+ // types.
+ // If there are no resource types to search, then all resources
+ // will be deleted.
resourceManager.deleteResources(searchTypes);
// Update the tree
if (null == resource) {
return;
}
- System.out.println("Selected resource: "
- + resource.getResourceURI());
resourceManager.resourceSelectionChanged(resource);
}
}
try {
Thread.sleep(Constants.FIND_RESOURCES_TIMEOUT * 1000);
} catch (InterruptedException e) {
- System.out.println("Interrupted during sleep.");
return;
}
@Override
public Object[] getElements(Object parent) {
- System.out.println("Inside getElements()");
List<RemoteResource> resourceList = Activator.getDefault()
.getResourceManager().getResourceList();
return resourceList.toArray();
@Override
public Object[] getElements(Object parent) {
- System.out.println("Inside getElements()");
List<RemoteResource> resourceList = Activator.getDefault()
.getResourceManager().getFavResourceList();
return resourceList.toArray();
package oic.simulator.clientcontroller.view.dialogs;
-import java.util.HashSet;
import java.util.Set;
import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
*/
public class FindResourcePage extends WizardPage {
- private Button stdResTypeRbtn;
- private CCombo resourceTypeCmb;
- private Button cusResTypeRbtn;
+ private Button allRbtn;
+ private Button resTypeRbtn;
private Text resTypeTxt;
- private Label stdRTypeLbl;
- private Label cusRTypeLbl;
+ private Label resTypeLbl;
private Set<String> typesToSearch;
- private String dummyRType;
-
protected FindResourcePage() {
super("Find Resource");
}
compContent.setLayoutData(gd);
Group configGroup = new Group(compContent, SWT.NONE);
- gridLayout = new GridLayout(1, false);
+ gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 10;
gridLayout.marginTop = 5;
configGroup.setLayout(gridLayout);
configGroup.setLayoutData(gd);
configGroup.setText("Resource Type");
- stdResTypeRbtn = new Button(configGroup, SWT.RADIO);
- stdResTypeRbtn.setText("Standard OIC Resources");
-
- Composite stdConfigComp = new Composite(configGroup, SWT.NONE);
- stdConfigComp.setLayout(new GridLayout(2, false));
+ allRbtn = new Button(configGroup, SWT.RADIO);
+ allRbtn.setText("All");
gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- stdConfigComp.setLayoutData(gd);
-
- stdRTypeLbl = new Label(stdConfigComp, SWT.NONE);
- stdRTypeLbl.setText("ResourceType:");
- stdRTypeLbl.setEnabled(false);
+ gd.horizontalSpan = 2;
+ allRbtn.setLayoutData(gd);
- resourceTypeCmb = new CCombo(stdConfigComp, SWT.READ_ONLY | SWT.BORDER);
+ resTypeRbtn = new Button(configGroup, SWT.RADIO);
+ resTypeRbtn.setText("Specific Resource types (seperated by commas)");
gd = new GridData();
- gd.widthHint = 150;
- resourceTypeCmb.setLayoutData(gd);
- resourceTypeCmb.setEnabled(false);
+ gd.horizontalSpan = 2;
+ resTypeRbtn.setLayoutData(gd);
- cusResTypeRbtn = new Button(configGroup, SWT.RADIO);
- cusResTypeRbtn.setText("Custom Resources");
+ resTypeLbl = new Label(configGroup, SWT.NONE);
+ resTypeLbl.setText("Resource Types:");
+ resTypeLbl.setEnabled(false);
- Composite cusConfigComp = new Composite(configGroup, SWT.NONE);
- cusConfigComp.setLayout(new GridLayout(2, false));
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- cusConfigComp.setLayoutData(gd);
-
- cusRTypeLbl = new Label(cusConfigComp, SWT.NONE);
- cusRTypeLbl.setText("Enter ResourceType:");
- cusRTypeLbl.setEnabled(false);
-
- resTypeTxt = new Text(cusConfigComp, SWT.BORDER);
+ resTypeTxt = new Text(configGroup, SWT.BORDER);
+ resTypeTxt.setToolTipText("Ex: sample.light, hall.fridge");
+ resTypeTxt.setMessage("Ex: sample.light, hall.fridge");
gd = new GridData();
gd.minimumWidth = 200;
gd.horizontalAlignment = SWT.FILL;
resTypeTxt.setLayoutData(gd);
resTypeTxt.setEnabled(false);
- populateDataInUI();
-
addUIListeners();
setControl(compContent);
}
- private void populateDataInUI() {
- // Populate Standard resource-types in Combo
- populateResourceTypeCombo();
- }
-
- private void populateResourceTypeCombo() {
- /*
- * List<String> configList; configList =
- * Activator.getDefault().getManager().getResourceConfigurationList();
- * if(null != configList) { Iterator<String> itr =
- * configList.iterator(); while(itr.hasNext()) {
- * resourceTypeCmb.add(itr.next()); } }
- */
-
- // TODO: Temporarily adding a resourceType for testing
- resourceTypeCmb.add("oic.r.light");
- // resourceTypeCmb.add("sample.light");
-
- // By default, selecting the first item in the resourceType combo
- if (resourceTypeCmb.getItemCount() > 0) {
- resourceTypeCmb.select(0);
- // TODO: Get the RAML configuration file path of the selected
- // resource
- // configFilePath =
- // Activator.getManager().getConfigFilePath(resourceTypeCmb.getItem(0));
- }
- }
-
private void addUIListeners() {
- stdResTypeRbtn.addSelectionListener(new SelectionAdapter() {
+ allRbtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- // Clear the existing items from the search list
- if (null != typesToSearch)
- typesToSearch.clear();
-
- // Set the configFilePath to the first item in the combo
- if (resourceTypeCmb.getItemCount() > 0) {
- resourceTypeCmb.select(0);
- addSearchType(resourceTypeCmb.getText());
- }
-
- setPageComplete(isSelectionDone());
-
+ typesToSearch = null;
+ setPageComplete(true);
// Change the visibility of widgets
- changeVisibility(true);
+ changeVisibility(false);
}
});
- cusResTypeRbtn.addSelectionListener(new SelectionAdapter() {
+ resTypeRbtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- // Clear the existing items from the search list
- if (null != typesToSearch)
- typesToSearch.clear();
-
- addSearchType(resTypeTxt.getText());
-
- setPageComplete(isSelectionDone());
+ String typeText = resTypeTxt.getText();
+ if (null != typeText && typeText.length() > 0) {
+ typesToSearch = Utility.splitStringByComma(typeText);
+ }
+ if (null != typesToSearch && typesToSearch.size() > 0) {
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
// Change the visibility of widgets
- changeVisibility(false);
-
+ changeVisibility(true);
resTypeTxt.setFocus();
}
});
- resourceTypeCmb.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int index = resourceTypeCmb.getSelectionIndex();
- if (index < 0) {
- return;
- }
- String resourceType = resourceTypeCmb.getItem(index);
- addSearchType(resourceType);
- setPageComplete(isSelectionDone());
- }
- });
-
resTypeTxt.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- String resourceType = resTypeTxt.getText();
- if (null != dummyRType) {
- removeSearchType(dummyRType);
+ String typeText = resTypeTxt.getText();
+ typesToSearch = Utility.splitStringByComma(typeText);
+ if (null != typesToSearch && typesToSearch.size() > 0) {
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
}
- dummyRType = resourceType;
- addSearchType(resourceType);
- setPageComplete(isSelectionDone());
}
});
}
private void changeVisibility(boolean standard) {
- stdRTypeLbl.setEnabled(standard);
- resourceTypeCmb.setEnabled(standard);
- cusRTypeLbl.setEnabled(!standard);
- resTypeTxt.setEnabled(!standard);
- }
-
- private boolean isSelectionDone() {
- if (null == typesToSearch || typesToSearch.size() < 1) {
- return false;
- }
- return true;
- }
-
- private void addSearchType(String resourceType) {
- if (null == resourceType)
- return;
- resourceType = resourceType.trim();
- if (resourceType.length() < 1) {
- return;
- }
- if (null == typesToSearch) {
- typesToSearch = new HashSet<String>();
- }
- typesToSearch.add(resourceType);
- }
-
- private void removeSearchType(String resourceType) {
- if (null == resourceType || null == typesToSearch)
- return;
- resourceType = resourceType.trim();
- if (resourceType.length() < 1) {
- return;
- }
- typesToSearch.remove(resourceType);
+ resTypeLbl.setEnabled(standard);
+ resTypeTxt.setEnabled(standard);
}
public Set<String> getSearchTypes() {
} 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;
}
}
Calendar calendar;
calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR, h);
+ calendar.set(Calendar.HOUR_OF_DAY, h);
calendar.set(Calendar.MINUTE, m);
calendar.set(Calendar.SECOND, s);