public class DefaultLayoutChangeStrategy extends java.lang.Object implements LayoutChangeStrategy
LayoutChangeStrategy
heavily depends on the methods of PredefinedDockSituation
. It
also offers a set of methods that may be interesting for subclasses which do not use a PredefinedDockSituation
.Modifier and Type | Class and Description |
---|---|
protected class |
DefaultLayoutChangeStrategy.SettingAccess
A wrapper around a
Setting , allows algorithms access to the settings
but also allows to modify the data without changing the setting. |
Constructor and Description |
---|
DefaultLayoutChangeStrategy() |
Modifier and Type | Method and Description |
---|---|
protected void |
applyInvisibleLayout(DockFrontendInternals frontend,
DockSituation situation,
DefaultLayoutChangeStrategy.SettingAccess setting)
Applies
setting to the invisible elements. |
protected void |
applyLayout(DockFrontendInternals frontend,
DockSituation situation,
DefaultLayoutChangeStrategy.SettingAccess setting,
boolean entry)
Applies the layout described in
setting to the visible elements. |
protected java.util.Collection<Dockable> |
approveClosing(DockFrontendInternals frontend,
DockSituation situation,
DefaultLayoutChangeStrategy.SettingAccess setting)
Asks the
VetoManager whether some Dockable s can be hidden. |
protected DefaultLayoutChangeStrategy.SettingAccess |
createAccess(DockFrontendInternals frontend,
Setting setting)
Creates a wrapper around
setting that allows the algorithm of this
LayoutChangeStrategy to access the setting. |
DockFrontendPerspective |
createPerspective(DockFrontendInternals frontend,
boolean entry,
FrontendPerspectiveCache cache)
Creates a
Perspective that is used to read and write perspectives related to frontend . |
PredefinedDockSituation |
createSituation(DockFrontendInternals frontend,
boolean entry)
Forwards to
createSituation(DockFrontendInternals, boolean, boolean) with the
last argument set to false . |
protected PredefinedDockSituation |
createSituation(DockFrontendInternals frontend,
boolean entry,
boolean onSetLayout)
Creates a
DockSituation which represents all the knowledge
frontend currently has. |
PropertyTransformer |
createTransformer(DockFrontendInternals frontend)
Creates a converter for reading and writing
DockableProperty s. |
void |
estimateLocations(DockFrontendInternals frontend,
DockSituation situation,
DockLayoutComposition layout)
Tries to fill the property
location
for each element in layout . |
protected java.util.Set<Dockable> |
estimateVisible(DockFrontendInternals frontend,
DockSituation situation,
DockLayoutComposition layout)
Tries to estimate which of the currently visible
Dockable s will
still be visible if layout is applied to frontend . |
protected java.util.Collection<Dockable> |
getClosingDockables(DockFrontendInternals frontend,
java.util.Set<Dockable> visible)
Creates a collection of all the
Dockable s that are about to be closed. |
PlaceholderStrategy |
getPlaceholderStrategy(DockFrontendInternals frontend)
Gets the default
PlaceholderStrategy which should be used to filter placeholders by frontend . |
protected java.util.Map<java.lang.String,DockableProperty> |
listEstimateLocations(DockSituation situation,
DockLayoutComposition layout)
Tries to estimate the location of missing
Dockable s. |
protected java.util.Map<java.lang.String,DockLayoutComposition> |
listLayouts(DockSituation situation,
DockLayoutComposition layout)
Tries to estimate the layouts of missing
Dockable s. |
boolean |
setLayout(DockFrontendInternals frontend,
Setting setting,
boolean entry)
Changes the layout of
frontend by reading and applying setting . |
protected boolean |
shouldPredefine(Dockable dockable)
Tells whether the element
dockable should be added as predefined element to the PredefinedDockSituation
that is created by createSituation(DockFrontendInternals, boolean, boolean) . |
boolean |
shouldUpdateLayoutOnAdd(Dockable dockable)
Called when
dockable is added to a DockFrontend , and the frontend already knows the layout which should be used
for dockable . |
public boolean setLayout(DockFrontendInternals frontend, Setting setting, boolean entry) throws java.io.IOException, XException
LayoutChangeStrategy
frontend
by reading and applying setting
.
The DockRegister
is stalled
while this method runs.VetoManager
provided by frontend
to ensure
that all operations are legal.setLayout
in interface LayoutChangeStrategy
frontend
- internal information about a DockFrontend
setting
- the layout to read and applyentry
- true
if setting
contains only little information about
the layout, false
if there is much information abut the layout.true
if the layout has been applied, false
if
the operation was canceled due of any reasonjava.io.IOException
- in case of some stream that cannot be readXException
- in case of some XElement
that cannot be readLayoutChangeStrategy.shouldUpdateLayoutOnAdd(Dockable)
public boolean shouldUpdateLayoutOnAdd(Dockable dockable)
LayoutChangeStrategy
dockable
is added to a DockFrontend
, and the frontend already knows the layout which should be used
for dockable
. If the result is true
, then all children of dockable
are removed, and reloaded to apply the layout
that is stored in the frontend.false
if LayoutChangeStrategy.setLayout(DockFrontendInternals, Setting, boolean)
is currently executed, preventing concurrent
modifications of the dock-tree.shouldUpdateLayoutOnAdd
in interface LayoutChangeStrategy
dockable
- the dockable that is added to a DockFrontend
true
if the layout of dockable
should be updated.protected DefaultLayoutChangeStrategy.SettingAccess createAccess(DockFrontendInternals frontend, Setting setting)
setting
that allows the algorithm of this
LayoutChangeStrategy
to access the setting.frontend
- the caller of this methodsetting
- the setting to hidepublic PredefinedDockSituation createSituation(DockFrontendInternals frontend, boolean entry)
createSituation(DockFrontendInternals, boolean, boolean)
with the
last argument set to false
.createSituation
in interface LayoutChangeStrategy
frontend
- the frontend for which the situation is requiredentry
- true
if the situation is used for a regular setting,
false
if the situation is used as the final setting which will
be loaded the next time the application starts.protected PredefinedDockSituation createSituation(DockFrontendInternals frontend, boolean entry, boolean onSetLayout)
DockSituation
which represents all the knowledge
frontend
currently has.frontend
- the frontend for which the situation is requiredentry
- true
if the situation is used for a regular setting,
false
if the situation is used as the final setting which will
be loaded the next time the application starts.onSetLayout
- whether this method is called by setLayout(DockFrontendInternals, Setting, boolean)
or not. If
true
then the situation is used to apply some layout, otherwise it is used to store or read a layoutPredefinedDockSituation
, subclasses
may override and return other situations.protected boolean shouldPredefine(Dockable dockable)
dockable
should be added as predefined element to the PredefinedDockSituation
that is created by createSituation(DockFrontendInternals, boolean, boolean)
.dockable
- the element which may need to be predefinedtrue
if dockable
is to be predefinedpublic DockFrontendPerspective createPerspective(DockFrontendInternals frontend, boolean entry, FrontendPerspectiveCache cache)
LayoutChangeStrategy
Perspective
that is used to read and write perspectives related to frontend
.createPerspective
in interface LayoutChangeStrategy
frontend
- the frontend for which the situation is requiredentry
- true
if the situation is used for a regular setting,
false
if the situation is used as the final setting which will
be loaded the next time the application starts.cache
- a cache that takes DockElement
s and returns the matching PerspectiveElement
. The cache
also offers methods to convert ids and PerspectiveElement
s directlypublic PropertyTransformer createTransformer(DockFrontendInternals frontend)
LayoutChangeStrategy
DockableProperty
s.createTransformer
in interface LayoutChangeStrategy
frontend
- the frontend for which the converter is requiredprotected void applyLayout(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting, boolean entry) throws java.io.IOException, XException
setting
to the visible elements.
This implementation tries to estimate the location of missing dockables using
listEstimateLocations(DockSituation, DockLayoutComposition)
.frontend
- the caller of this methodsituation
- used to convert the layoutsetting
- the new layoutentry
- whether the layout is a full or regular layoutjava.io.IOException
- if the layout cannot be convertedXException
- if the layout cannot be convertedprotected void applyInvisibleLayout(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting) throws java.io.IOException, XException
setting
to the invisible elements.frontend
- the caller of this methodsituation
- to convert the layoutsetting
- the new layoutjava.io.IOException
- if the layout cannot be convertedXException
- if the layout cannot be convertedprotected java.util.Map<java.lang.String,DockLayoutComposition> listLayouts(DockSituation situation, DockLayoutComposition layout)
Dockable
s. The
default implementation works with any PredefinedDockSituation
.situation
- the situation to use for transforming informationlayout
- the layout to analyzeDockable
-names as key or null
protected java.util.Map<java.lang.String,DockableProperty> listEstimateLocations(DockSituation situation, DockLayoutComposition layout)
Dockable
s. The
default implementation works with any PredefinedDockSituation
.situation
- the situation to use for transforming informationlayout
- the layout to analyzeDockable
-names as key or null
public void estimateLocations(DockFrontendInternals frontend, DockSituation situation, DockLayoutComposition layout)
LayoutChangeStrategy
location
for each element in layout
.estimateLocations
in interface LayoutChangeStrategy
frontend
- the frontend which calls this methodsituation
- the situation to use for transforming informationlayout
- the layout to estimateprotected java.util.Collection<Dockable> approveClosing(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting)
VetoManager
whether some Dockable
s can be hidden. Only Dockable
s that
are returned by DockFrontendInternals.getDockables()
are checked by this method.frontend
- the caller of this methodsituation
- the situation that will convert the layoutsetting
- the new layoutnull
if the operation should be canceledprotected java.util.Collection<Dockable> getClosingDockables(DockFrontendInternals frontend, java.util.Set<Dockable> visible)
Dockable
s that are about to be closed. Subclasses
may override this method, they should at least check all the Dockable
s that are
registered at frontend
. Subclasses may need to override
estimateVisible
as
well to get the correct set of visible
elements.frontend
- the caller of this methodvisible
- the elements that remain visible as told by estimateVisible(DockFrontendInternals, DockSituation, DockLayoutComposition)
.null
, may be emptyprotected java.util.Set<Dockable> estimateVisible(DockFrontendInternals frontend, DockSituation situation, DockLayoutComposition layout)
Dockable
s will
still be visible if layout
is applied to frontend
. The
default implementation assumes that situation
is a PredefinedDockSituation
.frontend
- the caller of this methodsituation
- algorithm used to convert layout
layout
- the layout that will be appliednull
public PlaceholderStrategy getPlaceholderStrategy(DockFrontendInternals frontend)
LayoutChangeStrategy
PlaceholderStrategy
which should be used to filter placeholders by frontend
.getPlaceholderStrategy
in interface LayoutChangeStrategy
frontend
- information about the DockFrontend
that needs the strategynull