}
public static String getPossibleJSON(Object selection) throws DatabaseException {
- if(selection instanceof WorkbenchSelectionElement) return getPossibleJSON((WorkbenchSelectionElement)selection);
- WorkbenchSelectionElement element = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);
- if(element == null) return null;
- return getPossibleJSON(element);
+ WorkbenchSelectionElement element = getPossibleWorkbenchSelectionElement(selection);
+ return element != null ? getPossibleJSON(element) : null;
}
public static Resource getPossibleResource(Object selection) throws DatabaseException {
- if(selection instanceof WorkbenchSelectionElement) return getPossibleResource((WorkbenchSelectionElement)selection);
- WorkbenchSelectionElement element = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);
- if(element == null) return null;
- return getPossibleResource(element);
+ WorkbenchSelectionElement element = getPossibleWorkbenchSelectionElement(selection);
+ return element != null ? getPossibleResource(element) : null;
}
public static Variable getPossibleVariable(Object selection) throws DatabaseException {
- if(selection instanceof WorkbenchSelectionElement) return getPossibleVariable((WorkbenchSelectionElement)selection);
- WorkbenchSelectionElement element = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);
- if(element == null) return null;
- return getPossibleVariable(element);
+ WorkbenchSelectionElement element = getPossibleWorkbenchSelectionElement(selection);
+ return element != null ? getPossibleVariable(element) : null;
+ }
+
+ public static Resource getPossibleResourceFromSelection(RequestProcessor processor, Object selection) throws DatabaseException {
+ WorkbenchSelectionElement element = getPossibleWorkbenchSelectionElement(selection);
+ return element != null ? getPossibleResource(processor, element) : null;
+ }
+
+ public static Variable getPossibleVariableFromSelection(RequestProcessor processor, Object selection) throws DatabaseException {
+ WorkbenchSelectionElement element = getPossibleWorkbenchSelectionElement(selection);
+ return element != null ? getPossibleVariable(processor, element) : null;
}
public static Variable getPossibleVariable(Object[] selection) throws DatabaseException {
return wse.getContent(contentType);
}
-// public static <T> T getPossibleExplorerInput(Object selection) throws DatabaseException {
-// if(selection instanceof WorkbenchSelectionElement) return getPossibleExplorerInput((WorkbenchSelectionElement)selection);
-// WorkbenchSelectionElement element = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);
-// if(element == null) return null;
-// return getPossibleExplorerInput(element);
-// }
-
-// public static <T> T getPossibleExplorerColumn(Object selection) throws DatabaseException {
-// if(selection instanceof WorkbenchSelectionElement) return getPossibleExplorerColumn((WorkbenchSelectionElement)selection);
-// WorkbenchSelectionElement element = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);
-// if(element == null) return null;
-// return getPossibleExplorerColumn(element);
-// }
-
public static String getPossibleJSON(WorkbenchSelectionElement wse) throws DatabaseException {
return getPossibleJSON(Simantics.getSession(), wse);
}
return getPossibleElement(input, new AnyVariable(processor));
}
-// @SuppressWarnings("unchecked")
-// public static <T> T getPossibleExplorerInput(WorkbenchSelectionElement input) throws DatabaseException {
-// return ((T)getPossibleElement(input, new ExplorerInputContentType()));
-// }
-
public static <T> T getPossibleElement(Object input, WorkbenchSelectionContentType<T> contentType) {
Object single = getPossibleSingleElement(input);
if(single == null) return null;
}
return null;
}
-
-
+
+ private static WorkbenchSelectionElement getPossibleWorkbenchSelectionElement(Object selection) {
+ return getPossibleObject(selection, WorkbenchSelectionElement.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> T getPossibleObject(Object selection, Class<T> clazz) {
+ return clazz.isInstance(selection)
+ ? (T) selection
+ : ISelectionUtils.filterSingleSelection(selection, clazz);
+ }
+
}