Interface WidgetFactory
public interface WidgetFactory
A factory for creating different reusable widgets. Most of the widgets is
supplied only to make a consistent look and feel across different modules. That
is, when the user instructs a module to create a new model, it is desirable to
show a dialog that looks the same no matter which module that creates the model.
Example usage
Clients:final Color[] userDefinedColor = new Color[1]; ChooserWidget<Color> colorChooser = widgetFactory.getChooserWidget(Color.class); if(colorChooser != null) { colorChooser.showChooser(new ChooserWidget.ChooserCallback<Color>() { @Override public void cancelled() {} @Override public void done(Color chosenValue) { userDefinedColor[0] = chosenValue; } }); }ChooserWidget implementors:
widgetFactory.addChooserWidget(myChooserWidget, Color.class);
- Author:
- Per-Erik
-
Method Summary
Modifier and TypeMethodDescription<T> void
addChooserWidget
(ChooserWidget<T> widget, Class<T> chooserClass) Adds a new chooser widget for the specified type/class.<T> void
addMultiChooserWidget
(MultiChooserWidget<T> widget, Class<T> chooserClass) Adds a new multi-chooser widget for the specified type/class.<T> JDialog
createChooserDialog
(Class<T> choosableType, boolean onlyMultiChoosers, ChooserFilter<T> filter, ChooserDialogCallback<T> callback, Window parent, boolean isModal, boolean isRefreshable) Creates and returns a JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type.<T> JDialog
createChooserDialog
(Class<T> choosableType, T preselectionHint, boolean onlyMultiChoosers, ChooserFilter<T> filter, ChooserDialogCallback<T> callback, Window parent, boolean isModal, boolean isRefreshable) Creates and returns a JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type.createDefaultEdgeTypeFilter
(List<EdgeType> allTypes, ModelType modelType, SymbolType from, SymbolType to) Creates a default chooser filter for selecting an edge type between two symbol types for a given model type, taking the repository configuration into account.Creates and returns a list cell renderer.createModelTypeIcon
(ModelType type, Dimension size) Deprecated.createNewModelWidget
(String typeID, Consumer<MTCompleteModel> onCreate) Creates a new JDialog where the user can create a new model.Creates a new JDialog where the user can create a new model.default JDialog
createNewModelWidget
(ModelType type, Consumer<MTCompleteModel> onCreate) Creates a new JDialog where the user can create a new model.Creates a new JDialog where the user can change the name of a model.createRevisionOperationWidget
(Window parent, boolean modal, MTRevisionOperation op) Creates a new JDialog that lets the user perform a revision operation.Creates and returns a list cell renderer.Creates and returns a tree cell renderer.Returns a collection of all choosable types, that is, all types that has a registered chooser widget installed.<T> ChooserWidget<T>
getChooserWidget
(Class<T> chooserClass) Returns a chooser widget able to choose objects of the specified type/class, or null if no such widget can be found.Returns a menu builder widget, used to construct menus.Returns a collection of all mutli-choosable types, that is, all types that has a registered mutli-chooser widget installed.<T> MultiChooserWidget<T>
getMultiChooserWidget
(Class<T> chooserClass) Returns a mutli chooser widget able to choose objects of the specified type/class, or null if no such widget can be found.<T> void
removeChooserWidget
(ChooserWidget<T> widget, Class<T> chooserClass) Removes the specified widget if and only if it is the currently registered chooser widget for the specified class.<T> void
removeMultiChooserWidget
(MultiChooserWidget<T> widget, Class<T> chooserClass) Removes the specified widget if and only if it is the currently registered multi-chooser widget for the specified class.
-
Method Details
-
createRevisionOperationWidget
Creates a new JDialog that lets the user perform a revision operation.- Parameters:
op
- The operation to perform
-
createNewModelWidget
Creates a new JDialog where the user can create a new model. The user will be able to choose the type of model to create. The supplied model type will be selected by default (so if the user don't change it, a new model of that type will be created). When the model has been created, it is opened in aPage
.- Parameters:
type
- The initially selected model type, or null to let the widget select an arbitrary model type. If the type is not part of a registeredModelExtension
this argument is treated as null.- Returns:
- A new JDialog or null if the Shell is not in modeling state.
-
createNewModelWidget
Creates a new JDialog where the user can create a new model. The user will be able to choose the type of model to create. The supplied model type will be selected by default (so if the user don't change it, a new model of that type will be created). When the model has been created, it is opened in aPage
.- Parameters:
type
- The initially selected model type, or null to let the widget select an arbitrary model type. If the type is not part of a registeredModelExtension
this argument is treated as null.onCreate
- A callback that will be invoked when the model has been created and the page for it opened, or null if no callback is needed.- Returns:
- A new JDialog or null if the Shell is not in modeling state.
-
createNewModelWidget
Creates a new JDialog where the user can create a new model. The user will be able to choose the type of model to create. The supplied model type id will be used to lookup the corresponding model type. That type will be selected by default (so if the user don't change it, a new model of that type will be created). When the model has been created, it is opened in aPage
.
Note that this method is equivalent to looking up the model type manually and then callingcreateNewModelWidget(type, onCreate)
.- Parameters:
typeID
- The id of the initially selected model type, or null to let the widget select an arbitrary model type. If the type id is not part of a registeredModelExtension
this argument is treated as null.onCreate
- A callback that will be invoked when the model has been created and the page for it opened, or null if no callback is needed.- Returns:
- A new JDialog or null if the Shell is not in modeling state.
-
createRenameModelWidget
Creates a new JDialog where the user can change the name of a model.- Parameters:
model
- The model to change- Returns:
- a new (not visible) JDialog.
-
createTreeRendererWidget
TreeCellRenderer createTreeRendererWidget()Creates and returns a tree cell renderer. A new JLabel will be created each time, so keep that in mind when painting the tree. For large tree models, it is advisable to use the same component each time you paint.- Returns:
- A JLabel that implements TreeCellRenderer. Note that the label might not react to validate, repaint and the like.
-
createListRendererWidget
ListCellRenderer createListRendererWidget()Creates and returns a list cell renderer. A new JLabel will be created each time, so keep that in mind when painting. For large models, it is advisable to use the same component each time you paint.- Returns:
- A JLabel that implements ListCellRenderer. Note that the label might not react to validate, repaint and the like.
-
createTableRendererWidget
TableCellRenderer createTableRendererWidget()Creates and returns a list cell renderer. A new JLabel will be created each time, so keep that in mind when painting. For large models, it is advisable to use the same component each time you paint.- Returns:
- A JLabel that implements ListCellRenderer. Note that the label might not react to validate, repaint and the like.
-
createModelTypeIcon
Deprecated.DEPRECATED: This isn't a widget, use icon factory or URL:s instead. Creates an icon for a model type.- Parameters:
type
- the model typesize
- the preferred size of the icon- Returns:
- an icon, or null if there is no available renderering facility for drawables (RendererService).
-
getMenuBuilderWidget
MenuBuilderWidget getMenuBuilderWidget()Returns a menu builder widget, used to construct menus.- Returns:
- a menu builder widget, used to construct menus.
-
createChooserDialog
<T> JDialog createChooserDialog(Class<T> choosableType, boolean onlyMultiChoosers, ChooserFilter<T> filter, ChooserDialogCallback<T> callback, Window parent, boolean isModal, boolean isRefreshable) Creates and returns a JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type. The chooser will be initialized with the filter and callback. This method is equivalent to a call tocreateChooserDialog(Class, Object, boolean, ChooserFilter, ChooserDialogCallback, Window, boolean, boolean)
createChooserDialog} with a preselectionHint of null.- Type Parameters:
T
- The type parameter of the class. The type of the objects that the chooser should select.- Parameters:
choosableType
- The class that the dialog should find a chooser for.onlyMultiChoosers
- true to only use multi-choosers. This can be used if you need a multi-chooser. False implies first trying to find a single-chooser, if none is found a multi-chooser is searched for.filter
- A ChooserFilter used to narrow the set of recommended objects or null if no filter is to be used (shows everything).callback
- called when the dialog closes.parent
- The parent of the dialog or null. A null value will center the new dialog on the primary screen or on the shell frame if one exists.isModal
- True to make a model dialog, false otherwise.isRefreshable
-true
if the chooser should have a "refresh" button for updating the selectable content.- Returns:
- a new (non shared) JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type. Note that the chooser might be shared.
- See Also:
-
createChooserDialog
<T> JDialog createChooserDialog(Class<T> choosableType, T preselectionHint, boolean onlyMultiChoosers, ChooserFilter<T> filter, ChooserDialogCallback<T> callback, Window parent, boolean isModal, boolean isRefreshable) Creates and returns a JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type. The chooser will be initialized with the preselctedHint, filter and callback.- Type Parameters:
T
- The type parameter of the class. The type of the objects that the chooser should select.- Parameters:
choosableType
- The class that the dialog should find a chooser for.preselectionHint
- a hint to the chooser what value to select until the user has made a choice or null to not use any hint.onlyMultiChoosers
- true to only use multi-choosers. This can be used if you need a multi-chooser. False implies first trying to find a single-chooser, if none is found a multi-chooser is searched for.filter
- A ChooserFilter used to narrow the set of recommended objects or null if no filter is to be used (shows everything).callback
- called when the dialog closes.parent
- The parent of the dialog or null. A null value will center the new dialog on the primary screen or on the shell frame if one exists.isModal
- True to make a model dialog, false otherwise.isRefreshable
-true
if the chooser should have a "refresh" button for updating the selectable content.- Returns:
- a new (non shared) JDialog containing a chooser for the specified choosable type, or null if no chooser can be found for that type. Note that the chooser might be shared.
- See Also:
-
getChoosableTypes
Collection<Class> getChoosableTypes()Returns a collection of all choosable types, that is, all types that has a registered chooser widget installed. This includes multi-chooser widgets.- Returns:
- a collection of all choosable types, that is, all types that has a registered chooser widget installed. This includes multi-chooser widgets.
- See Also:
-
getMultiChoosableTypes
Collection<Class> getMultiChoosableTypes()Returns a collection of all mutli-choosable types, that is, all types that has a registered mutli-chooser widget installed. This excludes single-chooser widgets.- Returns:
- a collection of all choosable types, that is, all types that has a registered chooser widget installed. This excludes single-chooser widgets.
- See Also:
-
getChooserWidget
Returns a chooser widget able to choose objects of the specified type/class, or null if no such widget can be found.- Type Parameters:
T
- The type parameter of the class.- Parameters:
chooserClass
- The class that the chooser can "chose".- Returns:
- a chooser widget able to choose objects of the specified type/class, or null if no such widget can be found.
- See Also:
-
removeChooserWidget
Removes the specified widget if and only if it is the currently registered chooser widget for the specified class. If it isn't, some other widget has replaced the widget for that class and removal is not necessary. Thus, this method guarantees that the specified widget will no longer be registered for the specified class.- Type Parameters:
T
- The type parameter of the class.- Parameters:
widget
- The widget to removechooserClass
- The class that the widget was added with
-
addChooserWidget
Adds a new chooser widget for the specified type/class. If a chooser of this type/class already exists, the new widget will replace it in future calls togetChooserWidget
. This does not imply that visible or existing references to the old widget is replaced in clients, unless the clients callgetChooserWidget
again.- Type Parameters:
T
- The type parameter of the class.- Parameters:
widget
- The chooser widget that can handle the specified type/class.chooserClass
- The class that the chooser can "chose".- See Also:
-
getMultiChooserWidget
Returns a mutli chooser widget able to choose objects of the specified type/class, or null if no such widget can be found.- Type Parameters:
T
- The type parameter of the class.- Parameters:
chooserClass
- The class that the chooser can "chose".- Returns:
- a chooser widget able to choose multiple objects of the specified type/class, or null if no such widget can be found.
- See Also:
-
removeMultiChooserWidget
Removes the specified widget if and only if it is the currently registered multi-chooser widget for the specified class. If it isn't, some other widget has replaced the widget for that class and removal is not necessary. Thus, this method guarantees that the specified widget will no longer be registered for the specified class.- Type Parameters:
T
- The type parameter of the class.- Parameters:
widget
- The widget to removechooserClass
- The class that the widget was added with
-
addMultiChooserWidget
Adds a new multi-chooser widget for the specified type/class. If a chooser of this type/class already exists, the new widget will replace it in future calls togetChooserWidget
. This does not imply that visible or existing references to the old widget is replaced in clients, unless the clients callgetMultiChooserWidget
again.- Type Parameters:
T
- The type parameter of the class.- Parameters:
widget
- The multi-chooser widget that can handle the specified type/class.chooserClass
- The class that the chooser can "chose".- See Also:
-
createDefaultEdgeTypeFilter
ChooserFilter<EdgeType> createDefaultEdgeTypeFilter(List<EdgeType> allTypes, ModelType modelType, SymbolType from, SymbolType to) Creates a default chooser filter for selecting an edge type between two symbol types for a given model type, taking the repository configuration into account.
-