Package org.knime.core.ui.wrapper
Interface Wrapper<W>
- Type Parameters:
W- the class that is wrapped
- All Superinterfaces:
UI
- All Known Implementing Classes:
AbstractWrapper,ConnectionContainerWrapper,InteractiveWebViewsResultWrapper,NativeNodeContainerWrapper,NodeContainerWrapper,NodeInPortWrapper,NodeOutPortWrapper,SingleInteractiveWebViewResultWrapper,SingleNodeContainerWrapper,SubNodeContainerWrapper,WorkflowContextWrapper,WorkflowDefWrapper,WorkflowInPortWrapper,WorkflowManagerWrapper,WorkflowOutPortWrapper,WorkflowPersistorWrapper
Wraps another object and provides static methods to wrap and unwrap those.
Only intended for
UI-stuff.- Author:
- Martin Horn, University of Konstanz
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConcurrentMap<Integer,Wrapper<?>> The global wrapper map - not for direct access - usewrapOrGet(Object, Function)instead! -
Method Summary
Modifier and TypeMethodDescriptionunwrap()Unwraps the wrapped object.static <W> WChecks if the passed object is a wrapper (i.e.static org.knime.core.node.workflow.ConnectionContainerShortcut forunwrap(wrapper, ConnectionContainer.class).static org.knime.core.node.workflow.NodeContainerShortcut forunwrap(wrapper, NodeContainer.class).static Optional<org.knime.core.node.workflow.NodeContainer>unwrapNCOptional(UI wrapper) Shortcut forunwrapOptional(wrapper, NodeContainer.class).static <W> Optional<W>unwrapOptional(UI wrapper, Class<W> wrappedObjectClass) Checks if the passed object is a wrapper (i.e.static org.knime.core.node.workflow.WorkflowManagerShortcut forunwrap(wrapper, WorkflowManager.class).static Optional<org.knime.core.node.workflow.WorkflowManager>unwrapWFMOptional(UI wrapper) Shortcut forunwrapOptional(wrapper, WorkflowManager.class).static UITries to wrap the passed object into its specific UI-wrapper, e.g.static <W> Wrapper<W>Either returns a wrapper object stored in a central global wrapper map (with the identity hashcode as key - seeSystem.identityHashCode(Object)).static <W> booleanChecks whether a object wraps a certain object of a given class.
-
Field Details
-
WRAPPER_MAP
The global wrapper map - not for direct access - usewrapOrGet(Object, Function)instead!
-
-
Method Details
-
unwrap
W unwrap()Unwraps the wrapped object.- Returns:
- the wrapped object
-
unwrapWFM
Shortcut forunwrap(wrapper, WorkflowManager.class).- Parameters:
wrapper-- Returns:
- the wrapped workflow manager
-
unwrapWFMOptional
Shortcut forunwrapOptional(wrapper, WorkflowManager.class).- Parameters:
wrapper-- Returns:
- the wrapped workflow manager
-
unwrapNC
Shortcut forunwrap(wrapper, NodeContainer.class).- Parameters:
wrapper-- Returns:
- the unwrapped node container
-
unwrapNCOptional
Shortcut forunwrapOptional(wrapper, NodeContainer.class).- Parameters:
wrapper-- Returns:
- the unwrapped node container or an empty optional
- Since:
- 3.6
-
unwrapCC
Shortcut forunwrap(wrapper, ConnectionContainer.class).- Parameters:
wrapper-- Returns:
- the unwrapped node container
-
wrapOrGet
Either returns a wrapper object stored in a central global wrapper map (with the identity hashcode as key - seeSystem.identityHashCode(Object)). Or wraps the given object (see#wrap(Object, Class)). Its primary purpose is to workaround "1:1" wrappers. Within the eclipse UI very often instances are checked for object equality. Consequently, there must be exactly one wrapper class instance for a certain object to be wrapped. Two wrapper instances wrapping the same object should be avoided (this happens if, e.g. a getter method is called twice and each time a new wrapper instance is created around the same object returned). The global wrapper map caches object instances (weak references) for look up with the identity hashcode as key.- Parameters:
object- the object to be wrapped. Its identity hashcode serves as the key to look for an already existing wrapperwrap- function that does the wrapping if no already existing wrapper has been found (i.e. was cached)- Returns:
- a new or already existing wrapper instance that wraps an object of the given type
-
unwrap
Checks if the passed object is a wrapper (i.e. implementsWrapper) and returns the wrapped object. Otherwise anIllegalArgumentExceptionis thrown.- Parameters:
wrapper- the supposed wrapperwrappedObjectClass- the class of the object to be unwrapped- Returns:
- the unwrapped object
- Throws:
IllegalArgumentException- if the wrapper object is not a wrapper
-
unwrapOptional
Checks if the passed object is a wrapper (i.e. implementsWrapper) and returns the wrapped object. Otherwise an empty optional is returned.- Parameters:
wrapper- the supposed wrapperwrappedObjectClass- the class of the object to be unwrapped- Returns:
- the unwrapped object or an empty optional if it coudn't be unwrapped
- Throws:
IllegalArgumentException- if the unwrapped object is not compatible with the given wrapped object class
-
wraps
Checks whether a object wraps a certain object of a given class.- Parameters:
wrapper- the supposed wrapperwrappedObjectClass- the class of the object to check for- Returns:
trueif the object wraps an object with the given class,falseif it doesn't wrap it OR the object is not of typeWrapper
-
wrap
Tries to wrap the passed object into its specific UI-wrapper, e.g.WorkflowManagerintoWorkflowManagerUI. If it's already aUI-class, the very same object is just returned.- Parameters:
obj- the object to possibly wrap- Returns:
- the object wrapped into a UI-wrapper or itself if already UI
- Throws:
IllegalArgumentException- if the object is _not_ of typeUI,ConnectionContainerorNodeContainer
-