Class DesignerViewState
One instance is filled by PanelEditor.captureViewState() and applied by PanelEditor.applyViewState(DesignerViewState). The same instance is written to and read from the workbench IMemento for editor close and open, so the refresh and the close/open paths share one state object, one save and one apply. The state is kept in memory for a refresh and in the per-user workbench memento for close/open; it is never stored in the panel file, which is versioned and shared.
The Structure tree selection and expansion are not part of this object: they survive a refresh untouched (the tree is an SWT control) and the memento already holds them through PropHelper.saveViewer. The tree selection and the panel marks are two different selections, each with its own order, and this object only carries the marks.
The methods that resolve names, parse the scroll data and format it for JavaScript are static and free of SWT so that they can be unit tested.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidaddContainerScroll(String name, int x, int y) Adds a container scroll offset.Gets the container scroll offsets.getMarks()Gets the marks as names relative to the panel, in mark order.intGets the design area horizontal scroll offset.intGets the design area vertical scroll offset.intgetZoom()Gets the zoom level.booleanChecks if any scroll offset is known.booleanGets the flag for the last selection made in the panel rather than in the tree.static DesignerViewStateLoads the state from a memento.static voidLogs the skipped items of an apply operation: one line per skipped item and one summary line.voidreadScrollArray(Object[] a, List<String> skips) Reads the scroll data returned by the design view: an array of the design area offsets followed by triplets of container name, x and y.static <T> List<T> resolve(List<String> names, Class<T> type, Function<String, Object> lookup, String what, List<String> skips) Resolves names to targets one by one.voidSaves the state as a child of the memento.voidSets the marks.voidsetScroll(int x, int y) Sets the design area scroll offsets.voidsetSelectionFromComponents(boolean on) Sets the flag for the last selection made in the panel rather than in the tree.voidsetZoom(int zoom) Sets the zoom level.Formats the scroll offsets as a JavaScript array literal in the same shape asreadScrollArray(Object[],List)reads:[x,y,"name",x,y,...].toString()Gets a short description of the state for logging.voidverifyScrollResult(Object[] r, List<String> skips) Verifies the offsets the design view reports after applying the scroll data: the same shape asreadScrollArray(Object[],List), with -1,-1 for a container that was not found.
Constructor Details
DesignerViewState
public DesignerViewState()Creates an empty state.
Method Details
getMarks
setMarks
isSelectionFromComponents
public boolean isSelectionFromComponents()Gets the flag for the last selection made in the panel rather than in the tree.- Returns:
- The flag.
setSelectionFromComponents
public void setSelectionFromComponents(boolean on) Sets the flag for the last selection made in the panel rather than in the tree.- Parameters:
on- The flag.
getZoom
public int getZoom()Gets the zoom level.- Returns:
- The zoom level in percent, zero when unknown.
setZoom
public void setZoom(int zoom) Sets the zoom level.- Parameters:
zoom- The zoom level in percent, zero for unknown.
getScrollX
public int getScrollX()Gets the design area horizontal scroll offset.- Returns:
- The offset in CSS pixels, -1 when unknown.
getScrollY
public int getScrollY()Gets the design area vertical scroll offset.- Returns:
- The offset in CSS pixels, -1 when unknown.
setScroll
public void setScroll(int x, int y) Sets the design area scroll offsets.- Parameters:
x- The horizontal offset, -1 for unknown.y- The vertical offset, -1 for unknown.
getContainerScrolls
addContainerScroll
Adds a container scroll offset.- Parameters:
name- The container name relative to the panel, empty string for the panel itself.x- The horizontal offset.y- The vertical offset.
hasScroll
public boolean hasScroll()Checks if any scroll offset is known.- Returns:
- true if the design area offsets or any container offset is present.
save
Saves the state as a child of the memento.- Parameters:
memento- The memento.
load
Loads the state from a memento.- Parameters:
memento- The memento, may be null.- Returns:
- The state, or null if the memento is null or holds no state.
resolve
public static <T> List<T> resolve(List<String> names, Class<T> type, Function<String, Object> lookup, String what, List<String> skips) Resolves names to targets one by one. A name whose target is missing, of the wrong type or refused by the lookup is skipped with a reason and the rest continues.- Type Parameters:
T- The target type.- Parameters:
names- The names to resolve, in order.type- The target type.lookup- The lookup: returns the target, or null when not found, or a String with the reason when the target exists but must be skipped.what- What is being resolved, for the skip messages, e.g. "mark".skips- The list receiving one message per skipped name.- Returns:
- The resolved targets in the order of the names, without the skipped ones.
logSkips
Logs the skipped items of an apply operation: one line per skipped item and one summary line. The level is WARNING for now, so the frequency can be seen; it will become INFO if frequent.- Parameters:
originator- The logging class.operation- The operation, e.g. "refresh".skips- The skip messages, empty for none.
readScrollArray
Reads the scroll data returned by the design view: an array of the design area offsets followed by triplets of container name, x and y. Elements that are not numbers or strings where expected are skipped with a reason.- Parameters:
a- The array returned byBrowser.evaluate, may be null.skips- The list receiving one message per skipped element.
verifyScrollResult
Verifies the offsets the design view reports after applying the scroll data: the same shape asreadScrollArray(Object[],List), with -1,-1 for a container that was not found. An offset the page could not take (content smaller than before) or a container that is gone is reported as a skip.- Parameters:
r- The array returned by the apply script, may be null.skips- The list receiving one message per item not applied as captured.
toScrollArrayLiteral
Formats the scroll offsets as a JavaScript array literal in the same shape asreadScrollArray(Object[],List)reads:[x,y,"name",x,y,...].- Returns:
- The literal, e.g.
[10,20,"$components/c1",0,50].
toString