diff options
| author | Stephan Wahlbrink | 2021-09-02 12:14:50 +0000 |
|---|---|---|
| committer | Stephan Wahlbrink | 2021-09-02 18:39:40 +0000 |
| commit | fe1eca17bebaecf704ca2ad5c3a4c20d5b855d96 (patch) | |
| tree | 9988c4f9f9f91ac4daf0df44cebe903e0a275eaa | |
| parent | 175c44a13dd05b691f444dfc3e748159f2b6c5ad (diff) | |
| download | org.eclipse.statet-commons-fe1eca17bebaecf704ca2ad5c3a4c20d5b855d96.tar.gz org.eclipse.statet-commons-fe1eca17bebaecf704ca2ad5c3a4c20d5b855d96.tar.xz org.eclipse.statet-commons-fe1eca17bebaecf704ca2ad5c3a4c20d5b855d96.zip | |
Bug 575763: [WaLTable] Refactor (part 1)
- Extract core module
- Remove deprecated and duplicate code
- Make LayerEvents immutable
- Replace Column/Row events by Dim event implementations
- Add nullable annotations
- Add support for configuration of grid line color via registry
Change-Id: Ic3d8a8db8a0719c28caf988e0892ab40dda71649
458 files changed, 8142 insertions, 9107 deletions
diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/.classpath b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/.classpath index b9bb8eaa..4f143da2 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/.classpath +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/.classpath @@ -12,5 +12,7 @@ </attributes> </classpathentry> <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="srcBase"/> + <classpathentry kind="src" path="srcAdditional"/> <classpathentry kind="output" path="target/classes"/> </classpath> diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/META-INF/MANIFEST.MF b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/META-INF/MANIFEST.MF index 38bdbbb0..2f8c0176 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/META-INF/MANIFEST.MF +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/META-INF/MANIFEST.MF @@ -11,16 +11,28 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.core.runtime;bundle-version="3.16.0", org.eclipse.swt, org.eclipse.jface -Import-Package: org.eclipse.statet.jcommons.lang;version="4.5.0" +Import-Package: org.eclipse.statet.jcommons.collections;version="4.5.0", + org.eclipse.statet.jcommons.lang;version="4.5.0" Export-Package: org.eclipse.statet.ecommons.waltable, org.eclipse.statet.ecommons.waltable.command, org.eclipse.statet.ecommons.waltable.config, org.eclipse.statet.ecommons.waltable.conflation, org.eclipse.statet.ecommons.waltable.coordinate, org.eclipse.statet.ecommons.waltable.copy, - org.eclipse.statet.ecommons.waltable.copy.action, - org.eclipse.statet.ecommons.waltable.data, + org.eclipse.statet.ecommons.waltable.copy.ui.action, + org.eclipse.statet.ecommons.waltable.core, + org.eclipse.statet.ecommons.waltable.core.command, + org.eclipse.statet.ecommons.waltable.core.config, + org.eclipse.statet.ecommons.waltable.core.coordinate, + org.eclipse.statet.ecommons.waltable.core.data, + org.eclipse.statet.ecommons.waltable.core.layer, + org.eclipse.statet.ecommons.waltable.core.layer.events, + org.eclipse.statet.ecommons.waltable.core.layer.top, + org.eclipse.statet.ecommons.waltable.core.style, + org.eclipse.statet.ecommons.waltable.core.swt, + org.eclipse.statet.ecommons.waltable.core.swt.painters, org.eclipse.statet.ecommons.waltable.data.convert, + org.eclipse.statet.ecommons.waltable.data.core, org.eclipse.statet.ecommons.waltable.data.validate, org.eclipse.statet.ecommons.waltable.edit, org.eclipse.statet.ecommons.waltable.edit.action, @@ -28,47 +40,47 @@ Export-Package: org.eclipse.statet.ecommons.waltable, org.eclipse.statet.ecommons.waltable.edit.editor, org.eclipse.statet.ecommons.waltable.edit.gui, org.eclipse.statet.ecommons.waltable.export, - org.eclipse.statet.ecommons.waltable.export.action, org.eclipse.statet.ecommons.waltable.export.config, org.eclipse.statet.ecommons.waltable.export.excel, + org.eclipse.statet.ecommons.waltable.export.ui.action, org.eclipse.statet.ecommons.waltable.freeze, - org.eclipse.statet.ecommons.waltable.freeze.action, - org.eclipse.statet.ecommons.waltable.freeze.config, + org.eclipse.statet.ecommons.waltable.freeze.core, + org.eclipse.statet.ecommons.waltable.freeze.swt, + org.eclipse.statet.ecommons.waltable.freeze.ui.action, org.eclipse.statet.ecommons.waltable.grid, - org.eclipse.statet.ecommons.waltable.grid.cell, - org.eclipse.statet.ecommons.waltable.grid.data, - org.eclipse.statet.ecommons.waltable.grid.labeled, - org.eclipse.statet.ecommons.waltable.grid.layer, - org.eclipse.statet.ecommons.waltable.grid.layer.config, - org.eclipse.statet.ecommons.waltable.layer, + org.eclipse.statet.ecommons.waltable.grid.config, + org.eclipse.statet.ecommons.waltable.grid.core, + org.eclipse.statet.ecommons.waltable.grid.core.data, + org.eclipse.statet.ecommons.waltable.grid.core.labeled, + org.eclipse.statet.ecommons.waltable.grid.core.layers, + org.eclipse.statet.ecommons.waltable.grid.swt, org.eclipse.statet.ecommons.waltable.layer.cell, org.eclipse.statet.ecommons.waltable.layer.config, - org.eclipse.statet.ecommons.waltable.layer.event, - org.eclipse.statet.ecommons.waltable.painter, org.eclipse.statet.ecommons.waltable.painter.cell, org.eclipse.statet.ecommons.waltable.painter.cell.decorator, - org.eclipse.statet.ecommons.waltable.painter.layer, org.eclipse.statet.ecommons.waltable.persistence, org.eclipse.statet.ecommons.waltable.persistence.gui, org.eclipse.statet.ecommons.waltable.print, - org.eclipse.statet.ecommons.waltable.print.action, org.eclipse.statet.ecommons.waltable.print.config, + org.eclipse.statet.ecommons.waltable.print.ui.action, + org.eclipse.statet.ecommons.waltable.refresh.core, org.eclipse.statet.ecommons.waltable.resize, - org.eclipse.statet.ecommons.waltable.resize.action, - org.eclipse.statet.ecommons.waltable.resize.config, - org.eclipse.statet.ecommons.waltable.selection, - org.eclipse.statet.ecommons.waltable.selection.action, + org.eclipse.statet.ecommons.waltable.resize.core, + org.eclipse.statet.ecommons.waltable.resize.ui.action, org.eclipse.statet.ecommons.waltable.selection.config, + org.eclipse.statet.ecommons.waltable.selection.core, + org.eclipse.statet.ecommons.waltable.selection.swt, + org.eclipse.statet.ecommons.waltable.selection.ui.action, org.eclipse.statet.ecommons.waltable.sort, - org.eclipse.statet.ecommons.waltable.sort.action, org.eclipse.statet.ecommons.waltable.sort.config, - org.eclipse.statet.ecommons.waltable.sort.painter, + org.eclipse.statet.ecommons.waltable.sort.core, + org.eclipse.statet.ecommons.waltable.sort.swt, + org.eclipse.statet.ecommons.waltable.sort.ui.action, org.eclipse.statet.ecommons.waltable.style, org.eclipse.statet.ecommons.waltable.style.editor, - org.eclipse.statet.ecommons.waltable.swt, org.eclipse.statet.ecommons.waltable.tickupdate, - org.eclipse.statet.ecommons.waltable.tickupdate.action, org.eclipse.statet.ecommons.waltable.tickupdate.config, + org.eclipse.statet.ecommons.waltable.tickupdate.ui.action, org.eclipse.statet.ecommons.waltable.tooltip, org.eclipse.statet.ecommons.waltable.ui, org.eclipse.statet.ecommons.waltable.ui.action, @@ -76,8 +88,10 @@ Export-Package: org.eclipse.statet.ecommons.waltable, org.eclipse.statet.ecommons.waltable.ui.matcher, org.eclipse.statet.ecommons.waltable.ui.menu, org.eclipse.statet.ecommons.waltable.ui.mode, + org.eclipse.statet.ecommons.waltable.ui.swt.widgets, org.eclipse.statet.ecommons.waltable.ui.util, org.eclipse.statet.ecommons.waltable.util, - org.eclipse.statet.ecommons.waltable.viewport, - org.eclipse.statet.ecommons.waltable.viewport.action, - org.eclipse.statet.ecommons.waltable.widget + org.eclipse.statet.ecommons.waltable.util.data, + org.eclipse.statet.ecommons.waltable.viewport.core, + org.eclipse.statet.ecommons.waltable.viewport.swt, + org.eclipse.statet.ecommons.waltable.viewport.ui.action diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/build.properties b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/build.properties index a891cad1..8066e2cf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/build.properties +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/build.properties @@ -1,4 +1,6 @@ -source..= src/ +source..= src/,\ + srcBase/,\ + srcAdditional/ output..= target/classes/ bin.includes= META-INF/,\ .,\ diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTable.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTable.java index da2a79b6..1d9e7ccb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTable.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTable.java @@ -13,15 +13,14 @@ package org.eclipse.statet.ecommons.waltable; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.Properties; +import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -45,59 +44,61 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.statet.jcommons.collections.CopyOnWriteIdentityListSet; +import org.eclipse.statet.jcommons.collections.ImList; + import org.eclipse.statet.ecommons.waltable.command.DisposeResourcesCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.command.StructuralRefreshCommand; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.DefaultNatTableStyleConfiguration; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IConfiguration; import org.eclipse.statet.ecommons.waltable.conflation.EventConflaterChain; import org.eclipse.statet.ecommons.waltable.conflation.IEventConflater; import org.eclipse.statet.ecommons.waltable.conflation.VisualChangeEventConflater; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.ClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerListener; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.events.VisualChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.top.OverlayPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.top.TopLayer; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.TableLayerPainter; import org.eclipse.statet.ecommons.waltable.edit.ActiveCellEditorRegistry; -import org.eclipse.statet.ecommons.waltable.grid.ClientAreaResizeCommand; -import org.eclipse.statet.ecommons.waltable.grid.InitializeGridCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerListener; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.IVisualChangeEvent; -import org.eclipse.statet.ecommons.waltable.painter.IOverlayPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.NatLayerPainter; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.selection.CellSelectionEvent; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.grid.core.ClientAreaResizeCommand; +import org.eclipse.statet.ecommons.waltable.refresh.core.StructuralRefreshCommand; +import org.eclipse.statet.ecommons.waltable.selection.core.CellSelectionEvent; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.mode.ConfigurableModeEventHandler; import org.eclipse.statet.ecommons.waltable.ui.mode.Mode; import org.eclipse.statet.ecommons.waltable.ui.mode.ModeSupport; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; -import org.eclipse.statet.ecommons.waltable.viewport.RecalculateScrollBarsCommand; -import org.eclipse.statet.internal.ecommons.waltable.LayerListenerList; +import org.eclipse.statet.ecommons.waltable.viewport.core.RecalculateScrollBarsCommand; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; -public class NatTable extends Canvas implements ILayer, PaintListener, ILayerListener, IPersistable { +public class NatTable extends Canvas implements TopLayer, PaintListener, LayerListener, Persistable { public static final int DEFAULT_STYLE_OPTIONS= SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL; - private final NatTableDim hDim; - private final NatTableDim vDim; + private final NatTableLayerDim hDim; + private final NatTableLayerDim vDim; - private IClientAreaProvider clientAreaProvider= new IClientAreaProvider() { + private ClientAreaProvider clientAreaProvider= new ClientAreaProvider() { @Override public LRectangle getClientArea() { if (!isDisposed()) { - return SWTUtil.toNatTable(NatTable.this.getClientArea()); + return SwtUtils.toNatTable(NatTable.this.getClientArea()); } else { return new LRectangle(0, 0, 0, 0); } @@ -112,40 +113,40 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis private final EventConflaterChain conflaterChain= new EventConflaterChain(); - private final List<IOverlayPainter> overlayPainters= new ArrayList<>(); + private final CopyOnWriteIdentityListSet<OverlayPainter> overlayPainters= new CopyOnWriteIdentityListSet<>(); - private final List<IPersistable> persistables= new LinkedList<>(); + private final List<Persistable> persistables= new LinkedList<>(); - private ILayer underlyingLayer; + private Layer underlyingLayer; - private IConfigRegistry configRegistry; + private ConfigRegistry configRegistry; protected final Collection<IConfiguration> configurations= new LinkedList<>(); protected String id= GUIHelper.getSequenceNumber(); - private ILayerPainter layerPainter= new NatLayerPainter(this); + private LayerPainter layerPainter= new TableLayerPainter(this); private final boolean autoconfigure; - public NatTable(final Composite parent, final ILayer layer) { + public NatTable(final Composite parent, final Layer layer) { this(parent, DEFAULT_STYLE_OPTIONS, layer); } - public NatTable(final Composite parent, final ILayer layer, final boolean autoconfigure) { + public NatTable(final Composite parent, final Layer layer, final boolean autoconfigure) { this(parent, DEFAULT_STYLE_OPTIONS, layer, autoconfigure); } - public NatTable(final Composite parent, final int style, final ILayer layer) { + public NatTable(final Composite parent, final int style, final Layer layer) { this(parent, style, layer, true); } - public NatTable(final Composite parent, final int style, final ILayer layer, final boolean autoconfigure) { + public NatTable(final Composite parent, final int style, final Layer layer, final boolean autoconfigure) { super(parent, style); - this.hDim= new NatTableDim(this, layer.getDim(HORIZONTAL)); - this.vDim= new NatTableDim(this, layer.getDim(VERTICAL)); + this.hDim= new NatTableLayerDim(this, layer.getDim(HORIZONTAL)); + this.vDim= new NatTableLayerDim(this, layer.getDim(VERTICAL)); // Disable scroll bars by default; if a Viewport is available, it will enable the scroll bars disableScrollBar(getHorizontalBar()); @@ -179,7 +180,7 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis @Override - public NatTableDim getDim(final Orientation orientation) { + public NatTableLayerDim getDim(final Orientation orientation) { if (orientation == null) { throw new NullPointerException("orientation"); //$NON-NLS-1$ } @@ -201,11 +202,11 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis } } - public ILayer getLayer() { + public Layer getUnderlyingLayer() { return this.underlyingLayer; } - private void internalSetLayer(final ILayer layer) { + private void internalSetLayer(final Layer layer) { if (layer != null) { this.underlyingLayer= layer; this.underlyingLayer.setClientAreaProvider(getClientAreaProvider()); @@ -233,17 +234,17 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis } /** - * @return {@link IConfigRegistry} used to hold the configuration bindings + * @return {@link ConfigRegistry} used to hold the configuration bindings * by Layer, DisplayMode and Config labels. */ - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getStyleRegistry() { if (this.configRegistry == null) { - this.configRegistry= new ConfigRegistry(); + this.configRegistry= new BasicConfigRegistry(); } return this.configRegistry; } - public void setConfigRegistry(final IConfigRegistry configRegistry) { + public void setConfigRegistry(final ConfigRegistry configRegistry) { if (this.autoconfigure) { throw new IllegalStateException("May only set config registry post construction if autoconfigure is turned off"); //$NON-NLS-1$ } @@ -313,15 +314,15 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis // Painting /////////////////////////////////////////////////////////////// - public List<IOverlayPainter> getOverlayPainters() { - return this.overlayPainters; + public ImList<OverlayPainter> getOverlayPainters() { + return this.overlayPainters.toList(); } - public void addOverlayPainter(final IOverlayPainter overlayPainter) { + public void addOverlayPainter(final OverlayPainter overlayPainter) { this.overlayPainters.add(overlayPainter); } - public void removeOverlayPainter(final IOverlayPainter overlayPainter) { + public void removeOverlayPainter(final OverlayPainter overlayPainter) { this.overlayPainters.remove(overlayPainter); } @@ -334,16 +335,16 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis final Rectangle eventRectangle= new Rectangle(event.x, event.y, event.width, event.height); if (!eventRectangle.isEmpty()) { - getLayerPainter().paintLayer(this, event.gc, 0, 0, eventRectangle, getConfigRegistry()); + getLayerPainter().paintLayer(this, event.gc, 0, 0, eventRectangle, getStyleRegistry()); } } @Override - public ILayerPainter getLayerPainter() { + public LayerPainter getLayerPainter() { return this.layerPainter; } - public void setLayerPainter(final ILayerPainter layerPainter) { + public void setLayerPainter(final LayerPainter layerPainter) { this.layerPainter= layerPainter; } @@ -367,12 +368,12 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis this.vDim.repaintPosition(rowPosition); } - protected void repaint(final Orientation orientation, final int start, final int size) { + protected void repaint(final Orientation orientation, final long start, final long size) { if (orientation == HORIZONTAL) { - redraw(start, 0, size, safe(getHeight()), true); + redraw(SwtUtils.toSWT(start), 0, SwtUtils.toSWT(size), safe(getHeight()), true); } else { - redraw(0, start, safe(getWidth()), size, true); + redraw(0, SwtUtils.toSWT(start), safe(getWidth()), SwtUtils.toSWT(size), true); } } @@ -421,29 +422,25 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis } if (this.underlyingLayer != null) { - this.underlyingLayer.configure((ConfigRegistry) getConfigRegistry(), getUiBindingRegistry()); + this.underlyingLayer.configure(getStyleRegistry(), getUiBindingRegistry()); } for (final IConfiguration configuration : this.configurations) { configuration.configureLayer(this); - configuration.configureRegistry(getConfigRegistry()); + configuration.configureRegistry(getStyleRegistry()); configuration.configureUiBindings(getUiBindingRegistry()); } - - // Once everything is initialized and properly configured we will - // now formally initialize the grid - doCommand(new InitializeGridCommand(this)); } // Events ///////////////////////////////////////////////////////////////// @Override - public void handleLayerEvent(final ILayerEvent event) { - for (final ILayerListener layerListener : this.listeners.getListeners()) { + public void handleLayerEvent(final LayerEvent event) { + for (final LayerListener layerListener : this.listeners) { layerListener.handleLayerEvent(event); } - if (event instanceof IVisualChangeEvent) { + if (event instanceof VisualChangeEvent) { this.conflaterChain.addEvent(event); } @@ -466,12 +463,12 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis /** * Save the state of the table to the properties object. - * {@link ILayer#saveState(String, Properties)} is invoked on all the underlying layers. + * {@link Layer#saveState(String, Map)} is invoked on all the underlying layers. * This properties object will be populated with the settings of all underlying layers - * and any {@link IPersistable} registered with those layers. + * and any {@link Persistable} registered with those layers. */ @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { BusyIndicator.showWhile(null, new Runnable() { @Override @@ -483,10 +480,10 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis /** * Restore the state of the underlying layers from the values in the properties object. - * @see #saveState(String, Properties) + * @see #saveState(String, Map) */ @Override - public void loadState(final String prefix, final Properties properties) { + public void loadState(final String prefix, final Map<String, String> properties) { BusyIndicator.showWhile(null, new Runnable() { @Override @@ -497,51 +494,51 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis } /** - * @see ILayer#registerPersistable(IPersistable) + * @see Layer#registerPersistable(Persistable) */ @Override - public void registerPersistable(final IPersistable persistable) { + public void registerPersistable(final Persistable persistable) { this.persistables.add(persistable); } @Override - public void unregisterPersistable(final IPersistable persistable) { + public void unregisterPersistable(final Persistable persistable) { this.persistables.remove(persistable); } // Command @Override - public boolean doCommand(final ILayerCommand command) { + public boolean doCommand(final LayerCommand command) { return this.underlyingLayer.doCommand(command); } @Override - public void registerCommandHandler(final ILayerCommandHandler<?> commandHandler) { + public void registerCommandHandler(final LayerCommandHandler<?> commandHandler) { this.underlyingLayer.registerCommandHandler(commandHandler); } @Override - public void unregisterCommandHandler(final Class<? extends ILayerCommand> commandClass) { + public void unregisterCommandHandler(final Class<? extends LayerCommand> commandClass) { this.underlyingLayer.unregisterCommandHandler(commandClass); } // Events - private final LayerListenerList listeners= new LayerListenerList(); + private final CopyOnWriteIdentityListSet<LayerListener> listeners= new CopyOnWriteIdentityListSet<>(); @Override - public void fireLayerEvent(final ILayerEvent event) { + public void fireLayerEvent(final LayerEvent event) { this.underlyingLayer.fireLayerEvent(event); } @Override - public void addLayerListener(final ILayerListener listener) { + public void addLayerListener(final LayerListener listener) { this.listeners.add(listener); } @Override - public void removeLayerListener(final ILayerListener listener) { + public void removeLayerListener(final LayerListener listener) { this.listeners.remove(listener); } @@ -595,7 +592,7 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis // Cell features @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { return this.underlyingLayer.getCellByPosition(columnPosition, rowPosition); } @@ -607,17 +604,17 @@ public class NatTable extends Canvas implements ILayer, PaintListener, ILayerLis } @Override - public ILayer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { + public Layer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { return this.underlyingLayer; } @Override - public IClientAreaProvider getClientAreaProvider() { + public ClientAreaProvider getClientAreaProvider() { return this.clientAreaProvider; } @Override - public void setClientAreaProvider(final IClientAreaProvider clientAreaProvider) { + public void setClientAreaProvider(final ClientAreaProvider clientAreaProvider) { this.clientAreaProvider= clientAreaProvider; this.underlyingLayer.setClientAreaProvider(clientAreaProvider); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTableDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTableLayerDim.java index f368eeec..a821c3fd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTableDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/NatTableLayerDim.java @@ -14,17 +14,19 @@ package org.eclipse.statet.ecommons.waltable; -import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.check; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ForwardLayerDim; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.top.TopLayerDim; -public class NatTableDim extends ForwardLayerDim<NatTable> { +@NonNullByDefault +public class NatTableLayerDim extends ForwardLayerDim<NatTable> implements TopLayerDim { - public NatTableDim(final NatTable layer, final ILayerDim underlyingDim) { + public NatTableLayerDim(final NatTable layer, final LayerDim underlyingDim) { super(layer, underlyingDim); } @@ -34,14 +36,16 @@ public class NatTableDim extends ForwardLayerDim<NatTable> { return this.layer; } + @Override public void repaintPosition(final long position) { if (position == POSITION_NA) { return; } final long start= getPositionStart(position); - this.layer.repaint(this.orientation, check(start), getPositionSize(position)); + this.layer.repaint(this.orientation, start, getPositionSize(position)); } + @Override public void repaintPositions(final LRange positions) { if (positions.size() == 0) { return; @@ -49,7 +53,7 @@ public class NatTableDim extends ForwardLayerDim<NatTable> { final long start= getPositionStart(positions.start); final long end= ((positions.size() == 1) ? start : getPositionStart(positions.end - 1)) + getPositionSize(positions.end - 1); - this.layer.repaint(this.orientation, check(start), check(end - start)); + this.layer.repaint(this.orientation, start, end - start); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractPositionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractPositionCommand.java index fc0c1b31..08aa78dc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractPositionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractPositionCommand.java @@ -14,16 +14,17 @@ package org.eclipse.statet.ecommons.waltable.command; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public abstract class AbstractPositionCommand implements ILayerCommand { +public abstract class AbstractPositionCommand implements LayerCommand { private PositionCoordinate positionCoordinate; - protected AbstractPositionCommand(final ILayer layer, final long columnPosition, final long rowPosition) { + protected AbstractPositionCommand(final Layer layer, final long columnPosition, final long rowPosition) { this.positionCoordinate= new PositionCoordinate(layer, columnPosition, rowPosition); } @@ -41,7 +42,7 @@ public abstract class AbstractPositionCommand implements ILayerCommand { } @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { final PositionCoordinate targetPositionCoordinate= LayerCommandUtil.convertPositionToTargetContext(this.positionCoordinate, targetLayer); if (targetPositionCoordinate != null) { this.positionCoordinate= targetPositionCoordinate; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/DisposeResourcesCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/DisposeResourcesCommand.java index a9f48f15..dd16cb49 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/DisposeResourcesCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/DisposeResourcesCommand.java @@ -14,6 +14,7 @@ package org.eclipse.statet.ecommons.waltable.command; import org.eclipse.statet.ecommons.waltable.NatTable; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/LayerCommandUtil.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/LayerCommandUtil.java index de8b4912..419d580f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/LayerCommandUtil.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/LayerCommandUtil.java @@ -13,21 +13,21 @@ package org.eclipse.statet.ecommons.waltable.command; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.statet.ecommons.waltable.coordinate.ColumnPositionCoordinate; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; import org.eclipse.statet.ecommons.waltable.coordinate.RowPositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; public class LayerCommandUtil { - public static PositionCoordinate convertPositionToTargetContext(final PositionCoordinate positionCoordinate, final ILayer targetLayer) { - final ILayer layer= positionCoordinate.getLayer(); + public static PositionCoordinate convertPositionToTargetContext(final PositionCoordinate positionCoordinate, final Layer targetLayer) { + final Layer layer= positionCoordinate.getLayer(); if (layer == targetLayer) { return positionCoordinate; @@ -45,7 +45,7 @@ public class LayerCommandUtil { return null; } - final ILayer underlyingLayer= layer.getUnderlyingLayerByPosition(columnPosition, rowPosition); + final Layer underlyingLayer= layer.getUnderlyingLayerByPosition(columnPosition, rowPosition); if (underlyingLayer == null) { return null; } @@ -53,28 +53,28 @@ public class LayerCommandUtil { return convertPositionToTargetContext(new PositionCoordinate(underlyingLayer, underlyingColumnPosition, underlyingRowPosition), targetLayer); } - public static ColumnPositionCoordinate convertColumnPositionToTargetContext(final ColumnPositionCoordinate columnPositionCoordinate, final ILayer targetLayer) { + public static ColumnPositionCoordinate convertColumnPositionToTargetContext(final ColumnPositionCoordinate columnPositionCoordinate, final Layer targetLayer) { if (columnPositionCoordinate != null) { - final ILayer layer= columnPositionCoordinate.getLayer(); + final Layer layer= columnPositionCoordinate.getLayer(); - final long targetPosition= LayerUtil.convertPosition(layer.getDim(HORIZONTAL), + final long targetPosition= LayerUtils.convertPosition(layer.getDim(HORIZONTAL), columnPositionCoordinate.columnPosition, columnPositionCoordinate.columnPosition, targetLayer.getDim(HORIZONTAL) ); - return (targetPosition != ILayerDim.POSITION_NA) ? + return (targetPosition != LayerDim.POSITION_NA) ? new ColumnPositionCoordinate(targetLayer, targetPosition) : null; } return null; } - public static RowPositionCoordinate convertRowPositionToTargetContext(final RowPositionCoordinate rowPositionCoordinate, final ILayer targetLayer) { + public static RowPositionCoordinate convertRowPositionToTargetContext(final RowPositionCoordinate rowPositionCoordinate, final Layer targetLayer) { if (rowPositionCoordinate != null) { - final ILayer layer= rowPositionCoordinate.getLayer(); + final Layer layer= rowPositionCoordinate.getLayer(); - final long targetPosition= LayerUtil.convertPosition(layer.getDim(VERTICAL), + final long targetPosition= LayerUtils.convertPosition(layer.getDim(VERTICAL), rowPositionCoordinate.rowPosition, rowPositionCoordinate.rowPosition, targetLayer.getDim(VERTICAL) ); - return (targetPosition != ILayerDim.POSITION_NA) ? + return (targetPosition != LayerDim.POSITION_NA) ? new RowPositionCoordinate(targetLayer, targetPosition) : null; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractLayerConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractLayerConfiguration.java index 5f4314d5..9835fb92 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractLayerConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractLayerConfiguration.java @@ -13,7 +13,8 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; @@ -21,18 +22,18 @@ import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; * Casts the layer to be to the type parameter for convenience. * @param <L> type of the layer being configured */ -public abstract class AbstractLayerConfiguration<L extends ILayer> implements IConfiguration { +public abstract class AbstractLayerConfiguration<L extends Layer> implements IConfiguration { @Override @SuppressWarnings("unchecked") - public void configureLayer(final ILayer layer) { + public void configureLayer(final Layer layer) { configureTypedLayer((L) layer); } public abstract void configureTypedLayer(L layer); @Override - public void configureRegistry(final IConfigRegistry configRegistry) {} + public void configureRegistry(final ConfigRegistry configRegistry) {} @Override public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) {} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractRegistryConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractRegistryConfiguration.java index bde187c6..e4443565 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractRegistryConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractRegistryConfiguration.java @@ -13,14 +13,14 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; public abstract class AbstractRegistryConfiguration implements IConfiguration { @Override - public void configureLayer(final ILayer layer) {} + public void configureLayer(final Layer layer) {} @Override public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) {} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractUiBindingConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractUiBindingConfiguration.java index 7495ad6c..8dc51f52 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractUiBindingConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AbstractUiBindingConfiguration.java @@ -13,15 +13,16 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public abstract class AbstractUiBindingConfiguration implements IConfiguration { @Override - public void configureLayer(final ILayer layer) {} + public void configureLayer(final Layer layer) {} @Override - public void configureRegistry(final IConfigRegistry configRegistry) {} + public void configureRegistry(final ConfigRegistry configRegistry) {} } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AggregateConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AggregateConfiguration.java index ef771bb8..c5aad69a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AggregateConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/AggregateConfiguration.java @@ -16,7 +16,8 @@ package org.eclipse.statet.ecommons.waltable.config; import java.util.Collection; import java.util.LinkedList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; @@ -32,14 +33,14 @@ public class AggregateConfiguration implements IConfiguration { } @Override - public void configureLayer(final ILayer layer) { + public void configureLayer(final Layer layer) { for (final IConfiguration configuration : this.configurations) { configuration.configureLayer(layer); } } @Override - public void configureRegistry(final IConfigRegistry configRegistry) { + public void configureRegistry(final ConfigRegistry configRegistry) { for (final IConfiguration configuration : this.configurations) { configuration.configureRegistry(configRegistry); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/CellConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/CellConfigAttributes.java index 6b3d8f75..1517c15b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/CellConfigAttributes.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/CellConfigAttributes.java @@ -13,17 +13,17 @@ package org.eclipse.statet.ecommons.waltable.config; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.style.IStyle; public interface CellConfigAttributes { - ConfigAttribute<ICellPainter> CELL_PAINTER= new ConfigAttribute<>(); + ConfigAttribute<LayerCellPainter> CELL_PAINTER= new ConfigAttribute<>(); - ConfigAttribute<IStyle> CELL_STYLE= new ConfigAttribute<>(); + ConfigAttribute<Style> CELL_STYLE= new ConfigAttribute<>(); ConfigAttribute<IDisplayConverter> DISPLAY_CONVERTER= new ConfigAttribute<>(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ConfigRegistry.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ConfigRegistry.java deleted file mode 100644 index 9cb5ad79..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ConfigRegistry.java +++ /dev/null @@ -1,149 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.config; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.style.DefaultDisplayModeOrdering; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IDisplayModeLookupStrategy; - - -public class ConfigRegistry implements IConfigRegistry { - - - // Map<configAttributeType, Map<displayMode, Map<configLabel, value>>> - final Map<ConfigAttribute<?>, Map<DisplayMode, Map<String, ?>>> configRegistry= new HashMap<>(); - - private IDisplayModeLookupStrategy displayModeLookupStrategy= new DefaultDisplayModeOrdering(); - - - public ConfigRegistry() { - } - - - @Override - public IDisplayModeLookupStrategy getDisplayModeOrdering() { - return this.displayModeLookupStrategy; - } - - public void setDisplayModeOrdering(final IDisplayModeLookupStrategy displayModeLookupStrategy) { - this.displayModeLookupStrategy= displayModeLookupStrategy; - } - - - @Override - public <T> T getConfigAttribute(final ConfigAttribute<T> configAttribute, - final DisplayMode targetDisplayMode, final String...configLabels) { - return getConfigAttribute(configAttribute, targetDisplayMode, Arrays.asList(configLabels)); - } - - @Override - @SuppressWarnings("unchecked") - public <T> T getConfigAttribute(final ConfigAttribute<T> configAttribute, - final DisplayMode targetDisplayMode, final List<String> configLabels) { - T attributeValue= null; - - final Map<DisplayMode, Map<String, ?>> displayModeConfigAttributeMap= this.configRegistry.get(configAttribute); - if (displayModeConfigAttributeMap != null) { - for (final DisplayMode displayMode : this.displayModeLookupStrategy.getDisplayModeOrdering(targetDisplayMode)) { - final Map<String, T> configAttributeMap= (Map<String, T>) displayModeConfigAttributeMap.get(displayMode); - if (configAttributeMap != null) { - for (final String configLabel : configLabels) { - attributeValue= configAttributeMap.get(configLabel); - if (attributeValue != null) { - return attributeValue; - } - } - - // default config type - attributeValue= configAttributeMap.get(null); - if (attributeValue != null) { - return attributeValue; - } - } - } - } - - return attributeValue; - } - - @Override - @SuppressWarnings("unchecked") - public <T> T getSpecificConfigAttribute(final ConfigAttribute<T> configAttribute, - final DisplayMode displayMode, final String configLabel) { - T attributeValue= null; - - final Map<DisplayMode, Map<String, ?>> displayModeConfigAttributeMap= this.configRegistry.get(configAttribute); - if (displayModeConfigAttributeMap != null) { - final Map<String, T> configAttributeMap= (Map<String, T>) displayModeConfigAttributeMap.get(displayMode); - if (configAttributeMap != null) { - attributeValue= configAttributeMap.get(configLabel); - if (attributeValue != null) { - return attributeValue; - } - } - } - - return attributeValue; - } - - @Override - public <T> void registerConfigAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue) { - registerConfigAttribute(configAttribute, attributeValue, DisplayMode.NORMAL); - } - - @Override - public <T> void registerConfigAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue, - final DisplayMode displayMode) { - registerConfigAttribute(configAttribute, attributeValue, displayMode, null); - } - - @Override - @SuppressWarnings("unchecked") - public <T> void registerConfigAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue, - final DisplayMode displayMode, final String configLabel) { - Map<DisplayMode, Map<String, ?>> displayModeConfigAttributeMap= this.configRegistry.get(configAttribute); - if (displayModeConfigAttributeMap == null) { - displayModeConfigAttributeMap= new HashMap<>(); - this.configRegistry.put(configAttribute, displayModeConfigAttributeMap); - } - - Map<String, T> configAttributeMap= (Map<String, T>) displayModeConfigAttributeMap.get(displayMode); - if (configAttributeMap == null) { - configAttributeMap= new HashMap<>(); - displayModeConfigAttributeMap.put(displayMode, configAttributeMap); - } - - configAttributeMap.put(configLabel, attributeValue); - } - - @Override - @SuppressWarnings("unchecked") - public <T> void unregisterConfigAttribute(final ConfigAttribute<T> configAttributeType, - final DisplayMode displayMode, final String configLabel) { - final Map<DisplayMode, Map<String, ?>> displayModeConfigAttributeMap= this.configRegistry.get(configAttributeType); - if (displayModeConfigAttributeMap != null) { - final Map<String, T> configAttributeMap= (Map<String, T>) displayModeConfigAttributeMap.get(displayMode); - if (configAttributeMap != null) { - configAttributeMap.remove(configLabel); - } - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ContextualEditableRule.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ContextualEditableRule.java index addc20db..36111a72 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ContextualEditableRule.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/ContextualEditableRule.java @@ -13,7 +13,8 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public abstract class ContextualEditableRule implements IEditableRule { @@ -24,6 +25,6 @@ public abstract class ContextualEditableRule implements IEditableRule { } @Override - public abstract boolean isEditable(ILayerCell cell, IConfigRegistry configRegistry); + public abstract boolean isEditable(LayerCell cell, ConfigRegistry configRegistry); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultEditableRule.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultEditableRule.java index f97e6b59..d3574196 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultEditableRule.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultEditableRule.java @@ -13,7 +13,8 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public class DefaultEditableRule implements IEditableRule { @@ -25,7 +26,7 @@ public class DefaultEditableRule implements IEditableRule { } @Override - public boolean isEditable(final ILayerCell cell, final IConfigRegistry configRegistry) { + public boolean isEditable(final LayerCell cell, final ConfigRegistry configRegistry) { return this.defaultEditable; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultNatTableStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultNatTableStyleConfiguration.java index d49c627e..9bb3c904 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultNatTableStyleConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/DefaultNatTableStyleConfiguration.java @@ -16,15 +16,16 @@ package org.eclipse.statet.ecommons.waltable.config; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.data.convert.DefaultDisplayConverter; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.TextPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.LineBorderDecorator; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -33,30 +34,30 @@ public class DefaultNatTableStyleConfiguration extends AbstractRegistryConfigura public Color bgColor= GUIHelper.COLOR_WHITE; public Color fgColor= GUIHelper.COLOR_BLACK; public Color gradientBgColor= GUIHelper.COLOR_WHITE; - public Color gradientFgColor= GUIHelper.getColor(136, 212, 215); + public Color gradientFgColor= new Color(136, 212, 215); public Font font= GUIHelper.DEFAULT_FONT; public HorizontalAlignment hAlign= HorizontalAlignment.CENTER; public VerticalAlignment vAlign= VerticalAlignment.MIDDLE; public BorderStyle borderStyle= null; - public ICellPainter cellPainter= new LineBorderDecorator(new TextPainter()); + public LayerCellPainter layerCellPainter= new LineBorderDecorator(new TextPainter()); @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter); - - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.bgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.fgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FONT, this.font); - cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, this.hAlign); - cellStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, this.vAlign); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.borderStyle); + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter); + + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.bgColor); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.fgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); + cellStyle.setAttributeValue(CellStyling.FONT, this.font); + cellStyle.setAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT, this.hAlign); + cellStyle.setAttributeValue(CellStyling.VERTICAL_ALIGNMENT, this.vAlign); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.borderStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter()); + configRegistry.registerAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter()); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfiguration.java index 2a3af1cf..de7f50bb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfiguration.java @@ -14,10 +14,11 @@ package org.eclipse.statet.ecommons.waltable.config; import org.eclipse.statet.ecommons.waltable.NatTable; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; -import org.eclipse.statet.ecommons.waltable.layer.AbstractLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; @@ -26,21 +27,21 @@ import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; * These will be processed when {@link NatTable#configure()} is invoked. * * Default configurations are added to most layers {@link AbstractLayer#addConfiguration(IConfiguration)}. - * You can turn off default configuration for an {@link ILayer} by setting auto configure to false + * You can turn off default configuration for an {@link Layer} by setting auto configure to false * in the constructor. */ public interface IConfiguration { - public void configureLayer(ILayer layer); + public void configureLayer(Layer layer); /** - * Configure NatTable's {@link IConfigRegistry} upon receiving this call back. - * A mechanism to plug-in custom {@link ICellPainter}, {@link IDataValidator} etc. + * Configure NatTable's {@link ConfigRegistry} upon receiving this call back. + * A mechanism to plug-in custom {@link LayerCellPainter}, {@link IDataValidator} etc. */ - public void configureRegistry(IConfigRegistry configRegistry); + public void configureRegistry(ConfigRegistry configRegistry); /** - * Configure NatTable's {@link IConfigRegistry} upon receiving this call back + * Configure NatTable's {@link ConfigRegistry} upon receiving this call back * A mechanism to customize key/mouse bindings. */ public void configureUiBindings(UiBindingRegistry uiBindingRegistry); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IEditableRule.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IEditableRule.java index 09b7fee4..9e73bcb0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IEditableRule.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IEditableRule.java @@ -13,7 +13,8 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public interface IEditableRule { @@ -22,7 +23,7 @@ public interface IEditableRule { IEditableRule ALWAYS_EDITABLE= new IEditableRule() { @Override - public boolean isEditable(final ILayerCell cell, final IConfigRegistry configRegistry) { + public boolean isEditable(final LayerCell cell, final ConfigRegistry configRegistry) { return true; } @@ -31,14 +32,14 @@ public interface IEditableRule { IEditableRule NEVER_EDITABLE= new IEditableRule() { @Override - public boolean isEditable(final ILayerCell cell, final IConfigRegistry configRegistry) { + public boolean isEditable(final LayerCell cell, final ConfigRegistry configRegistry) { return false; } }; - boolean isEditable(ILayerCell cell, IConfigRegistry configRegistry); + boolean isEditable(LayerCell cell, ConfigRegistry configRegistry); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/LayoutSizeConfig.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/LayoutSizeConfig.java index 9e60f0b4..ead744f0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/LayoutSizeConfig.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/LayoutSizeConfig.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.config; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; public class LayoutSizeConfig { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/AbstractEventConflater.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/AbstractEventConflater.java index c6c9de6f..ebd08e9f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/AbstractEventConflater.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/AbstractEventConflater.java @@ -16,15 +16,15 @@ package org.eclipse.statet.ecommons.waltable.conflation; import java.util.LinkedList; import java.util.List; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; public abstract class AbstractEventConflater implements IEventConflater { - protected List<ILayerEvent> queue= new LinkedList<>(); + protected List<LayerEvent> queue= new LinkedList<>(); @Override - public void addEvent(final ILayerEvent event){ + public void addEvent(final LayerEvent event){ this.queue.add(event); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/EventConflaterChain.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/EventConflaterChain.java index 4c0687c1..113bfbe4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/EventConflaterChain.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/EventConflaterChain.java @@ -17,7 +17,7 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.ScheduledFuture; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; import org.eclipse.statet.ecommons.waltable.util.Scheduler; @@ -69,7 +69,7 @@ public class EventConflaterChain implements IEventConflater { } @Override - public void addEvent(final ILayerEvent event) { + public void addEvent(final LayerEvent event) { for (final IEventConflater eventConflater : this.chain) { eventConflater.addEvent(event); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/IEventConflater.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/IEventConflater.java index d0652247..bacafd95 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/IEventConflater.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/IEventConflater.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.conflation; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; /** @@ -23,7 +23,7 @@ import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; */ public interface IEventConflater { - public abstract void addEvent(ILayerEvent event); + public abstract void addEvent(LayerEvent event); public abstract void clearQueue(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/VisualChangeEventConflater.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/VisualChangeEventConflater.java index e851c5cd..48054948 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/VisualChangeEventConflater.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/conflation/VisualChangeEventConflater.java @@ -14,8 +14,8 @@ package org.eclipse.statet.ecommons.waltable.conflation; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.IVisualChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.events.VisualChangeEvent; /** @@ -33,8 +33,8 @@ public class VisualChangeEventConflater extends AbstractEventConflater { } @Override - public void addEvent(final ILayerEvent event) { - if(event instanceof IVisualChangeEvent){ + public void addEvent(final LayerEvent event) { + if (event instanceof VisualChangeEvent){ super.addEvent(event); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ColumnPositionCoordinate.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ColumnPositionCoordinate.java index 0c54087e..013bc65f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ColumnPositionCoordinate.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ColumnPositionCoordinate.java @@ -13,24 +13,24 @@ package org.eclipse.statet.ecommons.waltable.coordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public final class ColumnPositionCoordinate { - private final ILayer layer; + private final Layer layer; public final long columnPosition; - public ColumnPositionCoordinate(final ILayer layer, final long columnPosition) { + public ColumnPositionCoordinate(final Layer layer, final long columnPosition) { this.layer= layer; this.columnPosition= columnPosition; } - public ILayer getLayer() { + public Layer getLayer() { return this.layer; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/Direction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/Direction.java deleted file mode 100644 index f8a269b5..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/Direction.java +++ /dev/null @@ -1,94 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.coordinate; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - - -public enum Direction { - - - LEFT (HORIZONTAL), - RIGHT (HORIZONTAL), - UP (VERTICAL), - DOWN (VERTICAL); - - - public static Direction backward(final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - return (orientation == HORIZONTAL) ? LEFT : UP; - } - - public static Direction forward(final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - return (orientation == HORIZONTAL) ? RIGHT : LEFT; - } - - - private final Orientation orientation; - - - private Direction(final Orientation orientation) { - this.orientation= orientation; - } - - - public Orientation getOrientation() { - return this.orientation; - } - - public boolean isBackward() { - switch (this) { - case LEFT: - case UP: - return true; - case RIGHT: - case DOWN: - default: - return false; - } - } - - public boolean isForward() { - switch (this) { - case RIGHT: - case DOWN: - return true; - case LEFT: - case UP: - default: - return false; - } - } - - public Direction getOpposite() { - switch (this) { - case LEFT: - return RIGHT; - case RIGHT: - return LEFT; - case UP: - return DOWN; - case DOWN: - default: - return UP; - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PixelOutOfBoundsException.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PixelOutOfBoundsException.java deleted file mode 100644 index 81845b07..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PixelOutOfBoundsException.java +++ /dev/null @@ -1,46 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2013, 2021 Stephan Wahlbrink and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 - # which is available at https://www.apache.org/licenses/LICENSE-2.0. - # - # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 - # - # Contributors: - # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.coordinate; - - -public class PixelOutOfBoundsException extends IllegalArgumentException { - - - private static final long serialVersionUID= 1L; - - - public static PixelOutOfBoundsException pixel(final long pixel, - final Orientation orientation) { - return new PixelOutOfBoundsException("pixel", pixel, orientation); //$NON-NLS-1$ - } - - public static PixelOutOfBoundsException pixel(final long pixel) { - return new PixelOutOfBoundsException("pixel", pixel); //$NON-NLS-1$ - } - - public PixelOutOfBoundsException(final String message) { - super(message); - } - - public PixelOutOfBoundsException(final String label, final long position) { - super(label + ": " + position); //$NON-NLS-1$ - } - - public PixelOutOfBoundsException(final String label, final long position, - final Orientation orientation) { - super(label + " (" + orientation + "): " + position); //$NON-NLS-1$ //$NON-NLS-2$ - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionCoordinate.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionCoordinate.java index 2857a113..8d6810d3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionCoordinate.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionCoordinate.java @@ -13,19 +13,19 @@ package org.eclipse.statet.ecommons.waltable.coordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public final class PositionCoordinate { - private final ILayer layer; + private final Layer layer; public long columnPosition; public long rowPosition; - public PositionCoordinate(final ILayer layer, final long columnPosition, final long rowPosition) { + public PositionCoordinate(final Layer layer, final long columnPosition, final long rowPosition) { this.layer= layer; this.columnPosition= columnPosition; this.rowPosition= rowPosition; @@ -38,7 +38,7 @@ public final class PositionCoordinate { } - public ILayer getLayer() { + public Layer getLayer() { return this.layer; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/RowPositionCoordinate.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/RowPositionCoordinate.java index 951ba11a..056fd033 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/RowPositionCoordinate.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/RowPositionCoordinate.java @@ -13,24 +13,24 @@ package org.eclipse.statet.ecommons.waltable.coordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public final class RowPositionCoordinate { - private final ILayer layer; + private final Layer layer; public final long rowPosition; - public RowPositionCoordinate(final ILayer layer, final long rowPosition) { + public RowPositionCoordinate(final Layer layer, final long rowPosition) { this.layer= layer; this.rowPosition= rowPosition; } - public ILayer getLayer() { + public Layer getLayer() { return this.layer; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/IPersistable.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/Persistable.java index 1f56739d..69a7df88 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/IPersistable.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/Persistable.java @@ -11,46 +11,54 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.persistence; +package org.eclipse.statet.ecommons.waltable.core; -import java.util.Properties; +import java.util.Map; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** - * Instances implementing this interface can save and load their - * state from a properties file. The state is therefore a collection - * of key value pairs. + * Instances implementing this interface can save and load their state from + * a properties map. The state is therefore a collection of key value pairs. */ -public interface IPersistable { - +@NonNullByDefault +public interface Persistable { + /** * Separator used for properties. Example: .BODY.columnWidth.resizableByDefault */ - public static final String DOT= "."; //$NON-NLS-1$ - + static final String DOT= "."; //$NON-NLS-1$ + /** * Separator used for values. Example: 0,1,2,3,4 */ - public static final String VALUE_SEPARATOR= ","; //$NON-NLS-1$ - + static final String VALUE_SEPARATOR= ","; //$NON-NLS-1$ + + /** - * Saves the state to the given Properties using the specified prefix. - * Note: The prefix must be prepended to the property key to support multiple states - * within one Properties instance. - * @param prefix The prefix to use for the state keys. Is also used as the state - * configuration name. - * @param properties The Properties instance to save the state to. + * Saves the state to the given Properties using the specified prefix. + * + * Note: The prefix must be prepended to the property key to support + * multiple states within one properties store. + * + * @param prefix the prefix to use for the state keys. It is also used as + * the state configuration name. + * @param properties the properties to save the state to. */ - public void saveState(String prefix, Properties properties); - + void saveState(String prefix, Map<String, String> properties); + /** - * Restore the state out of the given Properties identified by the specified prefix. + * Restore the state out of the given Properties identified by the + * specified prefix. + * * Note: The prefix must be prepended to the property key to support multiple states - * within one Properties instance. - * @param prefix The prefix to use for the state keys. Is also used as the state - * configuration name. - * @param properties The Properties instance to load the state from. + * within one properties store. + * + * @param prefix the prefix to use for the state keys. It is also used as + * the state configuration name. + * @param properties the properties to load the state from. */ - public void loadState(String prefix, Properties properties); + void loadState(String prefix, Map<String, String> properties); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractContextFreeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractContextFreeCommand.java index e7fc28d4..7936b9a9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractContextFreeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractContextFreeCommand.java @@ -11,15 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public abstract class AbstractContextFreeCommand implements ILayerCommand { + +@NonNullByDefault +public abstract class AbstractContextFreeCommand implements LayerCommand { + @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractDimPositionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractDimPositionCommand.java index 61df739b..efff90cf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractDimPositionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractDimPositionCommand.java @@ -12,23 +12,26 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; -public abstract class AbstractDimPositionCommand implements ILayerCommand { + +@NonNullByDefault +public abstract class AbstractDimPositionCommand implements LayerCommand { - private ILayerDim layerDim; + private LayerDim layerDim; private long position; - protected AbstractDimPositionCommand(final ILayerDim layerDim, final long position) { + protected AbstractDimPositionCommand(final LayerDim layerDim, final long position) { this.layerDim= layerDim; this.position= position; } @@ -43,7 +46,7 @@ public abstract class AbstractDimPositionCommand implements ILayerCommand { return this.layerDim.getOrientation(); } - public final ILayerDim getDim() { + public final LayerDim getDim() { return this.layerDim; } @@ -53,19 +56,19 @@ public abstract class AbstractDimPositionCommand implements ILayerCommand { @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - final ILayerDim targetDim= targetLayer.getDim(getOrientation()); - if (this.layerDim == targetDim) { + public boolean convertToTargetLayer(final Layer targetLayer) { + final LayerDim targetLayerDim= targetLayer.getDim(getOrientation()); + if (this.layerDim == targetLayerDim) { return true; } - return convertToTargetLayer(this.layerDim, this.position, targetDim); + return convertToTargetLayer(this.layerDim, this.position, targetLayerDim); } - protected boolean convertToTargetLayer(final ILayerDim dim, - final long position, final ILayerDim targetDim) { - final long targetPosition= LayerUtil.convertPosition(dim, position, position, targetDim); - if (targetPosition == ILayerDim.POSITION_NA) { + protected boolean convertToTargetLayer(final LayerDim dim, + final long position, final LayerDim targetDim) { + final long targetPosition= LayerUtils.convertPosition(dim, position, position, targetDim); + if (targetPosition == LayerDim.POSITION_NA) { return false; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractDimPositionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractDimPositionsCommand.java index 621f10a8..962a18cc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractDimPositionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractDimPositionsCommand.java @@ -12,38 +12,41 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; import java.util.Collection; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; -public abstract class AbstractDimPositionsCommand implements ILayerCommand { + +@NonNullByDefault +public abstract class AbstractDimPositionsCommand implements LayerCommand { protected static final long NO_REF= Long.MIN_VALUE + 1; - private ILayerDim layerDim; + private LayerDim layerDim; private long refPosition; private Collection<LRange> positions; - protected AbstractDimPositionsCommand(final ILayerDim layerDim, + protected AbstractDimPositionsCommand(final LayerDim layerDim, final long refPosition, final Collection<LRange> positions) { this.layerDim= layerDim; this.refPosition= refPosition; this.positions= positions; } - protected AbstractDimPositionsCommand(final ILayerDim layerDim, + protected AbstractDimPositionsCommand(final LayerDim layerDim, final Collection<LRange> positions) { this(layerDim, NO_REF, positions); } @@ -59,7 +62,7 @@ public abstract class AbstractDimPositionsCommand implements ILayerCommand { return this.layerDim.getOrientation(); } - public final ILayerDim getDim() { + public final LayerDim getDim() { return this.layerDim; } @@ -73,48 +76,48 @@ public abstract class AbstractDimPositionsCommand implements ILayerCommand { @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - final ILayerDim targetDim= targetLayer.getDim(getOrientation()); - if (this.layerDim == targetDim) { + public boolean convertToTargetLayer(final Layer targetLayer) { + final LayerDim targetLayerDim= targetLayer.getDim(getOrientation()); + if (this.layerDim == targetLayerDim) { return true; } - return convertToTargetLayer(this.layerDim, this.refPosition, targetDim); + return convertToTargetLayer(this.layerDim, this.refPosition, targetLayerDim); } - protected boolean convertToTargetLayer(final ILayerDim dim, - final long refPosition, final ILayerDim targetDim) { + protected boolean convertToTargetLayer(final LayerDim dim, + final long refPosition, final LayerDim targetDim) { final long targetRefPosition; final LRangeList targetPositions= new LRangeList(); if (refPosition == NO_REF) { targetRefPosition= NO_REF; for (final LRange lRange : this.positions) { for (long position= lRange.start; position < lRange.end; position++) { - final long targetPosition= LayerUtil.convertPosition(dim, + final long targetPosition= LayerUtils.convertPosition(dim, position, position, targetDim ); - if (targetPosition != ILayerDim.POSITION_NA) { + if (targetPosition != LayerDim.POSITION_NA) { targetPositions.values().add(targetPosition); } } } } - else if (refPosition != ILayerDim.POSITION_NA) { - targetRefPosition= LayerUtil.convertPosition(dim, refPosition, refPosition, targetDim); - if (targetRefPosition == ILayerDim.POSITION_NA) { + else if (refPosition != LayerDim.POSITION_NA) { + targetRefPosition= LayerUtils.convertPosition(dim, refPosition, refPosition, targetDim); + if (targetRefPosition == LayerDim.POSITION_NA) { return false; } for (final LRange lRange : this.positions) { for (long position= lRange.start; position < lRange.end; position++) { - final long targetPosition= LayerUtil.convertPosition(dim, + final long targetPosition= LayerUtils.convertPosition(dim, refPosition, position, targetDim ); - if (targetPosition != ILayerDim.POSITION_NA) { + if (targetPosition != LayerDim.POSITION_NA) { targetPositions.values().add(targetPosition); } } } } else { - targetRefPosition= ILayerDim.POSITION_NA; + targetRefPosition= LayerDim.POSITION_NA; } if (targetPositions.isEmpty()) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractLayerCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractLayerCommandHandler.java index c395edf0..36e942c3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractLayerCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractLayerCommandHandler.java @@ -11,16 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public abstract class AbstractLayerCommandHandler<T extends ILayerCommand> implements ILayerCommandHandler<T> { + +@NonNullByDefault +public abstract class AbstractLayerCommandHandler<T extends LayerCommand> implements LayerCommandHandler<T> { @Override - public final boolean doCommand(final ILayer targetLayer, final T command) { + public final boolean doCommand(final Layer targetLayer, final T command) { if (command.convertToTargetLayer(targetLayer)) { return doCommand(command); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractRelativeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractRelativeCommand.java index 490fae0e..c7e63af9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/AbstractRelativeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/AbstractRelativeCommand.java @@ -12,11 +12,16 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; + + +@NonNullByDefault public abstract class AbstractRelativeCommand extends AbstractContextFreeCommand { @@ -26,10 +31,7 @@ public abstract class AbstractRelativeCommand extends AbstractContextFreeCommand public AbstractRelativeCommand(final Direction direction, final long stepCount) { - if (direction == null) { - throw new NullPointerException("direction"); //$NON-NLS-1$ - } - this.direction= direction; + this.direction= nonNullAssert(direction); this.stepCount= stepCount; } @@ -38,9 +40,6 @@ public abstract class AbstractRelativeCommand extends AbstractContextFreeCommand this.stepCount= command.stepCount; } - @Override - public abstract AbstractRelativeCommand cloneCommand(); - public Direction getDirection() { return this.direction; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/ILayerCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/LayerCommand.java index b3a5f8ad..894c3f12 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/ILayerCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/LayerCommand.java @@ -11,20 +11,23 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.grid.layer.GridLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** - * Commands are fired by NatTable in response to user actions. - * Commands flow down the layer stack until they are processed by an - * {@link ILayer} or an associated {@link ILayerCommandHandler}. - * Commands can be fired from code by invoking {@link NatTable#doCommand(ILayerCommand)} + * A command triggers a specific operation on a layer or behaviour of the table. + * + * Commands flow down the layer stack until they are processed by a {@link Layer} + * or an associated {@link LayerCommandHandler}. + * Commands can be fired from code by invoking {@link NatTable#doCommand(LayerCommand)}. */ -public interface ILayerCommand { +@NonNullByDefault +public interface LayerCommand { /** @@ -36,15 +39,14 @@ public interface ILayerCommand { * @param targetLayer the target layer * @return true if the command is valid after conversion, false if the command is no longer valid. */ - public boolean convertToTargetLayer(ILayer targetLayer); + boolean convertToTargetLayer(Layer targetLayer); /** * Same semantics as {@link Object#clone()} * Used to make a copies of the command if has to passed to different layer stacks. * - * @see GridLayer#doCommand(ILayerCommand) * @return a cloned instance of the command */ - public ILayerCommand cloneCommand(); + LayerCommand cloneCommand(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/ILayerCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/LayerCommandHandler.java index 3c0336a8..5bf3f535 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/ILayerCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/command/LayerCommandHandler.java @@ -11,21 +11,30 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.core.command; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public interface ILayerCommandHandler <T extends ILayerCommand> { + +@NonNullByDefault +public interface LayerCommandHandler <T extends LayerCommand> { - public Class<T> getCommandClass(); + Class<T> getCommandClass(); /** * @param targetLayer the target layer * @param command the command * @return true if the command has been handled, false otherwise */ - public boolean doCommand(ILayer targetLayer, T command); + default boolean doCommand(final Layer targetLayer, final T command) { + return executeCommand(command); + } + + default boolean executeCommand(final T command) { + throw new UnsupportedOperationException(); + } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/BasicConfigRegistry.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/BasicConfigRegistry.java new file mode 100644 index 00000000..7f058baf --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/BasicConfigRegistry.java @@ -0,0 +1,150 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.config; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + + +@NonNullByDefault +public class BasicConfigRegistry implements ConfigRegistry { + + + private DisplayModeLookupStrategy displayModeLookupStrategy= new DefaultDisplayModeOrdering(); + + private final Map<ConfigAttribute<?>, Map<DisplayMode, Map<String, ?>>> configRegistry= new HashMap<>(); + + + public BasicConfigRegistry() { + } + + + @Override + public DisplayModeLookupStrategy getDisplayModeOrdering() { + return this.displayModeLookupStrategy; + } + + public void setDisplayModeOrdering(final DisplayModeLookupStrategy displayModeLookupStrategy) { + this.displayModeLookupStrategy= nonNullAssert(displayModeLookupStrategy); + } + + + @Override + public <T> @Nullable T getAttribute(final ConfigAttribute<T> configAttribute, + final DisplayMode targetDisplayMode, final @NonNull String... configLabels) { + return getAttribute(configAttribute, targetDisplayMode, ImCollections.newList(configLabels)); + } + + @Override + @SuppressWarnings("unchecked") + public <T> @Nullable T getAttribute(final ConfigAttribute<T> configAttribute, + final DisplayMode targetDisplayMode, final List<String> configLabels) { + @Nullable T attributeValue= null; + + final Map<DisplayMode, Map<String, ?>> displayModeAttributeMap= this.configRegistry.get(configAttribute); + if (displayModeAttributeMap != null) { + for (final DisplayMode displayMode : this.displayModeLookupStrategy.getDisplayModeOrdering(targetDisplayMode)) { + final Map<String, T> configAttributeMap= (Map<String, T>)displayModeAttributeMap.get(displayMode); + if (configAttributeMap != null) { + for (final String configLabel : configLabels) { + attributeValue= configAttributeMap.get(configLabel); + if (attributeValue != null) { + return attributeValue; + } + } + + // default config type + attributeValue= configAttributeMap.get(null); + if (attributeValue != null) { + return attributeValue; + } + } + } + } + + return attributeValue; + } + + @Override + @SuppressWarnings("unchecked") + public <T> @Nullable T getSpecificAttribute(final ConfigAttribute<T> configAttribute, + final DisplayMode displayMode, final @Nullable String configLabel) { + @Nullable T attributeValue= null; + + final Map<DisplayMode, Map<String, ?>> displayModeAttributeMap= this.configRegistry.get(configAttribute); + if (displayModeAttributeMap != null) { + final Map<String, T> configAttributeMap= (Map<String, T>)displayModeAttributeMap.get(displayMode); + if (configAttributeMap != null) { + attributeValue= configAttributeMap.get(configLabel); + if (attributeValue != null) { + return attributeValue; + } + } + } + + return attributeValue; + } + + @Override + public <T> void registerAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue) { + registerAttribute(configAttribute, attributeValue, DisplayMode.NORMAL); + } + + @Override + public <T> void registerAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue, + final DisplayMode displayMode) { + registerAttribute(configAttribute, attributeValue, displayMode, null); + } + + @Override + @SuppressWarnings("unchecked") + public <T> void registerAttribute(final ConfigAttribute<T> configAttribute, final T attributeValue, + final DisplayMode displayMode, final String configLabel) { + Map<DisplayMode, Map<String, ?>> displayModeAttributeMap= this.configRegistry.get(configAttribute); + if (displayModeAttributeMap == null) { + displayModeAttributeMap= new HashMap<>(); + this.configRegistry.put(configAttribute, displayModeAttributeMap); + } + + Map<String, T> configAttributeMap= (Map<String, T>) displayModeAttributeMap.get(displayMode); + if (configAttributeMap == null) { + configAttributeMap= new HashMap<>(); + displayModeAttributeMap.put(displayMode, configAttributeMap); + } + + configAttributeMap.put(configLabel, attributeValue); + } + + @Override + @SuppressWarnings("unchecked") + public <T> void unregisterAttribute(final ConfigAttribute<T> configAttributeType, + final DisplayMode displayMode, final String configLabel) { + final Map<DisplayMode, Map<String, ?>> displayModeAttributeMap= this.configRegistry.get(configAttributeType); + if (displayModeAttributeMap != null) { + final Map<String, T> configAttributeMap= (Map<String, T>) displayModeAttributeMap.get(displayMode); + if (configAttributeMap != null) { + configAttributeMap.remove(configLabel); + } + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/ConfigAttribute.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/ConfigAttribute.java index f8b48be3..58f4166b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/ConfigAttribute.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/ConfigAttribute.java @@ -11,9 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.config; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public class ConfigAttribute<T> { } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfigRegistry.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/ConfigRegistry.java index a9dbb5a2..697a09ac 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/config/IConfigRegistry.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/ConfigRegistry.java @@ -11,35 +11,37 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.config; +package org.eclipse.statet.ecommons.waltable.core.config; import java.util.List; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IDisplayModeLookupStrategy; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** - * Holds all the settings, bindings and other configuration for NatTable. - * <p> - * See ConfigRegistryTest for a better understanding. - * @see ConfigRegistry + * @see BasicConfigRegistry */ -public interface IConfigRegistry { +@NonNullByDefault +public interface ConfigRegistry { + + + DisplayModeLookupStrategy getDisplayModeOrdering(); + /** * If retrieving registered values * <p> * Example 1: - * <p>configRegistry.getConfigAttribute(attribute, DisplayMode.EDIT);</p> + * <p>registry.getAttribute(attribute, DisplayMode.EDIT);</p> * <ol> * <li>It will look for an attribute registered using the EDIT display mode</li> * <li>If it can't find that it will try and find an attribute under the NORMAL mode</li> - * <li>If it can't find one it will try and find one registered without a display mode {@link #registerConfigAttribute(ConfigAttribute, Object)}</li> + * <li>If it can't find one it will try and find one registered without a display mode {@link #registerAttribute(ConfigAttribute, Object)}</li> * </ol> * Example 2: - * <p>configRegistry.getConfigAttribute(attribute, DisplayMode.NORMAL, "testLabel", "testLabel_1");</p> + * <p>registry.getAttribute(attribute, DisplayMode.NORMAL, "testLabel", "testLabel_1");</p> * <ol> * <li>It will look for an attribute registered by display mode NORMAL and "testLabel"</li> * <li>It will look for an attribute registered by display mode NORMAL and "testLabel_1"</li> @@ -50,36 +52,38 @@ public interface IConfigRegistry { * @param configLabels the cell needs to have, for this attribute to be returned * @return the configAttribute, if the display mode and the configLabels match */ - <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, DisplayMode targetDisplayMode, String...configLabels); + <T> @Nullable T getAttribute(ConfigAttribute<T> configAttribute, DisplayMode targetDisplayMode, + @NonNull String... configLabels); /** - * @see #getConfigAttribute(ConfigAttribute, DisplayMode, String...) + * @see #getAttribute(ConfigAttribute, DisplayMode, String...) */ - <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, DisplayMode targetDisplayMode, List<String> configLabels); + <T> @Nullable T getAttribute(ConfigAttribute<T> configAttribute, DisplayMode targetDisplayMode, + List<String> configLabels); /** - * @see #getConfigAttribute(ConfigAttribute, DisplayMode, String...) + * @see #getAttribute(ConfigAttribute, DisplayMode, String...) */ - <T> T getSpecificConfigAttribute(ConfigAttribute<T> configAttribute, DisplayMode displayMode, String configLabel); + <T> @Nullable T getSpecificAttribute(ConfigAttribute<T> configAttribute, DisplayMode displayMode, + @Nullable String configLabel); /** * Register a configuration attribute */ - <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue); + <T> void registerAttribute(ConfigAttribute<T> configAttribute, T attributeValue); /** * Register an attribute against a {@link DisplayMode}. */ - <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, DisplayMode targetDisplayMode); + <T> void registerAttribute(ConfigAttribute<T> configAttribute, T attributeValue, DisplayMode targetDisplayMode); /** * Register an attribute against a {@link DisplayMode} and configuration label (applied to cells) */ - <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, DisplayMode targetDisplayMode, String configLabel); + <T> void registerAttribute(ConfigAttribute<T> configAttribute, T attributeValue, DisplayMode targetDisplayMode, String configLabel); - <T> void unregisterConfigAttribute(ConfigAttribute<T> configAttributeType, DisplayMode displayMode, String configLabel); + <T> void unregisterAttribute(ConfigAttribute<T> configAttributeType, DisplayMode displayMode, String configLabel); - IDisplayModeLookupStrategy getDisplayModeOrdering(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DefaultDisplayModeOrdering.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DefaultDisplayModeOrdering.java new file mode 100644 index 00000000..44f6ca57 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DefaultDisplayModeOrdering.java @@ -0,0 +1,52 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.config; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + + +@NonNullByDefault +public class DefaultDisplayModeOrdering implements DisplayModeLookupStrategy { + + + private static final ImList<DisplayMode> NORMAL_ORDERING= ImCollections.newList(DisplayMode.NORMAL); + + private static final ImList<DisplayMode> HOVER_ORDERING= ImCollections.newList(DisplayMode.HOVER, DisplayMode.NORMAL); + + private static final ImList<DisplayMode> SELECT_ORDERING= ImCollections.newList(DisplayMode.SELECTED, DisplayMode.NORMAL); + + private static final ImList<DisplayMode> EDIT_ORDERING= ImCollections.newList(DisplayMode.EDIT, DisplayMode.NORMAL); + + private static final ImList<DisplayMode> EMPTY_ORDERING= ImCollections.emptyList(); + + + @Override + public ImList<DisplayMode> getDisplayModeOrdering(final DisplayMode targetDisplayMode) { + switch (targetDisplayMode) { + case NORMAL: + return NORMAL_ORDERING; + case HOVER: + return HOVER_ORDERING; + case SELECTED: + return SELECT_ORDERING; + case EDIT: + return EDIT_ORDERING; + default: + return EMPTY_ORDERING; + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/DisplayMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DisplayMode.java index 7b60a48e..56e2cc42 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/DisplayMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DisplayMode.java @@ -11,7 +11,9 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.config; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** @@ -19,19 +21,19 @@ package org.eclipse.statet.ecommons.waltable.style; * <ol> * <li>During normal display a cell is in NORMAL mode.</li> * <li>If the contents of the cell are being edited, its in EDIT mode.</li> - * <li>If a cell has been selected, its in SELECT mode.</li> + * <li>If a cell has been selected, its in SELECTED mode.</li> * </ol> * - * These modes are used to bind different settings to different modes. - * For example, a different style can be registered for a cell - * when it is in SELECT mode. - * + * These modes are used to bind different settings to different modes. For + * example, a different style can be registered for a cell when it is in + * SELECTED mode. */ +@NonNullByDefault public enum DisplayMode { NORMAL, HOVER, - SELECT, + SELECTED, EDIT; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/IDisplayModeLookupStrategy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DisplayModeLookupStrategy.java index 702d20da..4c81cad8 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/IDisplayModeLookupStrategy.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/config/DisplayModeLookupStrategy.java @@ -11,14 +11,16 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.config; -import java.util.List; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -public interface IDisplayModeLookupStrategy { +@NonNullByDefault +public interface DisplayModeLookupStrategy { - List<DisplayMode> getDisplayModeOrdering(DisplayMode targetDisplayMode); + ImList<DisplayMode> getDisplayModeOrdering(DisplayMode targetDisplayMode); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/Direction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/Direction.java new file mode 100644 index 00000000..7884e988 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/Direction.java @@ -0,0 +1,154 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.coordinate; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + + +@NonNullByDefault +public enum Direction { + + + LEFT { + + @Override + public Orientation getOrientation() { + return HORIZONTAL; + } + + @Override + public boolean isForward() { + return false; + } + + @Override + public boolean isBackward() { + return true; + } + + @Override + public Direction getOpposite() { + return RIGHT; + } + + }, + + RIGHT { + + @Override + public Orientation getOrientation() { + return HORIZONTAL; + } + + @Override + public boolean isForward() { + return true; + } + + @Override + public boolean isBackward() { + return false; + } + + @Override + public Direction getOpposite() { + return LEFT; + } + + }, + + UP { + + @Override + public Orientation getOrientation() { + return VERTICAL; + } + + @Override + public boolean isForward() { + return false; + } + + @Override + public boolean isBackward() { + return true; + } + + @Override + public Direction getOpposite() { + return DOWN; + } + + }, + + DOWN { + + @Override + public Orientation getOrientation() { + return VERTICAL; + } + + @Override + public boolean isForward() { + return true; + } + + @Override + public boolean isBackward() { + return false; + } + + @Override + public Direction getOpposite() { + return UP; + } + + }; + + + public static Direction forward(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return RIGHT; + case VERTICAL: + return LEFT; + default: + throw new IllegalStateException(); + } + } + + public static Direction backward(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return LEFT; + case VERTICAL: + return UP; + default: + throw new IllegalStateException(); + } + } + + + public abstract Orientation getOrientation(); + + public abstract boolean isForward(); + + public abstract boolean isBackward(); + + public abstract Direction getOpposite(); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LPoint.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LPoint.java index ac9cbe7e..154a8291 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LPoint.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LPoint.java @@ -12,25 +12,27 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; + +import org.eclipse.statet.jcommons.lang.Immutable; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** - * Instances of this class represent places on the (x, y) - * coordinate plane. + * Point on the (x, y) coordinate plane. * - * <p>The coordinate space for rectangles and points is considered - * to have increasing values downward and to the right from its - * origin making this the normal, computer graphics oriented notion - * of (x, y) coordinates rather than the strict mathematical one. - * </p> + * <p>The coordinate space for rectangles and points is considered to have + * increasing values downward and to the right from its origin making this + * the normal, computer graphics oriented notion of (x, y) coordinates rather + * than the strict mathematical one.</p> * * @see LRectangle */ - -public final class LPoint { +@NonNullByDefault +public final class LPoint implements Immutable { /** * the x coordinate of the point @@ -49,7 +51,7 @@ public final class LPoint { * @param x the x coordinate * @param y the y coordinate */ - public LPoint (final long x, final long y) { + public LPoint(final long x, final long y) { this.x= x; this.y= y; } @@ -64,19 +66,19 @@ public final class LPoint { @Override public int hashCode() { - int h= (int) (this.x ^ (this.x >>> 32)); + int h= (int)(this.x ^ (this.x >>> 32)); h= Integer.rotateRight(h, 15); - h ^= (int) (this.y ^ (this.y >>> 32)); + h ^= (int)(this.y ^ (this.y >>> 32)); return h ^ (h >>> 7); } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } if (obj instanceof LPoint) { - final LPoint other= (LPoint) obj; + final LPoint other= (LPoint)obj; return (this.x == other.x && this.y == other.y); } return false; @@ -84,8 +86,8 @@ public final class LPoint { @Override - public String toString () { - return "LPoint {" + this.x + ", " + this.y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + public String toString() { + return "{" + this.x + ", " + this.y + "}L"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRange.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRange.java index 9a19ef9b..3435d16f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRange.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRange.java @@ -11,17 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; -import java.util.ArrayList; -import java.util.List; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** - * Represents an LRange of numbers. - * Example a LRange of selected rows: 1 - 100 - * Ranges are inclusive of their start value and not inclusive of their end value, i.e. start <= x < end + * Range of numbers of type long. + * + * <p>Ranges are inclusive of their start value and exclusive of their end value, + * start <= x < end.</p> */ +@NonNullByDefault public final class LRange implements Comparable<LRange> { @@ -52,17 +54,17 @@ public final class LRange implements Comparable<LRange> { @Override - public int compareTo(final LRange o) { - if (this.start < o.start) { + public int compareTo(final LRange other) { + if (this.start < other.start) { return -1; } - if (this.start > o.start) { + if (this.start > other.start) { return 1; } - if (this.end < o.end) { + if (this.end < other.end) { return -1; } - if (this.end > o.end) { + if (this.end > other.end) { return 1; } return 0; @@ -72,51 +74,40 @@ public final class LRange implements Comparable<LRange> { * @return <code>true</code> if the range contains the given row position */ public boolean contains(final long position) { - return ((position >= this.start) && (position < this.end)); + return (position >= this.start && position < this.end); } - + public boolean overlap(final LRange lRange) { - return ((this.start < this.end) && // this is a non-empty range - (lRange.start < lRange.end) && // range parameter is non-empty - (contains(lRange.start) || contains(lRange.end - 1) || lRange.contains(this.start) || lRange.contains(this.end - 1)) ); - } - - public List<Long> getMembers() { - final long l= size(); - if (l > Integer.MAX_VALUE) { - throw new RuntimeException("too long: " + l); - } - final List<Long> members= new ArrayList<>((int) l); - for (long i= this.start; i < this.end; i++) { - members.add(Long.valueOf(i)); - } - return members; + return (this.start < this.end && // this is non-empty + lRange.start < lRange.end && // parameter is non-empty + (contains(lRange.start) || contains(lRange.end - 1) + || lRange.contains(this.start) || lRange.contains(this.end - 1) )); } - - + + @Override public int hashCode() { - int h= (int) (this.start ^ (this.start >>> 32)); + int h= (int)(this.start ^ (this.start >>> 32)); h= Integer.rotateRight(h, 15); - h ^= (int) (this.end ^ (this.end >>> 32)); + h ^= (int)(this.end ^ (this.end >>> 32)); return h ^ (h >>> 7); } - + @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof LRange)) { - return false; + if (obj instanceof LRange) { + final LRange other= (LRange)obj; + return (this.start == other.start && this.end == other.end); } - final LRange other= (LRange) obj; - return ((this.start == other.start) && (this.end == other.end)); + return false; } @Override public String toString() { - return "LRange {" + this.start + ", " + this.end + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return "[" + this.start + ", " + this.end + ")L"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRangeList.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRangeList.java index 3f95d180..f630343d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRangeList.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRangeList.java @@ -12,7 +12,7 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; import java.util.ArrayList; import java.util.Collection; @@ -20,19 +20,26 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.eclipse.statet.jcommons.collections.LongIterator; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + /** - * A special list for {@link LRange ranges}, which sorts and merges automatically all added ranges. + * A special list for {@link LRange ranges}, which sorts and merges + * automatically all added ranges. * <p> - * Important Note: Added range objects may be changed if the list is modified. The range objects + * Important Note: Added range objects may be changed if the list is modified. The range objects * must not be changed outside of the list.</p> - * <p> - * The add and remove methods of LRangeList guarantees that the ranges in a list object are never - * empty, do not intersect and touch and are always sorted.</p> - * <p> - * The class provides additionally direct {@link #values() access} to the single values described by - * the ranges. + * + * <p>The add and remove methods of LRangeList guarantees that the ranges in a + * list object are never empty, do not intersect and touch and are always + * sorted.</p> + * <p>The class provides additionally direct {@link #values() access} to the + * single values described by the ranges.</p> */ +@NonNullByDefault public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { @@ -42,9 +49,9 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { /** * Iterator which allows to iterate over the values of a collection with {@link LRange} elements. * - * @see LRangeList#valuesIterator() + * @see LRangeList#values() */ - public static final class ValueIterator implements ILValueIterator { + public static final class ValueIterator implements LongIterator { private final Iterator<LRange> rangeIter; @@ -58,7 +65,7 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { * * @param c the collection to iterate over */ - public ValueIterator(/*@NonNull*/ final Collection<LRange> c) { + public ValueIterator(final Collection<LRange> c) { this.rangeIter= c.iterator(); } @@ -125,7 +132,7 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { * * @param initialRanges the ranges initially added to the list */ - public LRangeList(final LRange... initialRanges) { + public LRangeList(final @NonNull LRange... initialRanges) { this(); for (int i= 0; i < initialRanges.length; i++) { @@ -282,7 +289,7 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { } @Override - public boolean remove(final Object o) { + public boolean remove(final @Nullable Object o) { if (o instanceof LRange) { return remove((LRange) o); } @@ -359,7 +366,7 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { } @Override - public ILValueIterator iterator() { + public LongIterator iterator() { return new ValueIterator(LRangeList.this); } @@ -431,7 +438,7 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { return LRangeList.super.get(LRangeList.super.size() - 1).end - 1; } - public LRange getRangeOf(final long value) { + public @Nullable LRange getRangeOf(final long value) { int idx= indexOfStart(value); if (idx >= 0) { // value == range1.start return LRangeList.super.get(idx); @@ -457,10 +464,10 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { return ((this == obj || (obj instanceof Values - && LRangeList.this.equals(((Values) obj).getRangeList())) )); + && LRangeList.this.equals(((Values)obj).getRangeList())) )); } } @@ -474,22 +481,4 @@ public final class LRangeList extends ArrayList<LRange> implements Set<LRange> { return this.values; } - - @Deprecated // not recommend - public static Collection<Long> listValues(final Collection<LRange> positions) { - final ArrayList<Long> list= new ArrayList<>(); - for (final Iterator<LRange> iter= positions.iterator(); iter.hasNext(); ) { - final LRange lRange= iter.next(); - final long sum= list.size() + lRange.size(); - if (sum > 0xffffff) { - throw new IndexOutOfBoundsException("" + sum); //$NON-NLS-1$ // TODO implement ranges - } - list.ensureCapacity((int) sum); - for (long position= lRange.start; position < lRange.end; position++) { - list.add(position); - } - } - return list; - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRectangle.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRectangle.java index f62c2345..b1a7edbe 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/LRectangle.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/LRectangle.java @@ -12,26 +12,27 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation for long coordinates #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** * Instances of this class represent rectangular areas in an (x, y) coordinate system. The top left * corner of the rectangle is specified by its x and y values, and the extent of the rectangle is * specified by its width and height. - * <p> - * The coordinate space for rectangles and points is considered to have increasing values downward + * + * <p>The coordinate space for rectangles and points is considered to have increasing values downward * and to the right from its origin making this the normal, computer graphics oriented notion * of (x, y) coordinates rather than the strict mathematical one. * </p> - * <p> - * The hashCode() method in this class uses the values of the public fields to compute the hash + * <p>The hashCode() method in this class uses the values of the public fields to compute the hash * value. When storing instances of the class in hashed collections, do not modify these fields * after the object has been inserted. * </p> */ +@NonNullByDefault public final class LRectangle { /** @@ -97,7 +98,7 @@ public final class LRectangle { * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise */ public boolean isEmpty() { - return ((this.width <= 0) || (this.height <= 0)); + return (this.width <= 0 || this.height <= 0); } /** @@ -109,8 +110,8 @@ public final class LRectangle { * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise */ public boolean contains(final long x, final long y) { - return ((x >= this.x) && (y >= this.y) - && x < (this.x + this.width) && y < (this.y + this.height) ); + return (x >= this.x && y >= this.y + && x < this.x + this.width && y < this.y + this.height ); } /** @@ -123,7 +124,7 @@ public final class LRectangle { * * @exception NullPointerException if the argument is <code>null</code> */ - public boolean contains(/*@NonNull*/ final LPoint pt) { + public boolean contains(final LPoint pt) { if (pt == null) { throw new NullPointerException("pt"); //$NON-NLS-1$ } @@ -141,7 +142,7 @@ public final class LRectangle { * * @exception NullPointerException if the argument is <code>null</code> */ - public boolean contains(/*@NonNull*/ final LRectangle rect) { + public boolean contains(final LRectangle rect) { if (rect == null) { throw new NullPointerException("rect"); //$NON-NLS-1$ } @@ -189,7 +190,7 @@ public final class LRectangle { * @see #intersection(LRectangle) * @see #isEmpty() */ - public boolean intersects(/*@NonNull*/ final LRectangle rect) { + public boolean intersects(final LRectangle rect) { if (rect == null) { throw new NullPointerException("rect"); //$NON-NLS-1$ } @@ -197,69 +198,6 @@ public final class LRectangle { } - //-- Destructive Methods --// - - /** - * Destructively replaces the x, y, width and height values in the receiver with ones which - * represent the union of the rectangles specified by the receiver and the given rectangle. - * <p> - * The union of two rectangles is the smallest single rectangle that completely covers both of - * the areas covered by the two given rectangles. - * </p> - * - * @param rect the rectangle to merge with the receiver - * - * @exception NullPointerException if the argument is <code>null</code> - */ - public void add(/*@NonNull*/ final LRectangle rect) { - if (rect == null) { - throw new NullPointerException("rect"); //$NON-NLS-1$ - } - final long left= (this.x < rect.x) ? this.x : rect.x; - final long top= (this.y < rect.y) ? this.y : rect.y; - long lhs= this.x + this.width; - long rhs= rect.x + rect.width; - final long right= (lhs > rhs) ? lhs : rhs; - lhs= this.y + this.height; - rhs= rect.y + rect.height; - final long bottom= (lhs > rhs) ? lhs : rhs; - this.x= left; - this.y= top; - this.width= right - left; - this.height= bottom - top; - } - - /** - * Destructively replaces the x, y, width and height values in the receiver with ones which - * represent the intersection of the rectangles specified by the receiver and the given - * rectangle. - * - * @param rect the rectangle to intersect with the receiver - * - * @exception NullPointerException if the argument is <code>null</code> - */ - public void intersect(/*@NonNull*/ final LRectangle rect) { - if (rect == null) { - throw new NullPointerException("rect"); //$NON-NLS-1$ - } - if (this == rect) { - return; - } - final long left= (this.x > rect.x) ? this.x : rect.x; - final long top= (this.y > rect.y) ? this.y : rect.y; - long lhs= this.x + this.width; - long rhs= rect.x + rect.width; - final long right= (lhs < rhs) ? lhs : rhs; - lhs= this.y + this.height; - rhs= rect.y + rect.height; - final long bottom= (lhs < rhs) ? lhs : rhs; - this.x= (right < left) ? 0 : left; - this.y= (bottom < top) ? 0 : top; - this.width= (right < left) ? 0 : right - left; - this.height= (bottom < top) ? 0 : bottom - top; - } - - //-- Methods Creating New Coordinate Objects --// /** @@ -275,7 +213,7 @@ public final class LRectangle { * * @exception NullPointerException if the argument is <code>null</code> */ - public LRectangle intersection(/*@NonNull*/ final LRectangle rect) { + public LRectangle intersection(final LRectangle rect) { if (rect == null) { throw new NullPointerException("rect"); //$NON-NLS-1$ } @@ -311,7 +249,7 @@ public final class LRectangle { * * @see #add(LRectangle) */ - public LRectangle union(/*@NonNull*/ final LRectangle rect) { + public LRectangle union(final LRectangle rect) { if (rect == null) { throw new NullPointerException("rect"); //$NON-NLS-1$ } @@ -332,13 +270,26 @@ public final class LRectangle { * @param orientation the orientation * @return the range of the rectangle */ - public LRange getRange(/*@NonNull*/ final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ + public LRange getRange(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return new LRange(this.x, this.x + this.width); + case VERTICAL: + return new LRange(this.y, this.y + this.height); + default: + throw new IllegalStateException(); + } + } + + public long getSize(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return this.width; + case VERTICAL: + return this.height; + default: + throw new IllegalStateException(); } - return (orientation == HORIZONTAL) ? - new LRange(this.x, this.x + this.width) : - new LRange(this.y, this.y + this.height); } public LRectangle switchOrientation() { @@ -348,52 +299,29 @@ public final class LRectangle { //-- Object Methods --// - /** - * Returns an integer hash code for the receiver. Any two objects that return <code>true</code> - * when passed to <code>equals</code> must return the same value for this method. - * - * @return the receiver's hash - * - * @see #equals(Object) - */ @Override public int hashCode() { - int h= (int) (this.x ^ (this.x >>> 32)); - h ^= Integer.rotateLeft((int) (this.width ^ (this.width >>> 32)), 3); + int h= (int)(this.x ^ (this.x >>> 32)); + h ^= Integer.rotateLeft((int)(this.width ^ (this.width >>> 32)), 3); h= Integer.rotateRight(h, 15); h ^= (int) (this.y ^ (this.y >>> 32)); - h ^= Integer.rotateLeft((int) (this.height ^ (this.height >>> 32)), 3); + h ^= Integer.rotateLeft((int)(this.height ^ (this.height >>> 32)), 3); return h ^ (h >>> 7); } - /** - * Compares the argument to the receiver, and returns true if they represent the <em>same</em> - * object using a class specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> - * otherwise - * - * @see #hashCode() - */ @Override - public boolean equals(final Object object) { + public boolean equals(final @Nullable Object object) { if (object == this) { return true; } - if (!(object instanceof LRectangle)) { - return false; + if (object instanceof LRectangle) { + final LRectangle other= (LRectangle)object; + return (this.x == other.x && this.y == other.y + && this.width == other.width && this.height == other.height ); } - final LRectangle other= (LRectangle) object; - return ((this.x == other.x) && (this.y == other.y) - && (this.width == other.width) && (this.height == other.height) ); + return false; } - /** - * Returns a string containing a concise, human-readable description of the receiver. - * - * @return a string representation of the rectangle - */ @Override public String toString() { return "LRectangle {" + this.x + ", " + this.y + ", " + this.width + ", " + this.height + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/Orientation.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/Orientation.java index 45a3b9e4..a8bc8674 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/Orientation.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/Orientation.java @@ -12,25 +12,40 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public enum Orientation { /** * The horizontal orientation (columns) */ - HORIZONTAL, + HORIZONTAL { + + @Override + public Orientation getOrthogonal() { + return VERTICAL; + } + + }, /** * The vertical orientation (rows) */ - VERTICAL(); + VERTICAL { + + @Override + public Orientation getOrthogonal() { + return HORIZONTAL; + } + + }; - public Orientation getOrthogonal() { - return (this == HORIZONTAL) ? VERTICAL : HORIZONTAL; - } + public abstract Orientation getOrthogonal(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PixelOutOfBoundsException.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PixelOutOfBoundsException.java new file mode 100644 index 00000000..fb32e23a --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PixelOutOfBoundsException.java @@ -0,0 +1,31 @@ +/*=============================================================================# + # Copyright (c) 2013, 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.coordinate; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + + +@NonNullByDefault +public class PixelOutOfBoundsException extends IllegalArgumentException { + + + private static final long serialVersionUID= 1L; + + + public PixelOutOfBoundsException(final long pixel, final Orientation orientation) { + super("pixel (" + orientation + ")= " + pixel); //$NON-NLS-1$ //$NON-NLS-2$ + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionId.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PositionId.java index 1f31dde3..70a61b97 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionId.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PositionId.java @@ -12,9 +12,12 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public class PositionId { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionOutOfBoundsException.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PositionOutOfBoundsException.java index 7357200a..02479833 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/PositionOutOfBoundsException.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/coordinate/PositionOutOfBoundsException.java @@ -12,28 +12,18 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.ecommons.waltable.core.coordinate; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public class PositionOutOfBoundsException extends IllegalArgumentException { private static final long serialVersionUID= 1L; - public static PositionOutOfBoundsException position(final long position, - final Orientation orientation) { - return new PositionOutOfBoundsException("position", position, orientation); //$NON-NLS-1$ - } - - public static PositionOutOfBoundsException position(final long position) { - return new PositionOutOfBoundsException("position", position); //$NON-NLS-1$ - } - - public static PositionOutOfBoundsException underlyingPosition(final long position) { - return new PositionOutOfBoundsException("underlyingPosition", position); //$NON-NLS-1$ - } - public static PositionOutOfBoundsException refPosition(final long position, final Orientation orientation) { return new PositionOutOfBoundsException("refPosition", position, orientation); //$NON-NLS-1$ @@ -53,4 +43,12 @@ public class PositionOutOfBoundsException extends IllegalArgumentException { super(label + " (" + orientation + "): " + position); //$NON-NLS-1$ //$NON-NLS-2$ } + public PositionOutOfBoundsException(final long position) { + super("position= " + position); //$NON-NLS-1$ + } + + public PositionOutOfBoundsException(final long position, final Orientation orientation) { + super("position (" + orientation + ")= " + position); //$NON-NLS-1$ //$NON-NLS-2$ + } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnAccessor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ColumnAccessor.java index 876cec35..34cf9f3f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnAccessor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ColumnAccessor.java @@ -11,20 +11,27 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.core.data; + +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** - * Maps the properties from the row object to the corresponding columns. + * Maps the properties from the row object to the corresponding columns. + * * @param <T> type of the bean used as a row object */ -public interface IColumnAccessor<T> { +@NonNullByDefault +public interface ColumnAccessor<T> { + + long getColumnCount(); - Object getDataValue(T rowObject, long columnIndex); - void setDataValue(T rowObject, long columnIndex, Object newValue); + @Nullable Object getDataValue(@NonNull T rowObject, long columnIndex); - long getColumnCount(); + void setDataValue(@NonNull T rowObject, long columnIndex, @Nullable Object newValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ControlData.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ControlData.java index 4f722f2a..48928e60 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ControlData.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ControlData.java @@ -12,9 +12,13 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.core.data; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +@NonNullByDefault public class ControlData { @@ -50,7 +54,7 @@ public class ControlData { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { return (obj == this || (obj instanceof ControlData && this.code == ((ControlData) obj).code )); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/DataCell.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/DataCell.java index 279719a6..aa1f9b59 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/DataCell.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/DataCell.java @@ -11,9 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.data; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +@NonNullByDefault public class DataCell { protected long columnPosition; @@ -68,18 +72,18 @@ public class DataCell { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof DataCell)) { - return false; + if (obj instanceof DataCell) { + final DataCell other= (DataCell) obj; + return (this.columnPosition == other.columnPosition + && this.rowPosition == other.rowPosition + && this.columnSpan == other.columnSpan + && this.rowSpan == other.rowSpan); } - final DataCell other= (DataCell) obj; - return (this.columnPosition == other.columnPosition - && this.rowPosition == other.rowPosition - && this.columnSpan == other.columnSpan - && this.rowSpan == other.rowSpan); + return false; } @Override diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/DataProvider.java index bca56e4c..4267e0f0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/DataProvider.java @@ -11,20 +11,22 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.core.data; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** * Provide data to the table. * - * @see DataLayer * @see ListDataProvider + * @see org.eclipse.statet.ecommons.waltable.data.core.DataLayer */ -public interface IDataProvider { +@NonNullByDefault +public interface DataProvider { int FORCE_SYNC= 1 << 0; @@ -44,17 +46,18 @@ public interface IDataProvider { * @param monitor * @return the data value associated with the specified cell */ - Object getDataValue(long columnIndex, long rowIndex, - int flags, IProgressMonitor monitor); + @Nullable Object getDataValue(long columnIndex, long rowIndex, + int flags, @Nullable IProgressMonitor monitor); /** - * Sets the value at the given column and row index. Optional operation. Should throw UnsupportedOperationException - * if this operation is not supported. + * Sets the value at the given column and row index. Optional operation. + * + * The method throws an UnsupportedOperationException if this operation is not supported. * * @param columnIndex * @param rowIndex * @param newValue */ - void setDataValue(long columnIndex, long rowIndex, Object newValue); + void setDataValue(long columnIndex, long rowIndex, @Nullable Object newValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ListDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ListDataProvider.java index 55875704..cc772c20 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ListDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/ListDataProvider.java @@ -11,35 +11,47 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.core.data; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + /** - * Enables the use of a {@link List} containing POJO(s) as a backing data source. + * Enables the use of a {@link List} containing POJO(s) as a backing data + * source. + * + * <p>By default a bean at position {@code x} in the list is displayed in row + * {@code x} in the table. A {@link ColumnAccessor} is used to retrieve column + * data from the row objects.</p> * - * By default a bean at position 'X' in the list is displayed in - * row 'X' in the table. The properties of the bean are used to - * populate the columns. A {@link IColumnPropertyResolver} is used to - * retrieve column data from the bean properties. + * @param <T> type of the row objects in the backing list. * - * @param <T> type of the Objects in the backing list. - * @see IColumnPropertyResolver + * @see org.eclipse.statet.ecommons.waltable.util.data.PropertyColumnResolver */ -public class ListDataProvider<T> implements IRowDataProvider<T> { +@NonNullByDefault +public class ListDataProvider<T> implements DataProvider { - protected List<T> list; - protected IColumnAccessor<T> columnAccessor; + protected final List<T> list; + protected final ColumnAccessor<T> columnAccessor; - public ListDataProvider(final List<T> list, final IColumnAccessor<T> columnAccessor) { + + public ListDataProvider(final List<T> list, final ColumnAccessor<T> columnAccessor) { this.list= list; this.columnAccessor= columnAccessor; } + + public List<T> getList() { + return this.list; + } + + @Override public long getColumnCount() { return this.columnAccessor.getColumnCount(); @@ -50,25 +62,6 @@ public class ListDataProvider<T> implements IRowDataProvider<T> { return this.list.size(); } - @Override - public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, final IProgressMonitor monitor) { - if (rowIndex >= Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - final T rowObj= this.list.get((int) rowIndex); - return this.columnAccessor.getDataValue(rowObj, columnIndex); - } - - @Override - public void setDataValue(final long columnIndex, final long rowIndex, final Object newValue) { - if (rowIndex >= Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - final T rowObj= this.list.get((int) rowIndex); - this.columnAccessor.setDataValue(rowObj, columnIndex, newValue); - } - - @Override public T getRowObject(final long rowIndex) { if (rowIndex >= Integer.MAX_VALUE) { throw new IndexOutOfBoundsException(); @@ -76,13 +69,22 @@ public class ListDataProvider<T> implements IRowDataProvider<T> { return this.list.get((int) rowIndex); } - @Override public long indexOfRowObject(final T rowObject) { return this.list.indexOf(rowObject); } - public List<T> getList() { - return this.list; + @Override + public @Nullable Object getDataValue(final long columnIndex, final long rowIndex, + final int flags, final @Nullable IProgressMonitor monitor) { + final var rowObject= getRowObject(rowIndex); + return this.columnAccessor.getDataValue(rowObject, columnIndex); + } + + @Override + public void setDataValue(final long columnIndex, final long rowIndex, + final @Nullable Object newValue) { + final var rowObject= getRowObject(rowIndex); + this.columnAccessor.setDataValue(rowObject, columnIndex, newValue); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ISpanningDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/SpanningDataProvider.java index bb49173f..341dbc78 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ISpanningDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/data/SpanningDataProvider.java @@ -11,12 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.core.data; -import org.eclipse.statet.ecommons.waltable.layer.cell.DataCell; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -public interface ISpanningDataProvider extends IDataProvider { +@NonNullByDefault +public interface SpanningDataProvider extends DataProvider { DataCell getCellByPosition(long columnPosition, long rowPosition); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/AbstractLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/AbstractLayer.java new file mode 100644 index 00000000..e3dd8189 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/AbstractLayer.java @@ -0,0 +1,325 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullLateInit; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.statet.jcommons.collections.CopyOnWriteIdentityListSet; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.config.IConfiguration; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.GridLineCellLayerPainter; +import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; + + +/** + * Base layer implementation with common methods for managing listeners and caching, etc. + * + * @param <TLayerDim> the type of the layer dimension + */ +@NonNullByDefault +public abstract class AbstractLayer<TLayerDim extends LayerDim> implements Layer { + + + private TLayerDim hDim= nonNullLateInit(); + private TLayerDim vDim= nonNullLateInit(); + + private @Nullable LayerPainter layerPainter; + private ClientAreaProvider clientAreaProvider= ClientAreaProvider.DEFAULT; + + private final Map<Class<? extends LayerCommand>, LayerCommandHandler<? extends LayerCommand>> commandHandlers= new LinkedHashMap<>(); + private final CopyOnWriteIdentityListSet<LayerListener> eventHandlers= new CopyOnWriteIdentityListSet<>(); + + private final CopyOnWriteIdentityListSet<Persistable> persistables= new CopyOnWriteIdentityListSet<>(); + private final CopyOnWriteIdentityListSet<LayerListener> listeners= new CopyOnWriteIdentityListSet<>(); + + private final Collection<IConfiguration> configurations= new ArrayList<>(); + + + protected AbstractLayer() { + } + + protected AbstractLayer(@Nullable final LayerPainter layerPainter) { + this.layerPainter= layerPainter; + } + + + protected void init() { + this.hDim= createDim(HORIZONTAL); + this.vDim= createDim(VERTICAL); + if (this.hDim.getOrientation() != HORIZONTAL || this.vDim.getOrientation() != VERTICAL) { + throw new RuntimeException("Invalid LayerDim"); + } + } + + // Dims + + protected abstract TLayerDim createDim(Orientation orientation); + + @Override + public TLayerDim getDim(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return this.hDim; + case VERTICAL: + return this.vDim; + default: + throw new IllegalStateException(); + } + } + + + // Dispose + + @Override + public void dispose() { + } + + + // Regions + + @Override + public LabelStack getRegionLabelsByXY(final long x, final long y) { + return new LabelStack(); + } + + // Persistence + + @Override + public void saveState(final String prefix, final Map<String, String> properties) { + for (final Persistable persistable : this.persistables) { + persistable.saveState(prefix, properties); + } + } + + @Override + public void loadState(final String prefix, final Map<String, String> properties) { + for (final Persistable persistable : this.persistables) { + persistable.loadState(prefix, properties); + } + } + + @Override + public void registerPersistable(final Persistable persistable){ + this.persistables.add(persistable); + } + + @Override + public void unregisterPersistable(final Persistable persistable){ + this.persistables.remove(persistable); + } + + // Configuration + + public void addConfiguration(final IConfiguration configuration) { + this.configurations.add(configuration); + } + + public void clearConfiguration() { + this.configurations.clear(); + } + + @Override + public void configure(final ConfigRegistry configRegistry, final UiBindingRegistry uiBindingRegistry) { + for (final IConfiguration configuration : this.configurations) { + configuration.configureLayer(this); + configuration.configureRegistry(configRegistry); + configuration.configureUiBindings(uiBindingRegistry); + } + } + + // Commands + + @Override + @SuppressWarnings("unchecked") + public boolean doCommand(final LayerCommand command) { + for (final var entry : this.commandHandlers.entrySet()) { + if (entry.getKey().isInstance(command)) { + final LayerCommandHandler commandHandler= entry.getValue(); + if (commandHandler.doCommand(this, command.cloneCommand())) { + return true; + } + } + } + + return false; + } + + // Command handlers + + /** + * Layers should use this method to register their command handlers + * and call it from their constructor. This allows easy overriding if + * required of command handlers + */ + protected void registerCommandHandlers() { + // No op + } + + @Override + public void registerCommandHandler(final LayerCommandHandler<?> commandHandler) { + this.commandHandlers.put(commandHandler.getCommandClass(), commandHandler); + } + + @Override + public void unregisterCommandHandler(final Class<? extends LayerCommand> commandClass) { + this.commandHandlers.remove(commandClass); + } + + // Events + + @Override + public void addLayerListener(final LayerListener listener) { + this.listeners.add(listener); + } + + @Override + public void removeLayerListener(final LayerListener listener) { + this.listeners.remove(listener); + } + + /** + * Handle layer event notification. Convert it to your context + * and propagate <i>UP</i>. + * + * If you override this method you <strong>MUST NOT FORGET</strong> to raise + * the event up the layer stack by calling <code>super.fireLayerEvent(event)</code> + * - unless you plan to eat the event yourself. + **/ + @Override + public void handleLayerEvent(final LayerEvent event) { + for (final var handler : this.eventHandlers) { + handler.handleLayerEvent(event); + } + + final var localEvent= event.toLayer(this); + // Pass on the event to our parent + if (localEvent != null) { + fireLayerEvent(localEvent); + } + } + + public void registerEventHandler(final LayerListener eventHandler) { + this.eventHandlers.add(eventHandler); + } + + public void unregisterEventHandler(final LayerListener eventHandler) { + this.eventHandlers.remove(eventHandler); + } + + /** + * Pass the event to all the {@link LayerListener} registered on this layer. + * A cloned copy is passed to each listener. + */ + @Override + public void fireLayerEvent(final LayerEvent event) { + for (final var listener : this.listeners) { + listener.handleLayerEvent(event); + } + } + + /** + * @return {@link LayerPainter}. Defaults to {@link GridLineCellLayerPainter} + */ + @Override + public LayerPainter getLayerPainter() { + var layerPainter= this.layerPainter; + if (layerPainter == null) { + layerPainter= createPainter(); + this.layerPainter= layerPainter; + } + return layerPainter; + } + + protected LayerPainter createPainter() { + return new GridLineCellLayerPainter(); + } + + + // Client area + + @Override + public ClientAreaProvider getClientAreaProvider() { + return this.clientAreaProvider; + } + + @Override + public void setClientAreaProvider(final ClientAreaProvider clientAreaProvider) { + this.clientAreaProvider= clientAreaProvider; + } + + + @Override + public final long getColumnCount() { + return this.hDim.getPositionCount(); + } + + @Override + public final long getWidth() { + return this.hDim.getSize(); + } + + @Override + public final long getColumnPositionByX(final long x) { + try { + return this.hDim.getPositionByPixel(x); + } + catch (final PixelOutOfBoundsException e) { + return Long.MIN_VALUE; + } + } + + + @Override + public final long getRowCount() { + return this.vDim.getPositionCount(); + } + + @Override + public final long getHeight() { + return this.vDim.getSize(); + } + + @Override + public final long getRowPositionByY(final long y) { + try { + return this.vDim.getPositionByPixel(y); + } + catch (final PixelOutOfBoundsException e) { + return Long.MIN_VALUE; + } + } + + + @Override + public String toString() { + return getClass().getSimpleName(); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/AbstractLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/AbstractLayerDim.java index 34a8a214..4a05d282 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/AbstractLayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/AbstractLayerDim.java @@ -12,9 +12,13 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; /** @@ -22,7 +26,8 @@ import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; * * @param <TLayer> the type of the layer */ -public abstract class AbstractLayerDim<TLayer extends ILayer> implements ILayerDim { +@NonNullByDefault +public abstract class AbstractLayerDim<TLayer extends Layer> implements LayerDim { protected final TLayer layer; @@ -30,20 +35,14 @@ public abstract class AbstractLayerDim<TLayer extends ILayer> implements ILayerD protected final Orientation orientation; - public AbstractLayerDim(/*@NonNull*/ final TLayer layer, /*@NonNull*/ final Orientation orientation) { - if (layer == null) { - throw new NullPointerException("layer"); //$NON-NLS-1$ - } - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - this.layer= layer; - this.orientation= orientation; + public AbstractLayerDim(final TLayer layer, final Orientation orientation) { + this.layer= nonNullAssert(layer); + this.orientation= nonNullAssert(orientation); } @Override - public ILayer getLayer() { + public Layer getLayer() { return this.layer; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/LayerCell.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/BasicLayerCell.java index 7ff4a657..3ccf3c65 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/LayerCell.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/BasicLayerCell.java @@ -11,36 +11,37 @@ # Edwin Park - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.data.ControlData; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.data.ControlData; -public class LayerCell implements ILayerCell { + +@NonNullByDefault +public class BasicLayerCell implements LayerCell { private static final ControlData NO_DATA= new ControlData(0, ""); //$NON-NLS-1$ - private final ILayer layer; + private final Layer layer; - private final ILayerCellDim h; - private final ILayerCellDim v; + private final LayerCellDim h; + private final LayerCellDim v; - public LayerCell(final ILayer layer, - final ILayerCellDim horizontalDim, final ILayerCellDim verticalDim) { + public BasicLayerCell(final Layer layer, + final LayerCellDim horizontalDim, final LayerCellDim verticalDim) { this.layer= layer; this.h= horizontalDim; this.v= verticalDim; @@ -48,17 +49,20 @@ public class LayerCell implements ILayerCell { @Override - public final ILayer getLayer() { + public final Layer getLayer() { return this.layer; } @Override - public final ILayerCellDim getDim(final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ + public final LayerCellDim getDim(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return this.h; + case VERTICAL: + return this.v; + default: + throw new IllegalStateException(); } - - return (orientation == HORIZONTAL) ? this.h : this.v; } @@ -104,12 +108,13 @@ public class LayerCell implements ILayerCell { } @Override - public LabelStack getConfigLabels() { + public LabelStack getLabels() { return new LabelStack(); } @Override - public Object getDataValue(final int flags, final IProgressMonitor monitor) { + public @Nullable Object getDataValue(final int flags, + final @Nullable IProgressMonitor monitor) { return NO_DATA; } @@ -120,25 +125,25 @@ public class LayerCell implements ILayerCell { final long yOffset; final long width; final long height; - { final ILayerCellDim dim= getDim(HORIZONTAL); + { final LayerCellDim dim= getDim(HORIZONTAL); final long cellPosition= dim.getPosition(); final long firstPosition= dim.getOriginPosition(); final long lastPosition= firstPosition + dim.getPositionSpan() - 1; - final ILayerDim layerDim= getLayer().getDim(HORIZONTAL); + final LayerDim layerDim= getLayer().getDim(HORIZONTAL); xOffset= layerDim.getPositionStart(cellPosition, firstPosition); width= (firstPosition == lastPosition) ? layerDim.getPositionSize(cellPosition, lastPosition) : layerDim.getPositionStart(cellPosition, lastPosition) - xOffset + layerDim.getPositionSize(cellPosition, lastPosition); } - { final ILayerCellDim dim= getDim(VERTICAL); + { final LayerCellDim dim= getDim(VERTICAL); final long cellPosition= dim.getPosition(); final long firstPosition= dim.getOriginPosition(); final long lastPosition= firstPosition + dim.getPositionSpan() - 1; - final ILayerDim layerDim= getLayer().getDim(VERTICAL); + final LayerDim layerDim= getLayer().getDim(VERTICAL); yOffset= layerDim.getPositionStart(cellPosition, firstPosition); height= (firstPosition == lastPosition) ? layerDim.getPositionSize(cellPosition, lastPosition) : @@ -159,17 +164,17 @@ public class LayerCell implements ILayerCell { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof ILayerCell)) { - return false; + if (obj instanceof LayerCell) { + final LayerCell other= (LayerCell)obj; + return (this.layer.equals(other.getLayer()) + && this.h.equals(other.getDim(HORIZONTAL)) + && this.v.equals(other.getDim(VERTICAL)) ); } - final ILayerCell other= (ILayerCell) obj; - return (this.layer.equals(other.getLayer()) - && this.h.equals(other.getDim(HORIZONTAL)) - && this.v.equals(other.getDim(VERTICAL)) ); + return false; } @Override diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/LayerCellDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/BasicLayerCellDim.java index 90649591..e46d8676 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/LayerCellDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/BasicLayerCellDim.java @@ -12,12 +12,20 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -public class LayerCellDim implements ILayerCellDim { +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; + + +@NonNullByDefault +public class BasicLayerCellDim implements LayerCellDim { private final Orientation orientation; @@ -30,20 +38,17 @@ public class LayerCellDim implements ILayerCellDim { private final long positionSpan; - public LayerCellDim(final Orientation orientation, final long id, + public BasicLayerCellDim(final Orientation orientation, final long id, final long position) { this(orientation, id, position, position, 1); } - public LayerCellDim(final Orientation orientation, final long id, + public BasicLayerCellDim(final Orientation orientation, final long id, final long position, final long originPosition, final long positionSpan) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } if (positionSpan < 0 || position < originPosition || position >= originPosition + positionSpan) { throw new IllegalArgumentException("position: " + position + " [" + originPosition + ", " + (originPosition + positionSpan) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } - this.orientation= orientation; + this.orientation= nonNullAssert(orientation); this.id= id; this.position= position; this.originPosition= originPosition; @@ -80,19 +85,19 @@ public class LayerCellDim implements ILayerCellDim { @Override public final int hashCode() { int h= (int) (this.originPosition ^ (this.originPosition >>> 32)); - if (this.orientation == Orientation.VERTICAL) { + if (this.orientation == VERTICAL) { h= 17 + Integer.rotateRight(h, 15); } return h ^ (h >>> 7); } @Override - public final boolean equals(final Object obj) { + public final boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (obj instanceof LayerCellDim) { - final LayerCellDim other= (LayerCellDim) obj; + if (obj instanceof BasicLayerCellDim) { + final BasicLayerCellDim other= (BasicLayerCellDim)obj; return (this.orientation == other.orientation && this.originPosition == other.originPosition && this.positionSpan == other.positionSpan); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/IClientAreaProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ClientAreaProvider.java index d61d1868..b0b442c3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/IClientAreaProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ClientAreaProvider.java @@ -11,23 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.ui; +package org.eclipse.statet.ecommons.waltable.core.layer; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; /** - * Specifies the rectangular area available to an {@link ILayer} - * Note: All layers get the client area from {@link NatTable} which implements this interface. + * Specifies the rectangular area available to an {@link Layer} + * Note: All layers get the client area from {@link NatTable} which implements this interface. * - * @see ILayer#getClientAreaProvider() + * @see Layer#getClientAreaProvider() */ -public interface IClientAreaProvider { +@NonNullByDefault +public interface ClientAreaProvider { - IClientAreaProvider DEFAULT= new IClientAreaProvider() { + static final ClientAreaProvider DEFAULT= new ClientAreaProvider() { @Override public LRectangle getClientArea() { return new LRectangle(0, 0, 0, 0); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/CompositeLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/CompositeLayer.java index 60ffb367..7fc908df 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/CompositeLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/CompositeLayer.java @@ -11,41 +11,44 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; -import java.util.Properties; +import java.util.Map; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; import org.eclipse.statet.ecommons.waltable.layer.cell.AggregrateConfigLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.IConfigLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.layer.cell.CellLabelContributor; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; /** - * A composite layer is a layer that is made up of a number of underlying child layers. This class assumes that the child - * layers are laid out in a regular grid pattern where the child layers in each composite row all have the same number of - * rows and the same height, and the child layers in each composite column each have the same number of columns and - * the same width. + * A composite layer is a layer that is made up of a number of underlying + * child layers. + * + * <p>This class assumes that the child layers are laid out in a regular grid + * pattern where the child layers in each composite row all have the same + * number of rows and the same height, and the child layers in each composite + * column each have the same number of columns and the same width.</p> */ -public class CompositeLayer extends AbstractLayer { +@NonNullByDefault +public class CompositeLayer extends AbstractLayer<CompositeLayerDim> { protected static final class Child { @@ -55,12 +58,12 @@ public class CompositeLayer extends AbstractLayer { public final String label; - public final ILayer layer; + public final Layer layer; - private IConfigLabelAccumulator configLabelAccumulator; + private CellLabelContributor configLabelAccumulator; - private Child(final int x, final int y, final String label, final ILayer layer) { + private Child(final int x, final int y, final String label, final Layer layer) { this.layoutX= x; this.layoutY= y; this.label= label; @@ -75,43 +78,32 @@ public class CompositeLayer extends AbstractLayer { protected final int layoutYCount; /** Data struct. for child Layers */ - private final Child[][] childLayout; + private final @NonNull Child [] @NonNull [] childLayout; public CompositeLayer(final int layoutXCount, final int layoutYCount) { this.layoutXCount= layoutXCount; this.layoutYCount= layoutYCount; - this.childLayout= new Child[layoutXCount][layoutYCount]; + this.childLayout= new @NonNull Child @NonNull [layoutXCount] @NonNull [layoutYCount]; - initDims(); + init(); } - @Override - protected void initDims() { - if (this.childLayout == null) { - return; - } - - for (final Orientation orientation : Orientation.values()) { - setDim((ignoreRef(orientation)) ? + protected CompositeLayerDim createDim(final Orientation orientation) { + return (ignoreRef(orientation)) ? new CompositeLayerDim.IgnoreRef(this, orientation) : - new CompositeLayerDim(this, orientation) ); - } + new CompositeLayerDim(this, orientation); } protected boolean ignoreRef(final Orientation orientation) { return false; } - final CompositeLayerDim get(final Orientation orientation) { - return (CompositeLayerDim) getDim(orientation); - } - @Override - protected ILayerPainter createPainter() { - return new CompositeLayerPainter(); + protected LayerPainter createPainter() { + return new CompositeLayerPainter(this); } @@ -132,7 +124,7 @@ public class CompositeLayer extends AbstractLayer { // Persistence @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { for (int layoutX= 0; layoutX < this.layoutXCount; layoutX++) { for (int layoutY= 0; layoutY < this.layoutYCount; layoutY++) { final Child child= this.childLayout[layoutX][layoutY]; @@ -145,7 +137,7 @@ public class CompositeLayer extends AbstractLayer { } @Override - public void loadState(final String prefix, final Properties properties) { + public void loadState(final String prefix, final Map<String, String> properties) { for (int layoutX= 0; layoutX < this.layoutXCount; layoutX++) { for (int layoutY= 0; layoutY < this.layoutYCount; layoutY++) { final Child child= this.childLayout[layoutX][layoutY]; @@ -175,14 +167,14 @@ public class CompositeLayer extends AbstractLayer { * Handle commands */ @Override - public boolean doCommand(final ILayerCommand command) { + public boolean doCommand(final LayerCommand command) { if (super.doCommand(command)) { return true; } return doCommandOnChildLayers(command); } - protected boolean doCommandOnChildLayers(final ILayerCommand command) { + protected boolean doCommandOnChildLayers(final LayerCommand command) { for (int layoutX= 0; layoutX < this.layoutXCount; layoutX++) { for (int layoutY= 0; layoutY < this.layoutYCount; layoutY++) { if (this.childLayout[layoutX][layoutY].layer.doCommand(command)) { @@ -196,29 +188,29 @@ public class CompositeLayer extends AbstractLayer { // Cell features @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { final Child child= getChildByPosition(columnPosition, rowPosition); if (child == null) { throw new PositionOutOfBoundsException(columnPosition + ", " + rowPosition); //$NON-NLS-1$ } - final long childColumnPosition= columnPosition - get(HORIZONTAL).getLayoutPosition(child.layoutX); - final long childRowPosition= rowPosition - get(VERTICAL).getLayoutPosition(child.layoutY); + final long childColumnPosition= columnPosition - getDim(HORIZONTAL).getLayoutPosition(child.layoutX); + final long childRowPosition= rowPosition - getDim(VERTICAL).getLayoutPosition(child.layoutY); - final ILayerCell underlyingCell= child.layer.getCellByPosition(childColumnPosition, childRowPosition); + final LayerCell underlyingCell= child.layer.getCellByPosition(childColumnPosition, childRowPosition); - final ILayerCellDim hDim= transformCellDim(underlyingCell.getDim(HORIZONTAL), columnPosition); - final ILayerCellDim vDim= transformCellDim(underlyingCell.getDim(VERTICAL), rowPosition); + final LayerCellDim hDim= transformCellDim(underlyingCell.getDim(HORIZONTAL), columnPosition); + final LayerCellDim vDim= transformCellDim(underlyingCell.getDim(VERTICAL), rowPosition); return new ForwardLayerCell(this, hDim, vDim, underlyingCell) { @Override - public LabelStack getConfigLabels() { - final LabelStack configLabels= super.getConfigLabels(); + public LabelStack getLabels() { + final LabelStack configLabels= super.getLabels(); if (child.configLabelAccumulator != null) { - child.configLabelAccumulator.accumulateConfigLabels(configLabels, childColumnPosition, childRowPosition); + child.configLabelAccumulator.addLabels(configLabels, childColumnPosition, childRowPosition); } configLabels.addLabel(child.label); @@ -229,31 +221,27 @@ public class CompositeLayer extends AbstractLayer { }; } - protected ILayerCellDim transformCellDim(final ILayerCellDim underlyingDim, final long position) { + protected LayerCellDim transformCellDim(final LayerCellDim underlyingDim, final long position) { final long originPosition= (underlyingDim.getPosition() == underlyingDim.getOriginPosition()) ? position : - get(underlyingDim.getOrientation()).underlyingToLocalPosition( + getDim(underlyingDim.getOrientation()).underlyingToLocalPosition( position, underlyingDim.getOriginPosition() ); - return new LayerCellDim(underlyingDim.getOrientation(), underlyingDim.getId(), + return new BasicLayerCellDim(underlyingDim.getOrientation(), underlyingDim.getId(), position, originPosition, underlyingDim.getPositionSpan() ); } // Child layer stuff - public void setChildLayer(final String label, final ILayer childLayer, final int layoutX, final int layoutY) { - if (childLayer == null) { - throw new IllegalArgumentException("Cannot set null child layer"); //$NON-NLS-1$ - } - - final Child child= new Child(layoutX, layoutY, label, childLayer); + public void setChildLayer(final String label, final Layer childLayer, final int layoutX, final int layoutY) { + final Child child= new Child(layoutX, layoutY, label, nonNullAssert(childLayer)); childLayer.addLayerListener(this); this.childLayout[layoutX][layoutY]= child; - get(HORIZONTAL).updateChild(layoutX, layoutY, childLayer); - get(VERTICAL).updateChild(layoutY, layoutX, childLayer); + getDim(HORIZONTAL).setChild(layoutX, layoutY, childLayer); + getDim(VERTICAL).setChild(layoutY, layoutX, childLayer); - childLayer.setClientAreaProvider(new IClientAreaProvider() { + childLayer.setClientAreaProvider(new ClientAreaProvider() { @Override public LRectangle getClientArea() { return getChildClientArea(child); @@ -264,10 +252,10 @@ public class CompositeLayer extends AbstractLayer { /** * Adds the configLabelAccumulator to the existing label accumulators. */ - public void addConfigLabelAccumulatorForRegion(final String regionLabel, final IConfigLabelAccumulator configLabelAccumulator) { + public void addCellLabelContributor(final String regionLabel, final CellLabelContributor labelContributor) { final Child child= getChildByLabel(regionLabel); if (child.configLabelAccumulator == null) { - child.configLabelAccumulator= configLabelAccumulator; + child.configLabelAccumulator= labelContributor; } else { final AggregrateConfigLabelAccumulator aggregateAccumulator; @@ -279,7 +267,7 @@ public class CompositeLayer extends AbstractLayer { aggregateAccumulator.add(child.configLabelAccumulator); child.configLabelAccumulator= aggregateAccumulator; } - aggregateAccumulator.add(configLabelAccumulator); + aggregateAccumulator.add(labelContributor); } } @@ -287,8 +275,8 @@ public class CompositeLayer extends AbstractLayer { final LRectangle compositeClientArea= getClientAreaProvider().getClientArea(); final LRectangle childClientArea= new LRectangle( - compositeClientArea.x + get(HORIZONTAL).getLayoutStart(child.layoutX), - compositeClientArea.y + get(VERTICAL).getLayoutStart(child.layoutY), + compositeClientArea.x + getDim(HORIZONTAL).getLayoutStart(child.layoutX), + compositeClientArea.y + getDim(VERTICAL).getLayoutStart(child.layoutY), child.layer.getDim(HORIZONTAL).getPreferredSize(), child.layer.getDim(VERTICAL).getPreferredSize() ); @@ -302,7 +290,7 @@ public class CompositeLayer extends AbstractLayer { * @param layoutY row position in the CompositeLayer * @return child layer according to the Composite Layer Layout */ - public ILayer getChildLayerByLayoutCoordinate(final int layoutX, final int layoutY) { + public @Nullable Layer getChildLayerByLayoutCoordinate(final int layoutX, final int layoutY) { if (layoutX < 0 || layoutX >= this.layoutXCount || layoutY < 0 || layoutY >= this.layoutYCount) { return null; } @@ -323,8 +311,8 @@ public class CompositeLayer extends AbstractLayer { return null; } - final long childX= x - get(HORIZONTAL).getLayoutStart(child.layoutX); - final long childY= y - get(VERTICAL).getLayoutStart(child.layoutY); + final long childX= x - getDim(HORIZONTAL).getLayoutStart(child.layoutX); + final long childY= y - getDim(VERTICAL).getLayoutStart(child.layoutY); final LabelStack regionLabels= child.layer.getRegionLabelsByXY(childX, childY); regionLabels.addLabel(child.label); @@ -333,14 +321,14 @@ public class CompositeLayer extends AbstractLayer { } @Override - public ILayer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { + public @Nullable Layer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { final Child child= getChildByPosition(columnPosition, rowPosition); return (child != null) ? child.layer : null; } // Layout coordinate accessors - protected final Child getChildByLabel(final String label) { + protected final @Nullable Child getChildByLabel(final String label) { for (int layoutX= 0; layoutX < this.layoutXCount; layoutX++) { for (int layoutY= 0; layoutY < this.layoutYCount; layoutY++) { if (label.equals(this.childLayout[layoutX][layoutY].label)) { @@ -351,7 +339,7 @@ public class CompositeLayer extends AbstractLayer { return null; } - protected final Child getChildByLayer(final ILayer childLayer) { + protected final @Nullable Child getChildByLayer(final Layer childLayer) { for (int layoutX= 0; layoutX < this.layoutXCount; layoutX++) { for (int layoutY= 0; layoutY < this.layoutYCount; layoutY++) { if (this.childLayout[layoutX][layoutY].layer == childLayer) { @@ -362,24 +350,24 @@ public class CompositeLayer extends AbstractLayer { return null; } - protected final Child getChildByPixelXY(final long x, final long y) { - final int layoutX= get(HORIZONTAL).getLayoutByPixel(x); + protected final @Nullable Child getChildByPixelXY(final long x, final long y) { + final int layoutX= getDim(HORIZONTAL).getLayoutByPixel(x); if (layoutX < 0) { return null; } - final int layoutY= get(VERTICAL).getLayoutByPixel(y); + final int layoutY= getDim(VERTICAL).getLayoutByPixel(y); if (layoutY < 0) { return null; } return this.childLayout[layoutX][layoutY]; } - protected final Child getChildByPosition(final long compositeColumnPosition, final long compositeRowPosition) { - final int layoutX= get(HORIZONTAL).getLayoutByPosition(compositeColumnPosition); + protected final @Nullable Child getChildByPosition(final long compositeColumnPosition, final long compositeRowPosition) { + final int layoutX= getDim(HORIZONTAL).getLayoutByPosition(compositeColumnPosition); if (layoutX < 0) { return null; } - final int layoutY= get(VERTICAL).getLayoutByPosition(compositeRowPosition); + final int layoutY= getDim(VERTICAL).getLayoutByPosition(compositeRowPosition); if (layoutY < 0) { return null; } @@ -387,62 +375,76 @@ public class CompositeLayer extends AbstractLayer { } - protected class CompositeLayerPainter implements ILayerPainter { + public static class CompositeLayerPainter implements LayerPainter { + + + protected final CompositeLayer layer; + + + public CompositeLayerPainter(final CompositeLayer layer) { + this.layer= layer; + } + @Override - public void paintLayer(final ILayer natLayer, final GC gc, + public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, + final LRectangle cellBounds) { + final Child child= this.layer.getChildByPosition(columnPosition, rowPosition); + final var hDim= this.layer.getDim(HORIZONTAL); + final var vDim= this.layer.getDim(VERTICAL); + + final long widthOffset= hDim.getLayoutStart(child.layoutX); + final long heightOffset= vDim.getLayoutStart(child.layoutY); + +// LRectangle bounds= new LRectangle(cellBounds.x - widthOffset, cellBounds.y - heightOffset, cellBounds.width, cellBounds.height); + cellBounds.x-= widthOffset; + cellBounds.y-= heightOffset; + + final var childLayerPainter= child.layer.getLayerPainter(); + final long childColumnPosition= columnPosition - hDim.getLayoutPosition(child.layoutX); + final long childRowPosition= rowPosition - vDim.getLayoutPosition(child.layoutY); + final LRectangle adjustedChildCellBounds= childLayerPainter.adjustCellBounds(childColumnPosition, childRowPosition, cellBounds); +// LRectangle adjustedChildCellBounds= childLayerPainter.adjustCellBounds(childColumnPosition, childRowPosition, bounds); + + adjustedChildCellBounds.x+= widthOffset; + adjustedChildCellBounds.y+= heightOffset; + + return adjustedChildCellBounds; + } + + @Override + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, final Rectangle pixelRectangle, - final IConfigRegistry configuration) { + final ConfigRegistry configuration) { int x= xOffset; - for (int layoutX= 0; layoutX < CompositeLayer.this.layoutXCount; layoutX++) { + for (int layoutX= 0; layoutX < this.layer.layoutXCount; layoutX++) { int y= yOffset; - final int width= safe(CompositeLayer.this.childLayout[layoutX][0].layer.getWidth()); - for (int layoutY= 0; layoutY < CompositeLayer.this.layoutYCount; layoutY++) { - final Child child= CompositeLayer.this.childLayout[layoutX][layoutY]; + final @NonNull Child[] layoutXChilds= this.layer.childLayout[layoutX]; + final int width= safe(layoutXChilds[0].layer.getWidth()); + for (int layoutY= 0; layoutY < this.layer.layoutYCount; layoutY++) { + final Child child= layoutXChilds[layoutY]; + final int height= safe(child.layer.getHeight()); - final Rectangle childRectangle= new Rectangle(x, y, width, safe(child.layer.getHeight()) ); + final Rectangle childRectangle= new Rectangle(x, y, width, height); final Rectangle childPaintRectangle= pixelRectangle.intersection(childRectangle); if (!childPaintRectangle.isEmpty()) { final Rectangle originalClipping= gc.getClipping(); gc.setClipping(childPaintRectangle); - child.layer.getLayerPainter().paintLayer(natLayer, gc, - x, y, childPaintRectangle, configuration ); + final var layerPainter= child.layer.getLayerPainter(); + layerPainter.paintLayer(natLayer, gc, x, y, childPaintRectangle, configuration); gc.setClipping(originalClipping); } - y+= childRectangle.height; + y+= height; } x+= width; } } - @Override - public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, final LRectangle cellBounds) { - final Child child= getChildByPosition(columnPosition, rowPosition); - - final long widthOffset= get(HORIZONTAL).getLayoutStart(child.layoutX); - final long heightOffset= get(VERTICAL).getLayoutStart(child.layoutY); - -// LRectangle bounds= new LRectangle(cellBounds.x - widthOffset, cellBounds.y - heightOffset, cellBounds.width, cellBounds.height); - cellBounds.x-= widthOffset; - cellBounds.y-= heightOffset; - - final ILayerPainter childLayerPainter= child.layer.getLayerPainter(); - final long childColumnPosition= columnPosition - get(HORIZONTAL).getLayoutPosition(child.layoutX); - final long childRowPosition= rowPosition - get(VERTICAL).getLayoutPosition(child.layoutY); - final LRectangle adjustedChildCellBounds= childLayerPainter.adjustCellBounds(childColumnPosition, childRowPosition, cellBounds); -// LRectangle adjustedChildCellBounds= childLayerPainter.adjustCellBounds(childColumnPosition, childRowPosition, bounds); - - adjustedChildCellBounds.x+= widthOffset; - adjustedChildCellBounds.y+= heightOffset; - - return adjustedChildCellBounds; - } - } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/CompositeLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/CompositeLayerDim.java index cff68c25..74e6d770 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/CompositeLayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/CompositeLayerDim.java @@ -12,20 +12,27 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PixelOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; + +@NonNullByDefault public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { @@ -62,15 +69,15 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { } - private final ILayerDim[][] childDims; + private final @NonNull LayerDim [] @NonNull [] childDims; public CompositeLayerDim(final CompositeLayer layer, final Orientation orientation) { super(layer, orientation); this.childDims= (orientation == HORIZONTAL) ? - new ILayerDim[layer.layoutXCount][layer.layoutYCount] : - new ILayerDim[layer.layoutYCount][layer.layoutXCount]; + new @NonNull LayerDim @NonNull [layer.layoutXCount] @NonNull [layer.layoutYCount] : + new @NonNull LayerDim @NonNull [layer.layoutYCount] @NonNull [layer.layoutXCount]; } @@ -80,7 +87,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { } - void updateChild(final int layout, final int layout2, final ILayer childLayer) { + void setChild(final int layout, final int layout2, final Layer childLayer) { this.childDims[layout][layout2]= childLayer.getDim(this.orientation); } @@ -108,9 +115,9 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { return -1; } - protected final int getLayoutByDim(final ILayerDim childDim) { + protected final int getLayoutByDim(final LayerDim childDim) { for (int layout= 0; layout < this.childDims.length; layout++) { - final ILayerDim[] layoutDims= this.childDims[layout]; + final LayerDim[] layoutDims= this.childDims[layout]; for (int layout2= 0; layout2 < layoutDims.length; layout2++) { if (layoutDims[layout2] == childDim) { return layout; @@ -195,7 +202,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { } @Override - public long underlyingToLocalPosition(final ILayerDim sourceUnderlyingDim, + public long underlyingToLocalPosition(final LayerDim sourceUnderlyingDim, final long underlyingPosition) { final int layout= getLayoutByDim(sourceUnderlyingDim); if (layout < 0) { @@ -207,7 +214,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { } @Override - public List<LRange> underlyingToLocalPositions(final ILayerDim sourceUnderlyingDim, + public List<LRange> underlyingToLocalPositions(final LayerDim sourceUnderlyingDim, final Collection<LRange> underlyingPositionRanges) { final int layout= getLayoutByDim(sourceUnderlyingDim); if (layout < 0) { @@ -227,20 +234,13 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { } @Override - public List<ILayerDim> getUnderlyingDimsByPosition(final long position) { + public @Nullable ImList<LayerDim> getUnderlyingDimsByPosition(final long position) { final int layout= getLayoutByPosition(position); if (layout < 0) { return null; } - final List<ILayerDim> underlyingDims= new ArrayList<>(this.childDims.length); - - final ILayerDim[] layoutDims= this.childDims[layout]; - for (int layout2= 0; layout2 < layoutDims.length; layout2++) { - underlyingDims.add(layoutDims[layout2]); - } - - return underlyingDims; + return ImCollections.newList(this.childDims[layout]); } @@ -266,7 +266,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { public long getPositionByPixel(final long pixel) { final int layout= getLayoutByPixel(pixel); if (layout < 0) { - throw PixelOutOfBoundsException.pixel(pixel, getOrientation()); + throw new PixelOutOfBoundsException(pixel, getOrientation()); } final long childPosition= this.childDims[layout][0].getPositionByPixel( @@ -290,7 +290,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { public long getPositionStart(final long position) { final int layout= getLayoutByPosition(position); if (layout < 0) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } final long layoutPosition= getLayoutPosition(layout); @@ -314,7 +314,7 @@ public class CompositeLayerDim extends AbstractLayerDim<CompositeLayer> { public int getPositionSize(final long position) { final int layout= getLayoutByPosition(position); if (layout < 0) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } final long layoutPosition= getLayoutPosition(layout); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayer.java new file mode 100644 index 00000000..ad813a22 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayer.java @@ -0,0 +1,154 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.Map; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralChangeEvent; +import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; + + +@NonNullByDefault +public abstract class ForwardLayer<TLayerDim extends ForwardLayerDim<? extends ForwardLayer<TLayerDim>>> + extends AbstractLayer<TLayerDim> { + + + private final Layer underlyingLayer; + + + public ForwardLayer(final Layer underlyingLayer, + final @Nullable LayerPainter layerPainter) { + super(layerPainter); + this.underlyingLayer= nonNullAssert(underlyingLayer); + this.underlyingLayer.setClientAreaProvider(getClientAreaProvider()); + this.underlyingLayer.addLayerListener(this); + } + + public ForwardLayer(final Layer underlyingLayer) { + this(underlyingLayer, null); + } + + + protected final Layer getUnderlyingLayer() { + return this.underlyingLayer; + } + + // Dispose + + @Override + public void dispose() { + this.underlyingLayer.dispose(); + } + + // Persistence + + @Override + public void saveState(final String prefix, final Map<String, String> properties) { + this.underlyingLayer.saveState(prefix, properties); + super.saveState(prefix, properties); + } + + /** + * Underlying layers <i>must</i> load state first. + * If this is not done, {@link StructuralChangeEvent} from underlying + * layers will reset caches after state has been loaded + */ + @Override + public void loadState(final String prefix, final Map<String, String> properties) { + this.underlyingLayer.loadState(prefix, properties); + super.loadState(prefix, properties); + } + + // Configuration + + @Override + public void configure(final ConfigRegistry configRegistry, final UiBindingRegistry uiBindingRegistry) { + this.underlyingLayer.configure(configRegistry, uiBindingRegistry); + super.configure(configRegistry, uiBindingRegistry); + } + + @Override + public LayerPainter getLayerPainter() { + final var layerPainter= super.getLayerPainter(); + return (layerPainter != null) ? layerPainter : this.underlyingLayer.getLayerPainter(); + } + + @Override + @SuppressWarnings("null") + protected LayerPainter createPainter() { + return null; + } + + + // Command + + @Override + public boolean doCommand(final LayerCommand command) { + if (super.doCommand(command)) { + return true; + } + + return this.underlyingLayer.doCommand(command); + } + + // Client area + + @Override + public void setClientAreaProvider(final ClientAreaProvider clientAreaProvider) { + super.setClientAreaProvider(clientAreaProvider); + this.underlyingLayer.setClientAreaProvider(clientAreaProvider); + } + + + // Cell features + + @Override + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerCell underlyingCell= this.underlyingLayer.getCellByPosition( + columnPosition, rowPosition ); + + return createCell( + underlyingCell.getDim(HORIZONTAL), + underlyingCell.getDim(VERTICAL), + underlyingCell ); + } + + protected LayerCell createCell(final LayerCellDim hDim, final LayerCellDim vDim, + final LayerCell underlyingCell) { + return new ForwardLayerCell(this, hDim, vDim, underlyingCell); + } + + // IRegionResolver + + @Override + public LabelStack getRegionLabelsByXY(final long x, final long y) { + return this.underlyingLayer.getRegionLabelsByXY(x, y); + } + + @Override + public Layer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { + return this.underlyingLayer; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ForwardLayerCell.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayerCell.java index 9ec6e7b7..3bc4934b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ForwardLayerCell.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayerCell.java @@ -11,31 +11,35 @@ # Edwin Park - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; -public class ForwardLayerCell extends LayerCell { +@NonNullByDefault +public class ForwardLayerCell extends BasicLayerCell { - private final ILayerCell underlyingCell; + private final LayerCell underlyingCell; - public ForwardLayerCell(final ILayer layer, - final ILayerCellDim horizontalDim, final ILayerCellDim verticalDim, - final ILayerCell underlyingCell) { + public ForwardLayerCell(final Layer layer, + final LayerCellDim horizontalDim, final LayerCellDim verticalDim, + final LayerCell underlyingCell) { super(layer, horizontalDim, verticalDim); - this.underlyingCell= underlyingCell; + this.underlyingCell= nonNullAssert(underlyingCell); } - public ILayerCell getUnderlyingCell() { + public LayerCell getUnderlyingCell() { return this.underlyingCell; } @@ -45,13 +49,14 @@ public class ForwardLayerCell extends LayerCell { } @Override - public LabelStack getConfigLabels() { - return this.underlyingCell.getConfigLabels(); + public LabelStack getLabels() { + return this.underlyingCell.getLabels(); } @Override - public Object getDataValue(final int flags, final IProgressMonitor monitor) { + public @Nullable Object getDataValue(final int flags, + final @Nullable IProgressMonitor monitor) { return this.underlyingCell.getDataValue(flags, monitor); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ForwardLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayerDim.java index a0717429..8dbadc51 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ForwardLayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/ForwardLayerDim.java @@ -12,39 +12,42 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; /** - * Dim implementation for {@link TransformLayer}. + * A layer dimension for a {@link ForwardLayer}. * - * @param <T> the type of the layer + * @param <TLayer> the type of the layer */ -public class ForwardLayerDim<T extends ILayer> extends AbstractLayerDim<T> { +@NonNullByDefault +public class ForwardLayerDim<TLayer extends Layer> extends AbstractLayerDim<TLayer> { - protected final ILayerDim underlyingDim; + protected final LayerDim underlyingDim; - public ForwardLayerDim(/*@NonNull*/ final T layer, /*@NonNull*/ final ILayerDim underlyingDim) { + public ForwardLayerDim(final TLayer layer, final LayerDim underlyingDim) { this(layer, underlyingDim.getOrientation(), underlyingDim); } - public ForwardLayerDim(/*@NonNull*/ final T layer, /*@NonNull*/ final Orientation orientation, - /*@NonNull*/ final ILayerDim underlyingDim) { + public ForwardLayerDim(final TLayer layer, final Orientation orientation, + final LayerDim underlyingDim) { super(layer, orientation); - if (underlyingDim == null) { - throw new NullPointerException("underlyingDim"); //$NON-NLS-1$ - } - this.underlyingDim= underlyingDim; + this.underlyingDim= nonNullAssert(underlyingDim); } @@ -70,7 +73,7 @@ public class ForwardLayerDim<T extends ILayer> extends AbstractLayerDim<T> { } @Override - public long underlyingToLocalPosition(final ILayerDim sourceUnderlyingDim, + public long underlyingToLocalPosition(final LayerDim sourceUnderlyingDim, final long underlyingPosition) { if (sourceUnderlyingDim != this.underlyingDim) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -80,7 +83,7 @@ public class ForwardLayerDim<T extends ILayer> extends AbstractLayerDim<T> { } @Override - public List<LRange> underlyingToLocalPositions(final ILayerDim sourceUnderlyingDim, + public List<LRange> underlyingToLocalPositions(final LayerDim sourceUnderlyingDim, final Collection<LRange> underlyingPositions) { if (sourceUnderlyingDim != this.underlyingDim) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -90,8 +93,8 @@ public class ForwardLayerDim<T extends ILayer> extends AbstractLayerDim<T> { } @Override - public List<ILayerDim> getUnderlyingDimsByPosition(final long position) { - return Collections.singletonList(this.underlyingDim); + public ImList<LayerDim> getUnderlyingDimsByPosition(final long position) { + return ImCollections.newList(this.underlyingDim); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/LabelStack.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LabelStack.java index 04711751..8dbf29ea 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/LabelStack.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LabelStack.java @@ -11,12 +11,16 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; import java.util.ArrayList; import java.util.List; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +@NonNullByDefault public class LabelStack { @@ -30,12 +34,6 @@ public class LabelStack { this.labels.add(label); } - public LabelStack(final String... labels) { - for (final String label : labels) { - this.labels.add(label); - } - } - /** * Adds a label to the bottom of the label stack. @@ -82,15 +80,15 @@ public class LabelStack { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof LabelStack)) { - return false; + if (obj instanceof LabelStack) { + final LabelStack other= (LabelStack)obj; + return this.labels.equals(other.labels); } - final LabelStack other= (LabelStack) obj; - return this.labels.equals(other.labels); + return false; } @Override diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/Layer.java index b6a2b709..d75c0000 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/Layer.java @@ -11,21 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; import java.util.Properties; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.IVisualChangeEvent; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.events.VisualChangeEvent; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; @@ -69,10 +68,9 @@ import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; * <tr><td>corner</td><td>column header</td></tr> * <tr><td>row header</td><td>body</td></tr> * </table> - * - * @see CompositeLayer */ -public interface ILayer extends ILayerListener, IPersistable { +@NonNullByDefault +public interface Layer extends LayerListener, Persistable { // Dispose @@ -87,7 +85,7 @@ public interface ILayer extends ILayerListener, IPersistable { * * @return the layer dimension */ - ILayerDim getDim(/*@NonNull*/ Orientation orientation); + LayerDim getDim(Orientation orientation); // Persistence @@ -97,9 +95,9 @@ public interface ILayer extends ILayerListener, IPersistable { * {@link Properties} instance when the layer is persisted. * @param persistable the persistable to be registered */ - void registerPersistable(IPersistable persistable); + void registerPersistable(Persistable persistable); - void unregisterPersistable(IPersistable persistable); + void unregisterPersistable(Persistable persistable); // Configuration @@ -130,17 +128,14 @@ public interface ILayer extends ILayerListener, IPersistable { * is not interested in the command it should allow the command to keep traveling * down the stack. * - * Note: Before the layer can process a command it <i>must</i> convert the - * command to its local co-ordinates using {@link ILayerCommand#convertToTargetLayer(ILayer)} - * * @param command the command to perform * @return true if the command has been handled, false otherwise */ - boolean doCommand(ILayerCommand command); + boolean doCommand(LayerCommand command); - void registerCommandHandler(ILayerCommandHandler<?> commandHandler); + void registerCommandHandler(LayerCommandHandler<?> commandHandler); - void unregisterCommandHandler(Class<? extends ILayerCommand> commandClass); + void unregisterCommandHandler(Class<? extends LayerCommand> commandClass); // Events @@ -148,26 +143,25 @@ public interface ILayer extends ILayerListener, IPersistable { * Events can be fired to notify other components of the grid. * Events travel <i>up</i> the layer stack and may cause a repaint. * <p> - * Example: When the contents of the grid change {@link IVisualChangeEvent} can be + * Example: When the contents of the grid change {@link VisualChangeEvent} can be * fired to notify other layers to refresh their caches etc. * * @param event the event to fire */ - void fireLayerEvent(ILayerEvent event); + void fireLayerEvent(LayerEvent event); - void addLayerListener(ILayerListener listener); + void addLayerListener(LayerListener listener); - void removeLayerListener(ILayerListener listener); + void removeLayerListener(LayerListener listener); - ILayerPainter getLayerPainter(); + LayerPainter getLayerPainter(); // Client area - IClientAreaProvider getClientAreaProvider(); + ClientAreaProvider getClientAreaProvider(); - void setClientAreaProvider(IClientAreaProvider clientAreaProvider); + void setClientAreaProvider(ClientAreaProvider clientAreaProvider); - // Horizontal features // Columns @@ -185,9 +179,6 @@ public interface ILayer extends ILayerListener, IPersistable { long getColumnPositionByX(long x); - // X - - // Vertical features // Rows @@ -205,12 +196,11 @@ public interface ILayer extends ILayerListener, IPersistable { long getRowPositionByY(long y); - // Y - // Cell features + // Cells - ILayerCell getCellByPosition(long columnPosition, long rowPosition); + LayerCell getCellByPosition(long columnPosition, long rowPosition); - ILayer getUnderlyingLayerByPosition(long columnPosition, long rowPosition); + @Nullable Layer getUnderlyingLayerByPosition(long columnPosition, long rowPosition); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ILayerCell.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCell.java index c27be959..9ae151c5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ILayerCell.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCell.java @@ -11,23 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; -public interface ILayerCell { + +@NonNullByDefault +public interface LayerCell { - ILayer getLayer(); + Layer getLayer(); - ILayerCellDim getDim(Orientation orientation); + LayerCellDim getDim(Orientation orientation); long getOriginColumnPosition(); @@ -49,9 +51,9 @@ public interface ILayerCell { LRectangle getBounds(); - LabelStack getConfigLabels(); + LabelStack getLabels(); - Object getDataValue(int flags, IProgressMonitor monitor); + @Nullable Object getDataValue(int flags, @Nullable IProgressMonitor monitor); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ILayerCellDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCellDim.java index 12006040..28dac820 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ILayerCellDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCellDim.java @@ -12,12 +12,15 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; -public interface ILayerCellDim { + +@NonNullByDefault +public interface LayerCellDim { Orientation getOrientation(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ICellPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCellPainter.java index 1c2db90f..6ae06979 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ICellPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerCellPainter.java @@ -11,27 +11,27 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.cell; +package org.eclipse.statet.ecommons.waltable.core.layer; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.painter.cell.PercentageBarCellPainter; /** * Implementations are responsible for painting a cell. * - * Custom {@link ICellPainter} can be registered in the {@link IConfigRegistry}. + * Custom {@link LayerCellPainter} can be registered in the {@link ConfigRegistry}. * This is a mechanism for plugging in custom cell painting. * * @see PercentageBarCellPainter */ -public interface ICellPainter { +public interface LayerCellPainter { - void paintCell(ILayerCell cell, GC gc, LRectangle bounds, IConfigRegistry configRegistry); + void paintCell(LayerCell cell, GC gc, LRectangle bounds, ConfigRegistry configRegistry); /** * Get the preferred width of the cell when rendered by this painter. Used for auto-resize. @@ -40,7 +40,7 @@ public interface ICellPainter { * @param configRegistry * @return */ - long getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry); + long getPreferredWidth(LayerCell cell, GC gc, ConfigRegistry configRegistry); /** * Get the preferred height of the cell when rendered by this painter. Used for auto-resize. @@ -49,9 +49,10 @@ public interface ICellPainter { * @param configRegistry * @return */ - long getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry); + long getPreferredHeight(LayerCell cell, GC gc, ConfigRegistry configRegistry); - ICellPainter getCellPainterAt(long x, long y, ILayerCell cell, GC gc, - LRectangle adjustedCellBounds, IConfigRegistry configRegistrys); + + LayerCellPainter getCellPainterAt(long x, long y, LayerCell cell, GC gc, + LRectangle adjustedCellBounds, ConfigRegistry configRegistrys); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerDim.java index 3cb4ed55..d345a2b5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerDim.java @@ -12,22 +12,27 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; import java.util.Collection; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; /** - * This interface for layers allows to write code which is independent of the orientation - * (horizontal= columns / vertical= rows). + * A LayerDim represents one dimension (horizontal= columns / vertical= rows) of a layer. + * This allows to write code which is independent of the orientation. * * It is recommend that implementation extends {@link AbstractLayerDim}. */ -public interface ILayerDim { +@NonNullByDefault +public interface LayerDim { long POSITION_NA= Long.MIN_VALUE; @@ -38,7 +43,7 @@ public interface ILayerDim { * * @return the layer */ - ILayer getLayer(); + Layer getLayer(); /** * Returns the orientation of this dimension. @@ -74,8 +79,8 @@ public interface ILayerDim { /** * Returns the number of positions in this layer dimension. * - * {@link ILayer#getColumnCount()} / - * {@link ILayer#getRowCount()} + * {@link Layer#getColumnCount()} / + * {@link Layer#getRowCount()} * * @return the count of local positions */ @@ -101,21 +106,21 @@ public interface ILayerDim { * * @return the local position */ - long underlyingToLocalPosition(ILayerDim sourceUnderlyingDim, long underlyingPosition); + long underlyingToLocalPosition(LayerDim sourceUnderlyingDim, long underlyingPosition); /** * Converts the specified positions in the specified underlying layer to the position in this * layer dimension. * - * {@link ILayer#underlyingToLocalColumnPositions(ILayer, Collection)} / - * {@link ILayer#underlyingToLocalRowPositions(ILayer, Collection)} + * {@link Layer#underlyingToLocalColumnPositions(Layer, Collection)} / + * {@link Layer#underlyingToLocalRowPositions(Layer, Collection)} * * @param sourceUnderlyingDim the underlying layer dimension the positions refers to * @param underlyingPositions the positions in the underlying layer * * @return the local positions */ - List<LRange> underlyingToLocalPositions(ILayerDim sourceUnderlyingDim, + List<LRange> underlyingToLocalPositions(LayerDim sourceUnderlyingDim, Collection<LRange> underlyingPositions); /** @@ -125,7 +130,7 @@ public interface ILayerDim { * * @return the underlying layer dimensions */ - List<ILayerDim> getUnderlyingDimsByPosition(long position); + @Nullable ImList<LayerDim> getUnderlyingDimsByPosition(long position); // Pixel= X / Y, Width / Height @@ -133,8 +138,8 @@ public interface ILayerDim { /** * Returns the size of this layer dimension. * - * {@link ILayer#getWidth()} / - * {@link ILayer#getHeight()} + * {@link Layer#getWidth()} / + * {@link Layer#getHeight()} * * @return the size in pixel */ @@ -150,8 +155,8 @@ public interface ILayerDim { /** * Returns the position in this layer dimension for the specified pixel coordinate. * - * {@link ILayer#getColumnPositionByX(int)} / - * {@link ILayer#getRowPositionByY(int)} + * {@link Layer#getColumnPositionByX(int)} / + * {@link Layer#getRowPositionByY(int)} * * @param pixel the pixel coordinate * diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerEvent.java new file mode 100644 index 00000000..72bfc043 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerEvent.java @@ -0,0 +1,36 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; + + +/** + * A event fired by the {@link LayerCommandHandler} classes (usually to signal + * to handling of a {@link LayerCommand}). + * + * <p>Layers can react to an event in {@link Layer#handleLayerEvent(LayerEvent)}, + * other can listen to events by adding a {@link LayerListener} to a layer.</p> + */ +@NonNullByDefault +public interface LayerEvent { + + + @Nullable LayerEvent toLayer(Layer targetLayer); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayerListener.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerListener.java index 40ce6f34..9d84fa3f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ILayerListener.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerListener.java @@ -11,21 +11,22 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** - * Object interested in receiving events related to a {@link ILayer}. + * Object interested in receiving events related to a {@link Layer}. */ -public interface ILayerListener { +@NonNullByDefault +public interface LayerListener { /** - * Handle an event notification from an {@link ILayer} + * Handle an event notification from an {@link Layer} * @param event the event */ - public void handleLayerEvent(ILayerEvent event); + void handleLayerEvent(LayerEvent event); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/ILayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerPainter.java index 291d2dc1..e1573bd0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/ILayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerPainter.java @@ -1,31 +1,42 @@ /*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. + # Copyright (c) 2021 Stephan Wahlbrink and others. # # This program and the accompanying materials are made available under the # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. # - # SPDX-License-Identifier: EPL-2.0 + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 # # Contributors: - # Original NatTable authors and others - initial API and implementation + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; /** * Classes implementing this interface are responsible for painting to the relevant {@link Device}. * Every layer has a layer painter. A layer can contribute to painting by providing its own painter. */ -public interface ILayerPainter { +@NonNullByDefault +public interface LayerPainter { + + + /** + * This method is used to adjust the cell bounds when painting the layer. This is most often used to reduce the size + * of the cell to accommodate grid lines. + */ + LRectangle adjustCellBounds(long columnPosition, long rowPosition, LRectangle cellBounds); /** * @param natLayer @@ -35,12 +46,7 @@ public interface ILayerPainter { * @param rectangle area the layer can paint in * @param configuration in use by NatTable. Useful for looking up associated painters. */ - public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, org.eclipse.swt.graphics.Rectangle rectangle, IConfigRegistry configuration); - - /** - * This method is used to adjust the cell bounds when painting the layer. This is most often used to reduce the size - * of the cell to accommodate grid lines. - */ - public LRectangle adjustCellBounds(long columnPosition, long rowPosition, LRectangle cellBounds); + void paintLayer(Layer natLayer, GC gc, int xOffset, int yOffset, + Rectangle rectangle, ConfigRegistry configuration); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/LayerUtil.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerUtils.java index 9eb3e135..604da000 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/LayerUtil.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/LayerUtils.java @@ -11,15 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; -public class LayerUtil { + +@NonNullByDefault +public class LayerUtils { /** @@ -29,9 +32,9 @@ public class LayerUtil { * @param targetLayer layer to convert the from position to * @return converted position, or ILayerDim.POSITION_NA if conversion not possible */ - public static final long convertPosition(final ILayerDim sourceDim, + public static final long convertPosition(final LayerDim sourceDim, final long sourceRefPosition, final long sourcePosition, - final ILayerDim targetDim) { + final LayerDim targetDim) { if (targetDim == sourceDim) { return sourcePosition; } @@ -41,7 +44,7 @@ public class LayerUtil { return targetDim.getPositionById(id); } catch (final PositionOutOfBoundsException e) { - return ILayerDim.POSITION_NA; + return LayerDim.POSITION_NA; } } @@ -52,8 +55,8 @@ public class LayerUtil { * @param targetLayer layer to convert the from position to * @return converted column position, or -1 if conversion not possible */ - public static final long convertColumnPosition(final ILayer sourceLayer, - final long sourceColumnPosition, final ILayer targetLayer) { + public static final long convertColumnPosition(final Layer sourceLayer, + final long sourceColumnPosition, final Layer targetLayer) { return convertPosition(sourceLayer.getDim(HORIZONTAL), sourceColumnPosition, sourceColumnPosition, targetLayer.getDim(HORIZONTAL) ); @@ -66,8 +69,8 @@ public class LayerUtil { * @param targetLayer layer to convert the from position to * @return converted row position, or -1 if conversion not possible */ - public static final long convertRowPosition(final ILayer sourceLayer, - final long sourceRowPosition, final ILayer targetLayer) { + public static final long convertRowPosition(final Layer sourceLayer, + final long sourceRowPosition, final Layer targetLayer) { return convertPosition(sourceLayer.getDim(VERTICAL), sourceRowPosition, sourceRowPosition, targetLayer.getDim(VERTICAL) ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/TransformLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/TransformLayer.java index 1f45679b..e1b11d22 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/TransformLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/TransformLayer.java @@ -11,14 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; /** @@ -30,21 +29,24 @@ import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; * * The layer is similar to {@link AbstractLayerTransform}, but is {@link DimBasedLayer dim-based}. */ -public abstract class TransformLayer extends ForwardLayer { +@NonNullByDefault +public abstract class TransformLayer<TLayerDim extends ForwardLayerDim<? extends TransformLayer<TLayerDim>>> + extends ForwardLayer<TLayerDim> { - public TransformLayer(/*@NonNull*/ final ILayer underlyingLayer) { - super(underlyingLayer); + public TransformLayer(final Layer underlyingLayer, + final @Nullable LayerPainter layerPainter) { + super(underlyingLayer, layerPainter); } - - @Override - protected abstract void initDims(); + public TransformLayer(final Layer underlyingLayer) { + this(underlyingLayer, null); + } @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerCell underlyingCell= getUnderlyingLayer().getCellByPosition( + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerCell underlyingCell= getUnderlyingLayer().getCellByPosition( getDim(HORIZONTAL).localToUnderlyingPosition(columnPosition, columnPosition), getDim(VERTICAL).localToUnderlyingPosition(rowPosition, rowPosition) ); @@ -54,14 +56,14 @@ public abstract class TransformLayer extends ForwardLayer { underlyingCell ); } - protected ILayerCellDim transformCellDim(final ILayerCellDim underlyingDim, final long position) { + protected LayerCellDim transformCellDim(final LayerCellDim underlyingDim, final long position) { if (underlyingDim.getPosition() == position) { return underlyingDim; } final long originPosition= position - (underlyingDim.getPosition() - underlyingDim.getOriginPosition()); - return new LayerCellDim(underlyingDim.getOrientation(), underlyingDim.getId(), + return new BasicLayerCellDim(underlyingDim.getOrientation(), underlyingDim.getId(), position, originPosition, underlyingDim.getPositionSpan() ); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/TransformLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/TransformLayerDim.java index d8a029b8..68808a55 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/TransformLayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/TransformLayerDim.java @@ -12,31 +12,34 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.core.layer; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PixelOutOfBoundsException; /** - * Dim implementation for {@link TransformLayer}. + * A layer dimension for a {@link TransformLayer}. * - * @param <T> the type of the layer + * @param <TLayer> the type of the layer */ -public abstract class TransformLayerDim<T extends ILayer> extends ForwardLayerDim<T> { +@NonNullByDefault +public abstract class TransformLayerDim<TLayer extends Layer> extends ForwardLayerDim<TLayer> { - public TransformLayerDim(/*@NonNull*/ final T layer, /*@NonNull*/ final ILayerDim underlyingDim) { + public TransformLayerDim(final TLayer layer, final LayerDim underlyingDim) { super(layer, underlyingDim.getOrientation(), underlyingDim); } - public TransformLayerDim(/*@NonNull*/ final T layer, /*@NonNull*/ final Orientation orientation, - /*@NonNull*/ final ILayerDim underlyingDim) { + public TransformLayerDim(final TLayer layer, final Orientation orientation, + final LayerDim underlyingDim) { super(layer, orientation, underlyingDim); } @@ -68,7 +71,7 @@ public abstract class TransformLayerDim<T extends ILayer> extends ForwardLayerDi public abstract long localToUnderlyingPosition(final long refPosition, final long position); @Override - public long underlyingToLocalPosition(final ILayerDim sourceUnderlyingDim, + public long underlyingToLocalPosition(final LayerDim sourceUnderlyingDim, final long underlyingPosition) { if (sourceUnderlyingDim != this.underlyingDim) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -78,7 +81,7 @@ public abstract class TransformLayerDim<T extends ILayer> extends ForwardLayerDi } @Override - public List<LRange> underlyingToLocalPositions(final ILayerDim sourceUnderlyingDim, + public List<LRange> underlyingToLocalPositions(final LayerDim sourceUnderlyingDim, final Collection<LRange> underlyingPositions) { if (sourceUnderlyingDim != this.underlyingDim) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -109,7 +112,7 @@ public abstract class TransformLayerDim<T extends ILayer> extends ForwardLayerDi public long getPositionByPixel(final long pixel) { final long position= doUnderlyingToLocalPosition(this.underlyingDim.getPositionByPixel(pixel)); if (position < 0 || position >= getPositionCount()) { - throw PixelOutOfBoundsException.pixel(pixel, getOrientation()); + throw new PixelOutOfBoundsException(pixel, getOrientation()); } return position; } @@ -119,7 +122,7 @@ public abstract class TransformLayerDim<T extends ILayer> extends ForwardLayerDi final long underlyingRefPosition= localToUnderlyingPosition(refPosition, refPosition); return this.underlyingDim.getPositionStart(underlyingRefPosition, (refPosition == position) ? - underlyingRefPosition : + underlyingRefPosition : localToUnderlyingPosition(refPosition, position) ); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/CellVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/CellVisualChangeEvent.java new file mode 100644 index 00000000..64afbf2a --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/CellVisualChangeEvent.java @@ -0,0 +1,95 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; + + +@NonNullByDefault +public class CellVisualChangeEvent implements VisualChangeEvent { + + + protected final Layer layer; + + protected final LPoint position; + + + public CellVisualChangeEvent(final Layer layer, final LPoint position) { + this.layer= layer; + this.position= position; + } + + public CellVisualChangeEvent(final Layer layer, final long columnPosition, final long rowPosition) { + this(layer, new LPoint(columnPosition, rowPosition)); + } + + @Override + public @Nullable CellVisualChangeEvent toLayer(final Layer targetLayer) { + if (targetLayer == this.layer) { + return this; + } + + final var hTargetDim= targetLayer.getDim(HORIZONTAL); + final var vTargetDim= targetLayer.getDim(VERTICAL); + final long hPosition= hTargetDim.underlyingToLocalPosition(this.layer.getDim(HORIZONTAL), + this.position.x ); + final long vPosition= vTargetDim.underlyingToLocalPosition(this.layer.getDim(VERTICAL), + this.position.y ); + + return (hPosition >= 0 && hPosition < hTargetDim.getPositionCount() + && vPosition >= 0 && vPosition < vTargetDim.getPositionCount() ) ? + toLayer(targetLayer, hPosition, vPosition) : + null; + } + + protected @Nullable CellVisualChangeEvent toLayer(final Layer targetLayer, + final long columnPosition, final long rowPosition) { + return new CellVisualChangeEvent(targetLayer, columnPosition, rowPosition); + } + + + @Override + public final Layer getLayer() { + return this.layer; + } + + public LPoint getPosition() { + return this.position; + } + + public long getColumnPosition() { + return this.position.x; + } + + public long getRowPosition() { + return this.position.y; + } + + @Override + public ImList<LRectangle> getChangedPositionRectangles() { + return ImCollections.newList( + new LRectangle(this.position.x, this.position.y, 1, 1) ); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimGeneralStrucuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimGeneralStrucuralChangeEvent.java new file mode 100644 index 00000000..edf5a77b --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimGeneralStrucuralChangeEvent.java @@ -0,0 +1,83 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import java.util.List; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +@NonNullByDefault +public class DimGeneralStrucuralChangeEvent implements VisualChangeEvent, StructuralChangeEvent { + + + private final LayerDim layerDim; + + + public DimGeneralStrucuralChangeEvent(final LayerDim layerDim) { + this.layerDim= layerDim; + } + + @Override + public @Nullable DimGeneralStrucuralChangeEvent toLayer(final Layer targetLayer) { + final LayerDim targetLayerDim= targetLayer.getDim(this.layerDim.getOrientation()); + if (targetLayerDim == this.layerDim) { + return this; + } + + return new DimGeneralStrucuralChangeEvent(targetLayerDim); + } + + + public final LayerDim getLayerDim() { + return this.layerDim; + } + + public final Orientation getOrientation() { + return this.layerDim.getOrientation(); + } + + @Override + public final Layer getLayer() { + return this.layerDim.getLayer(); + } + + + @Override + public ImList<LRectangle> getChangedPositionRectangles() { + final var layer= getLayer(); + return ImCollections.newList( + new LRectangle(0, 0, layer.getColumnCount(), layer.getRowCount()) ); + } + + + @Override + public boolean isStructureChanged(final Orientation orientation) { + return (getOrientation() == orientation); + } + + @Override + public @Nullable List<StructuralDiff> getDiffs(final Orientation orientation) { + return null; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsStructuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsStructuralChangeEvent.java new file mode 100644 index 00000000..4c70a170 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsStructuralChangeEvent.java @@ -0,0 +1,58 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +/** + * Event indicating a change in the structure of the columns/rows. + * + * <p>This event carried {@link StructuralDiff} indicating the columns/rows + * which have changed.</p> + */ +@NonNullByDefault +public abstract class DimPositionsStructuralChangeEvent extends DimPositionsVisualChangeEvent + implements StructuralChangeEvent { + + + /** + * Creates a new ColumnStructuralChangeEvent based on the given information. + * @param layerDim the layer dim to which the given positions match. + * @param positions the position ranges of columns/rows that have changed. + */ + public DimPositionsStructuralChangeEvent(final LayerDim layerDim, + final List<LRange> positions) { + super(layerDim, positions); + } + + @Override + protected @Nullable abstract DimPositionsStructuralChangeEvent toLayer(LayerDim targetLayerDim, + List<LRange> positions); + + + @Override + public boolean isStructureChanged(final Orientation orientation) { + return (getOrientation() == orientation); + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsVisualChangeEvent.java new file mode 100644 index 00000000..1cd6a559 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/DimPositionsVisualChangeEvent.java @@ -0,0 +1,144 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.List; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +/** + * An event that indicates a visible change to one ore more columns/rows in the + * layer. + */ +@NonNullByDefault +public class DimPositionsVisualChangeEvent implements VisualChangeEvent { + + + /** + * The LayerDim to which the given column/row positions match + */ + private final LayerDim layerDim; + + /** + * The column position ranges for the columns/rows that have changed. + */ + private final List<LRange> positions; + + + /** + * Creates a new ColumnVisualChangeEvent based on the given information. + * @param layerDim the layer dim to which the given positions match. + * @param positions the position ranges of columns/rows that have changed. + */ + public DimPositionsVisualChangeEvent(final LayerDim layerDim, final List<LRange> positions) { + this.layerDim= layerDim; + this.positions= positions; + } + + public DimPositionsVisualChangeEvent(final LayerDim layerDim, final LRange positionRanges) { + this.layerDim= layerDim; + this.positions= ImCollections.newList(positionRanges); + } + + @Override + public @Nullable DimPositionsVisualChangeEvent toLayer(final Layer targetLayer) { + final LayerDim targetLayerDim= targetLayer.getDim(getOrientation()); + if (targetLayerDim == this.layerDim) { + return this; + } + + final var positionRanges= targetLayerDim.underlyingToLocalPositions(this.layerDim, + this.positions ); + + return (positionRanges != null && positionRanges.size() > 0) ? + toLayer(targetLayerDim, positionRanges) : null; + } + + protected @Nullable DimPositionsVisualChangeEvent toLayer(final LayerDim targetLayerDim, + final List<LRange> positionRanges) { + return new DimPositionsVisualChangeEvent(targetLayerDim, positionRanges); + } + + + public final LayerDim getLayerDim() { + return this.layerDim; + } + + public final Orientation getOrientation() { + return this.layerDim.getOrientation(); + } + + @Override + public final Layer getLayer() { + return this.layerDim.getLayer(); + } + + /** + * @return The column/row position ranges for the columns that have changed. + */ + public List<LRange> getPositionRanges() { + return this.positions; + } + + @Override + public ImList<LRectangle> getChangedPositionRectangles() { + final var columnPositionRanges= getPositionRanges(); + final var positionRectangles= new @NonNull LRectangle[columnPositionRanges.size()]; + + final long positionCount; + switch (getOrientation()) { + case HORIZONTAL: + positionCount= getLayer().getDim(VERTICAL).getPositionCount(); + for (int i= 0; i < positionRectangles.length; i++) { + final var range= columnPositionRanges.get(i); + positionRectangles[i]= + new LRectangle(range.start, 0, range.end - range.start, positionCount); + } + break; + case VERTICAL: + positionCount= getLayer().getDim(HORIZONTAL).getPositionCount(); + for (int i= 0; i < positionRectangles.length; i++) { + final var range= columnPositionRanges.get(i); + positionRectangles[i]= + new LRectangle(0, range.start, positionCount, range.end - range.start); + } + break; + default: + throw new IllegalStateException(); + } + + return ImCollections.newList(positionRectangles); + } + + + @Override + public String toString() { + return getClass().getSimpleName(); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralStructuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralStructuralChangeEvent.java new file mode 100644 index 00000000..7e714e10 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralStructuralChangeEvent.java @@ -0,0 +1,55 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; + + +/** + * General event indicating that structures cached by the layers need refreshing. + * <p> + * TIP: Consider throwing a more focused event (subclass) if you need to do this. + */ +@NonNullByDefault +public class GeneralStructuralChangeEvent extends GeneralVisualChangeEvent implements StructuralChangeEvent { + + + public GeneralStructuralChangeEvent(final Layer layer) { + super(layer); + } + + @Override + public @Nullable GeneralStructuralChangeEvent toLayer(final Layer targetLayer) { + return new GeneralStructuralChangeEvent(targetLayer); + } + + + @Override + public boolean isStructureChanged(final Orientation orientation) { + return true; + } + + @Override + public @Nullable List<StructuralDiff> getDiffs(final Orientation orientation) { + return null; + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralVisualChangeEvent.java new file mode 100644 index 00000000..525cbd2f --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/GeneralVisualChangeEvent.java @@ -0,0 +1,58 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.events; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; + + +@NonNullByDefault +public class GeneralVisualChangeEvent implements VisualChangeEvent { + + + private final Layer layer; + + + public GeneralVisualChangeEvent(final Layer layer) { + this.layer= layer; + } + + @Override + public @Nullable GeneralVisualChangeEvent toLayer(final Layer targetLayer) { + if (targetLayer == this.layer) { + return this; + } + + return new GeneralVisualChangeEvent(targetLayer); + } + + + @Override + public Layer getLayer() { + return this.layer; + } + + + @Override + public ImList<LRectangle> getChangedPositionRectangles() { + return ImCollections.newList( + new LRectangle(0, 0, this.layer.getColumnCount(), this.layer.getRowCount()) ); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/IStructuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/StructuralChangeEvent.java index 4fdb2b78..74e1ff0d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/IStructuralChangeEvent.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/StructuralChangeEvent.java @@ -11,9 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.event; +package org.eclipse.statet.ecommons.waltable.core.layer.events; -import java.util.Collection; +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; /** @@ -21,14 +26,12 @@ import java.util.Collection; * defined as something that modifies the number of columns/rows in the layer or * their associated widths/heights. */ -public interface IStructuralChangeEvent extends IVisualChangeEvent { - - public boolean isHorizontalStructureChanged(); +@NonNullByDefault +public interface StructuralChangeEvent extends VisualChangeEvent { - public Collection<StructuralDiff> getColumnDiffs(); - public boolean isVerticalStructureChanged(); + boolean isStructureChanged(Orientation orientation); - public Collection<StructuralDiff> getRowDiffs(); + @Nullable List<StructuralDiff> getDiffs(Orientation orientation); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/StructuralDiff.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/StructuralDiff.java index fb0a40f6..a1447c32 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/StructuralDiff.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/StructuralDiff.java @@ -11,42 +11,38 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.event; +package org.eclipse.statet.ecommons.waltable.core.layer.events; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; + + +@NonNullByDefault public class StructuralDiff { - public enum DiffTypeEnum { + public enum DiffType { ADD, CHANGE, DELETE; } - private final DiffTypeEnum diffType; + private final DiffType diffType; private final LRange beforePositionRange; private final LRange afterPositionRange; - public StructuralDiff(final DiffTypeEnum diffType, final LRange beforePositionRange, final LRange afterPositionRange) { - if (diffType == null) { - throw new NullPointerException("diffType"); - } - if (beforePositionRange == null) { - throw new NullPointerException("beforePositionRange"); - } - if (afterPositionRange == null) { - throw new NullPointerException("afterPositionRange"); - } - - this.diffType= diffType; - this.beforePositionRange= beforePositionRange; - this.afterPositionRange= afterPositionRange; + public StructuralDiff(final DiffType diffType, final LRange beforePositionRange, final LRange afterPositionRange) { + this.diffType= nonNullAssert(diffType); + this.beforePositionRange= nonNullAssert(beforePositionRange); + this.afterPositionRange= nonNullAssert(afterPositionRange); } - public DiffTypeEnum getDiffType() { + public DiffType getDiffType() { return this.diffType; } @@ -67,17 +63,17 @@ public class StructuralDiff { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof StructuralDiff)) { - return false; + if (obj instanceof StructuralDiff) { + final StructuralDiff other= (StructuralDiff)obj; + return (this.diffType == other.diffType + && this.beforePositionRange == other.beforePositionRange + && this.afterPositionRange == other.afterPositionRange ); } - final StructuralDiff other= (StructuralDiff) obj; - return (this.diffType == other.diffType - && this.beforePositionRange == other.beforePositionRange - && this.afterPositionRange == other.afterPositionRange ); + return false; } @Override diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/IVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/VisualChangeEvent.java index 0709fbcb..644348d7 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/IVisualChangeEvent.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/events/VisualChangeEvent.java @@ -11,12 +11,15 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer.event; +package org.eclipse.statet.ecommons.waltable.core.layer.events; -import java.util.Collection; +import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; /** @@ -25,18 +28,20 @@ import org.eclipse.statet.ecommons.waltable.layer.ILayer; * It does not imply a structural change to the layer. This means that cached * structure does not need to be invalidated due to visible change events. */ -public interface IVisualChangeEvent extends ILayerEvent { - +@NonNullByDefault +public interface VisualChangeEvent extends LayerEvent { + + /** * @return the layer that the visible change event is originating from. */ - public ILayer getLayer(); + Layer getLayer(); /** * @return the position rectangles that have changed and need to be redrawn. * If no rectangles are returned, then the receiver should assume that the * entire layer is changed and will need to be redrawn. */ - public Collection<LRectangle> getChangedPositionRectangles(); + List<LRectangle> getChangedPositionRectangles(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/IOverlayPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/OverlayPainter.java index fe44e4be..81134d86 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/IOverlayPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/OverlayPainter.java @@ -11,22 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter; +package org.eclipse.statet.ecommons.waltable.core.layer.top; import org.eclipse.swt.graphics.GC; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** - * An overlay painter is given a chance to paint the canvas once - * the layers have finished rendering. + * An overlay painter is given a chance to paint the canvas once the layers have finished rendering. * - * @see NatTable#addOverlayPainter(IOverlayPainter) + * @see NatTable#addOverlayPainter(SwtOverlayPainter) */ -public interface IOverlayPainter { - - public void paintOverlay(GC gc, ILayer layer); +@NonNullByDefault +public interface OverlayPainter { + + + void paintOverlay(GC gc, Layer layer); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayer.java new file mode 100644 index 00000000..9d2924ea --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayer.java @@ -0,0 +1,30 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.top; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; + + +@NonNullByDefault +public interface TopLayer extends Layer { + + + @Override + TopLayerDim getDim(Orientation orientation); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayerDim.java new file mode 100644 index 00000000..817f8af5 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/layer/top/TopLayerDim.java @@ -0,0 +1,35 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.layer.top; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +@NonNullByDefault +public interface TopLayerDim extends LayerDim { + + + @Override + TopLayer getLayer(); + + + void repaintPosition(long position); + + void repaintPositions(LRange positions); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/Style.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/BasicStyle.java index f99d7f3f..a80e3122 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/Style.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/BasicStyle.java @@ -11,41 +11,54 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.style; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; -public class Style implements IStyle { +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; - private final Map<ConfigAttribute<?>, Object> styleAttributeValueMap= new HashMap<>(); +/** + * A style backed by a map. + */ +@NonNullByDefault +public class BasicStyle implements Style { + + + private final Map<ConfigAttribute<?>, Object> configAttributeValueMap= new HashMap<>(); + + @Override @SuppressWarnings("unchecked") - public <T> T getAttributeValue(final ConfigAttribute<T> styleAttribute) { - return (T) this.styleAttributeValueMap.get(styleAttribute); + public <T> T getAttributeValue(final ConfigAttribute<T> configAttribute) { + return (T)this.configAttributeValueMap.get(configAttribute); } - + @Override - public <T> void setAttributeValue(final ConfigAttribute<T> styleAttribute, final T value) { - this.styleAttributeValueMap.put(styleAttribute, value); + public <T> void setAttributeValue(final ConfigAttribute<T> configAttribute, final @Nullable T value) { + if (value != null) { + this.configAttributeValueMap.put(configAttribute, value); + } + else { + this.configAttributeValueMap.remove(configAttribute); + } } - + @Override public String toString() { final StringBuilder resultBuilder= new StringBuilder(); resultBuilder.append(this.getClass().getSimpleName() + ": "); //$NON-NLS-1$ - - final Set<Entry<ConfigAttribute<?>, Object>> entrySet= this.styleAttributeValueMap.entrySet(); - - for (final Entry<ConfigAttribute<?>, Object> entry : entrySet) { + + for (final Entry<ConfigAttribute<?>, Object> entry : this.configAttributeValueMap.entrySet()) { resultBuilder.append(entry.getKey() + ": " + entry.getValue() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } - + return resultBuilder.toString(); } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/BorderStyle.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/BorderStyle.java index 378973b9..8921d75a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/BorderStyle.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/BorderStyle.java @@ -11,30 +11,36 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.style; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; import org.eclipse.swt.graphics.Color; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + import org.eclipse.statet.ecommons.waltable.persistence.ColorPersistor; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; /** * This class defines the visual attributes of a border: * * <dl> - * <dt>Thickness</dt> + * <dt>Thickness</dt> * <dd>The width of the border in pixel</dd> - * <dt>Color</dt> + * <dt>Color</dt> * <dd>The color of the border</dd> - * <dt>Line Style</dt> + * <dt>Line Style</dt> * <dd>The line style of the border, a constant of {@link LineStyle}</dd> - * <dt>Offset</dt> + * <dt>Offset</dt> * <dd>The offset of the border toward the regular painting area. - * If not specified otherwise, the value is 0, meaning no offset. A value > 0 shifts the border inwards, a - * value < 0 shifts the border outwards. For example -1 can be used to paint the border over the grid.</dd> + * If not specified otherwise, the value is 0, meaning no offset. A + * value > 0 shifts the border inwards, a value < 0 shifts the + * border outwards.</dd> * </dl> */ +@NonNullByDefault public class BorderStyle { @@ -48,28 +54,17 @@ public class BorderStyle { } - - - private int thickness; - - private Color color; - - private LineStyle lineStyle; - - private int offset; - - - /** - * Creates a new border style to paint a thin, black, solid line. - */ - public BorderStyle() { - this(1, GUIHelper.COLOR_BLACK, LineStyle.SOLID, 0); - } - - public BorderStyle(final int thickness, final Color color, final LineStyle lineStyle) { - this(thickness, color, lineStyle, 0); - } - + + + private final int thickness; + + private final Color color; + + private final LineStyle lineStyle; + + private final int offset; + + /** * Creates a new border style. * @@ -79,68 +74,48 @@ public class BorderStyle { * @param offset the offset of the border */ public BorderStyle(final int thickness, final Color color, final LineStyle lineStyle, final int offset) { - setThickness(thickness); - setColor(color); - setLineStyle(lineStyle); - setOffset(offset); + this.thickness= (thickness > 0) ? thickness : 0; + this.color= nonNullAssert(color); + this.lineStyle= nonNullAssert(lineStyle); + this.offset= offset; } - + + public BorderStyle(final int thickness, final Color color, final LineStyle lineStyle) { + this(thickness, color, lineStyle, 0); + } + /** * Reconstruct this instance from the persisted String. * * @see BorderStyle#toString() */ public BorderStyle(final String string) { - final String[] tokens= string.split("\\|"); //$NON-NLS-1$ - + final var tokens= string.split("\\|"); //$NON-NLS-1$ + this.thickness= Integer.parseInt(tokens[0]); this.color= ColorPersistor.asColor(tokens[1]); this.lineStyle= LineStyle.valueOf(tokens[2]); - if (tokens.length > 3) { - this.offset= Integer.parseInt(tokens[3]); - } + this.offset= (tokens.length > 3) ? Integer.parseInt(tokens[3]) : 0; } - - + + public int getThickness() { return this.thickness; } - + public Color getColor() { return this.color; } - + public LineStyle getLineStyle() { return this.lineStyle; } - + public int getOffset() { return this.offset; } - - public void setThickness(final int thickness) { - this.thickness= (thickness > 0) ? thickness : 0; - } - - public void setColor(final Color color) { - if (color == null) { - throw new NullPointerException("color"); //$NON-NLS-1$ - } - this.color= color; - } - - public void setLineStyle(final LineStyle lineStyle) { - if (lineStyle == null) { - throw new NullPointerException("lineStyle"); //$NON-NLS-1$ - } - this.lineStyle= lineStyle; - } - - public void setOffset(final int offset) { - this.offset= offset; - } - - + + @Override public int hashCode() { return ((this.thickness @@ -150,21 +125,20 @@ public class BorderStyle { } @Override - public boolean equals(final Object obj) { + public boolean equals(final @Nullable Object obj) { if (this == obj) { return true; } - if (!(obj instanceof BorderStyle)) { - return false; + if (obj instanceof BorderStyle) { + final BorderStyle other= (BorderStyle)obj; + return (this.thickness == other.thickness + && this.color.equals(other.color) + && this.lineStyle == other.lineStyle + && this.offset == other.offset ); } - - final BorderStyle that= (BorderStyle) obj; - return (this.thickness == that.thickness - && this.color.equals(that.color) - && this.lineStyle == that.lineStyle - && this.offset == that.offset ); + return false; } - + /** * @return a human readable representation of the border style. This is * suitable for constructing an equivalent instance using the @@ -174,5 +148,5 @@ public class BorderStyle { public String toString() { return "" + this.thickness + '|' + ColorPersistor.asString(this.color) + '|' + this.lineStyle + '|' + this.offset; //$NON-NLS-1$ } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/CellStyling.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/CellStyling.java new file mode 100644 index 00000000..d95f8566 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/CellStyling.java @@ -0,0 +1,98 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.style; + +import java.util.Set; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; + + +@NonNullByDefault +public class CellStyling { + + /** + * Attribute for configuring the background color of a cell. + */ + public static final ConfigAttribute<Color> BACKGROUND_COLOR= new ConfigAttribute<>(); + + /** + * Attribute for configuring the foreground color of a cell. + */ + public static final ConfigAttribute<Color> FOREGROUND_COLOR= new ConfigAttribute<>(); + + /** + * Attribute for configuring the gradient sweeping background color. + * Is used by the GradientBackgroundPainter. + */ + public static final ConfigAttribute<Color> GRADIENT_BACKGROUND_COLOR= new ConfigAttribute<>(); + + /** + * Attribute for configuring the gradient sweeping foreground color. + * Is used by the GradientBackgroundPainter. + */ + public static final ConfigAttribute<Color> GRADIENT_FOREGROUND_COLOR= new ConfigAttribute<>(); + + /** + * Attribute for configuring the horizontal alignment of a cell. + */ + public static final ConfigAttribute<HorizontalAlignment> HORIZONTAL_ALIGNMENT= new ConfigAttribute<>(); + + /** + * Attribute for configuring the vertical alignment of a cell. + */ + public static final ConfigAttribute<VerticalAlignment> VERTICAL_ALIGNMENT= new ConfigAttribute<>(); + + /** + * Attribute for configuring the font to be used on rendering text. + * Is used by all specialisations of the AbstractTextPainter. + */ + public static final ConfigAttribute<Font> FONT= new ConfigAttribute<>(); + + /** + * Attribute for configuring the image to rendered. + * Is used by the ImagePainter to determine the image to render dynamically. + */ + public static final ConfigAttribute<Image> IMAGE= new ConfigAttribute<>(); + + /** + * Attribute for configuring the border style. + * Is used by the LineBorderDecorator. + */ + public static final ConfigAttribute<BorderStyle> BORDER_STYLE= new ConfigAttribute<>(); + + /** + * Attribute for configuring the echo character that should be used by PasswordTextPainter and + * PasswordCellEditor. + */ + public static final ConfigAttribute<Character> PASSWORD_ECHO_CHAR= new ConfigAttribute<>(); + + /** + * Attribute for configuring the text decoration (underline and/or strikethrough). + * Is used by all specialisations of the AbstractTextPainter + */ + public static final ConfigAttribute<Set<TextDecorationLine>> TEXT_DECORATION_LINES= new ConfigAttribute<>(); + + public static final ConfigAttribute<Font> CONTROL_FONT= new ConfigAttribute<>(); + + + private CellStyling() { + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/GridStyling.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/GridStyling.java new file mode 100644 index 00000000..df856942 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/GridStyling.java @@ -0,0 +1,72 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.style; + +import java.util.function.Function; + +import org.eclipse.swt.graphics.Color; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImIdentityList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.util.GUIHelper; + + +@NonNullByDefault +public class GridStyling { + + + public static final ConfigAttribute<Color> GRID_LINE_COLOR= new ConfigAttribute<>(); + + + public static class ConfigGridLineColorSupplier implements Function<ConfigRegistry, Color> { + + + private final ImIdentityList<String> configLabels; + + + public ConfigGridLineColorSupplier(final ImIdentityList<String> configLabels) { + this.configLabels= configLabels; + } + + public ConfigGridLineColorSupplier(final String configLabel) { + this(ImCollections.newIdentityList(configLabel)); + } + + public ConfigGridLineColorSupplier() { + this(ImCollections.emptyIdentityList()); + } + + + @Override + public Color apply(final ConfigRegistry configRegistry) { + final var value= configRegistry.getAttribute(GridStyling.GRID_LINE_COLOR, + DisplayMode.NORMAL, this.configLabels ); + if (value != null) { + return value; + } + return GUIHelper.COLOR_GRAY; + } + + } + + private GridStyling() { + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/HorizontalAlignment.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/HorizontalAlignment.java index 585cab3f..162194fd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/HorizontalAlignment.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/HorizontalAlignment.java @@ -11,9 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.style; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public enum HorizontalAlignment { LEFT, @@ -21,8 +24,4 @@ public enum HorizontalAlignment { RIGHT; - private HorizontalAlignment() { - } - - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/RegistryStyle.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/RegistryStyle.java new file mode 100644 index 00000000..42a7d770 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/RegistryStyle.java @@ -0,0 +1,85 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.style; + +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; + + +/** + * A style backed by a registry. + */ +@NonNullByDefault +public class RegistryStyle implements Style { + + + private final ConfigRegistry configRegistry; + + private final ConfigAttribute<Style> styleConfigAttribute; + private final DisplayMode targetDisplayMode; + private final List<String> configLabels; + + + public RegistryStyle(final ConfigRegistry configRegistry, + final ConfigAttribute<Style> styleConfigAttribute, + final DisplayMode targetDisplayMode, final List<String> configLabels) { + this.configRegistry= configRegistry; + this.styleConfigAttribute= styleConfigAttribute; + this.targetDisplayMode= targetDisplayMode; + this.configLabels= configLabels; + } + + + @Override + public <T> @Nullable T getAttributeValue(final ConfigAttribute<T> configAttribute) { + @Nullable T configAttributeValue= null; + for (final DisplayMode displayMode : this.configRegistry.getDisplayModeOrdering() + .getDisplayModeOrdering(this.targetDisplayMode) ) { + for (final String configLabel : this.configLabels) { + final Style style= this.configRegistry + .getSpecificAttribute(this.styleConfigAttribute, displayMode, configLabel); + if (style != null) { + configAttributeValue= style.getAttributeValue(configAttribute); + if (configAttributeValue != null) { + return configAttributeValue; + } + } + } + + // default + final Style cellStyle= this.configRegistry + .getSpecificAttribute(this.styleConfigAttribute, displayMode, null); + if (cellStyle != null) { + configAttributeValue= cellStyle.getAttributeValue(configAttribute); + if (configAttributeValue != null) { + return configAttributeValue; + } + } + } + + return null; + } + + @Override + public <T> void setAttributeValue(final ConfigAttribute<T> configAttribute, final @Nullable T value) { + throw new UnsupportedOperationException(); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/Style.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/Style.java new file mode 100644 index 00000000..c2edd6d0 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/Style.java @@ -0,0 +1,33 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.style; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; + + +/** + * Used to store attributes reflecting a (usually display) style. + */ +@NonNullByDefault +public interface Style { + + + <T> @Nullable T getAttributeValue(ConfigAttribute<T> configAttribute); + + <T> void setAttributeValue(ConfigAttribute<T> configAttribute, @Nullable T value); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/TextDecorationEnum.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/TextDecorationLine.java index 0f02541e..8519f365 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/TextDecorationEnum.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/TextDecorationLine.java @@ -11,21 +11,19 @@ # Dirk Fauth - initial API and implementation and/or initial documentation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.style; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** - * Enumeration for text decorations that can be configured for cell styles. - * <ul> - * <li>NONE (default) - Render no decoration</li> - * <li>UNDERLINE - Render the text underlined</li> - * <li>STRIKETHROUGH - Render the text strike through</li> - * <li>UNDERLINE_STRIKETHROUGH - Render the text underlined and strike through</li> - * </ul> + * Text decoration line that can be configured for cell styles. */ -public enum TextDecorationEnum { +@NonNullByDefault +public enum TextDecorationLine { + UNDERLINE, + STRIKETHROUGH; - NONE, UNDERLINE, STRIKETHROUGH, UNDERLINE_STRIKETHROUGH; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/VerticalAlignment.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/VerticalAlignment.java index 6c0cf597..1aab0226 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/VerticalAlignment.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/style/VerticalAlignment.java @@ -11,9 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.core.style; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public enum VerticalAlignment { TOP, diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/SwtUtils.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/SwtUtils.java new file mode 100644 index 00000000..6bb05713 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/SwtUtils.java @@ -0,0 +1,169 @@ +/*=============================================================================# + # Copyright (c) 2013, 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.core.swt; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.Scrollable; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle.LineStyle; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; + + +@NonNullByDefault +public class SwtUtils { + + + public static final @Nullable ScrollBar getScrollBar(final Scrollable control, + final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return control.getHorizontalBar(); + case VERTICAL: + return control.getVerticalBar(); + default: + throw new IllegalStateException(); + } + } + + + public static final int get(final Point point, final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return point.x; + case VERTICAL: + return point.y; + default: + throw new IllegalStateException(); + } + } + + public static final int getStart(final Rectangle rect, final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return rect.x; + case VERTICAL: + return rect.y; + default: + throw new IllegalStateException(); + } + } + + public static final int getEnd(final Rectangle rect, final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return rect.x + rect.width; + case VERTICAL: + return rect.y + rect.height; + default: + throw new IllegalStateException(); + } + } + + public static final int getSize(final Rectangle rect, final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return rect.width; + case VERTICAL: + return rect.height; + default: + throw new IllegalStateException(); + } + } + + + public static final int toSWT(final long pixel) { + if (pixel < Integer.MIN_VALUE || pixel > Integer.MAX_VALUE) { + throw new IndexOutOfBoundsException(); + } + return (int)pixel; + } + + public static final Rectangle toSWT(final LRectangle rect) { + return new Rectangle(toSWT(rect.x), toSWT(rect.y), toSWT(rect.width), toSWT(rect.height)); + } + + public static final LRectangle toNatTable(final Rectangle rect) { + return new LRectangle(rect.x, rect.y, rect.width, rect.height); + } + + public static final Point toSWT(final LPoint lPoint) { + return new Point(toSWT(lPoint.x), toSWT(lPoint.y)); + } + + + public static final int toSWT(final HorizontalAlignment alignment) { + switch (alignment) { + case LEFT: + return SWT.LEFT; + case CENTER: + return SWT.CENTER; + case RIGHT: + return SWT.RIGHT; + default: + throw new IllegalStateException(); + } + } + + public static final int toSWT(final LineStyle lineStyle) { + switch (lineStyle) { + case SOLID: + return SWT.LINE_SOLID; + case DASHED: + return SWT.LINE_DASH; + case DOTTED: + return SWT.LINE_DOT; + case DASHDOT: + return SWT.LINE_DASHDOT; + case DASHDOTDOT: + return SWT.LINE_DASHDOTDOT; + default: + throw new IllegalStateException(); + } + } + + + public static final int getMouseWheelEventType(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return SWT.MouseHorizontalWheel; + case VERTICAL: + return SWT.MouseVerticalWheel; + default: + throw new IllegalStateException(); + } + } + + public static final int getPixel(final MouseEvent event, final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return event.x; + case VERTICAL: + return event.y; + default: + throw new IllegalStateException(); + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/CellLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/CellLayerPainter.java index de4d0a6b..ca178d69 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/CellLayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/CellLayerPainter.java @@ -11,10 +11,10 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.layer; +package org.eclipse.statet.ecommons.waltable.core.swt.painters; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; import java.util.Collection; @@ -25,26 +25,30 @@ import java.util.Map; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; -public class CellLayerPainter implements ILayerPainter { +@NonNullByDefault +public class CellLayerPainter implements LayerPainter { - protected static final long getEndPosition(final ILayerDim dim, final int pixel) { - final long positionByPixel= dim.getPositionByPixel(pixel); + public static final long getEndPosition(final LayerDim layerDim, final int pixel) { + final long positionByPixel= layerDim.getPositionByPixel(pixel); return ((positionByPixel > 0) ? - Math.min(dim.getPositionCount(), positionByPixel) : - dim.getPositionCount() ); + Math.min(layerDim.getPositionCount(), positionByPixel) : + layerDim.getPositionCount() ); } - private static Map<Long, Long> calculateDimensionInfo(final ILayerDim dim, + private static Map<Long, Long> calculateDimensionInfo(final LayerDim dim, final long startPosition, final long endPosition) { final Map<Long, Long> positionToPixelMap= new HashMap<>(); long start2= (startPosition > 0) ? @@ -63,7 +67,7 @@ public class CellLayerPainter implements ILayerPainter { return positionToPixelMap; } - private static long getPositionStart(final ILayerDim dim, final long position, + private static long getPositionStart(final LayerDim dim, final long position, final Map<Long, Long> positionToPixelMap) { if (position < dim.getPositionCount()) { Long start= positionToPixelMap.get(position); @@ -86,15 +90,26 @@ public class CellLayerPainter implements ILayerPainter { } - private ILayer natLayer; + private Layer natLayer; private Map<Long, Long> horizontalPositionToPixelMap; private Map<Long, Long> verticalPositionToPixelMap; + @SuppressWarnings("null") + public CellLayerPainter() { + } + + + @Override + public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, + final LRectangle cellBounds) { + return cellBounds; + } + @Override - public void paintLayer(final ILayer natLayer, final GC gc, final int xOffset, final int yOffset, - final Rectangle pixelRectangle, final IConfigRegistry configRegistry) { + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, + final Rectangle pixelRectangle, final ConfigRegistry configRegistry) { if (pixelRectangle.isEmpty()) { return; } @@ -104,11 +119,11 @@ public class CellLayerPainter implements ILayerPainter { calculateDimensionInfo(positionRectangle); - final Collection<ILayerCell> spannedCells= new HashSet<>(); + final Collection<LayerCell> spannedCells= new HashSet<>(); for (long columnPosition= positionRectangle.x; columnPosition < positionRectangle.x + positionRectangle.width; columnPosition++) { for (long rowPosition= positionRectangle.y; rowPosition < positionRectangle.y + positionRectangle.height; rowPosition++) { - final ILayerCell cell= natLayer.getCellByPosition(columnPosition, rowPosition); + final LayerCell cell= natLayer.getCellByPosition(columnPosition, rowPosition); if (cell != null) { if (cell.isSpannedCell()) { spannedCells.add(cell); @@ -120,7 +135,7 @@ public class CellLayerPainter implements ILayerPainter { } } - for (final ILayerCell cell : spannedCells) { + for (final LayerCell cell : spannedCells) { paintCell(cell, gc, configRegistry); } } @@ -134,12 +149,7 @@ public class CellLayerPainter implements ILayerPainter { positionRectangle.y, positionRectangle.y + positionRectangle.height); } - @Override - public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, final LRectangle cellBounds) { - return cellBounds; - } - - protected LRectangle getPositionRectangleFromPixelRectangle(final ILayer natLayer, final Rectangle pixelRectangle) { + protected LRectangle getPositionRectangleFromPixelRectangle(final Layer natLayer, final Rectangle pixelRectangle) { final long columnPositionOffset= natLayer.getColumnPositionByX(pixelRectangle.x); final long rowPositionOffset= natLayer.getRowPositionByY(pixelRectangle.y); final long numColumns= natLayer.getColumnPositionByX(Math.min(natLayer.getWidth(), pixelRectangle.x + pixelRectangle.width) - 1) - columnPositionOffset + 1; @@ -153,15 +163,15 @@ public class CellLayerPainter implements ILayerPainter { return new LRectangle(columnPositionOffset, rowPositionOffset, numColumns, numRows); } - protected void paintCell(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { - final ILayer layer= cell.getLayer(); + protected void paintCell(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { + final Layer layer= cell.getLayer(); final long columnPosition= cell.getColumnPosition(); final long rowPosition= cell.getRowPosition(); - final ICellPainter cellPainter= configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, - cell.getDisplayMode(), cell.getConfigLabels().getLabels() ); + final LayerCellPainter layerCellPainter= configRegistry.getAttribute(CellConfigAttributes.CELL_PAINTER, + cell.getDisplayMode(), cell.getLabels().getLabels() ); final LRectangle adjustedCellBounds= layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, cell.getBounds()); - if (cellPainter != null) { + if (layerCellPainter != null) { final Rectangle originalClipping= gc.getClipping(); final long startX= getColumnPositionStart(columnPosition); @@ -175,7 +185,7 @@ public class CellLayerPainter implements ILayerPainter { // LRectangle adjustedClipBounds= layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, clipBounds); gc.setClipping(safe(adjustedClipBounds)); - cellPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry); + layerCellPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry); gc.setClipping(originalClipping); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/GridLineCellLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/GridLineCellLayerPainter.java index d37c61a6..f5d21fdb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/GridLineCellLayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/GridLineCellLayerPainter.java @@ -11,70 +11,65 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.layer; +package org.eclipse.statet.ecommons.waltable.core.swt.painters; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; +import java.util.function.Function; + import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.style.GridStyling.ConfigGridLineColorSupplier; +@NonNullByDefault public class GridLineCellLayerPainter extends CellLayerPainter { - private final Color gridColor; + private final Function<ConfigRegistry, Color> gridLineColorSupplier; - public GridLineCellLayerPainter(final Color gridColor) { - this.gridColor= gridColor; + public GridLineCellLayerPainter(final Function<ConfigRegistry, Color> gridLineColorSupplier) { + this.gridLineColorSupplier= gridLineColorSupplier; } public GridLineCellLayerPainter() { - this.gridColor= GUIHelper.COLOR_GRAY; + this(new ConfigGridLineColorSupplier()); } - public Color getGridColor() { - return this.gridColor; + @Override + public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, + final LRectangle bounds) { + return new LRectangle(bounds.x, bounds.y, Math.max(bounds.width - 1, 0), Math.max(bounds.height - 1, 0)); } - @Override - public void paintLayer(final ILayer natLayer, final GC gc, + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, final Rectangle pixelRectangle, - final IConfigRegistry configRegistry) { - //Draw GridLines - drawGridLines(natLayer, gc, pixelRectangle); + final ConfigRegistry configRegistry) { + gc.setForeground(this.gridLineColorSupplier.apply(configRegistry)); + drawHorizontalLines(natLayer, gc, pixelRectangle); + drawVerticalLines(natLayer, gc, pixelRectangle); super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry); } - @Override - public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, final LRectangle bounds) { - return new LRectangle(bounds.x, bounds.y, Math.max(bounds.width - 1, 0), Math.max(bounds.height - 1, 0)); - } - - protected void drawGridLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { - gc.setForeground(this.gridColor); - - drawHorizontalLines(natLayer, gc, rectangle); - drawVerticalLines(natLayer, gc, rectangle); - } - - private void drawHorizontalLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { + protected void drawHorizontalLines(final Layer natLayer, final GC gc, final Rectangle rectangle) { final int startX= safe(rectangle.x); final int endX= safe(rectangle.x + Math.min(natLayer.getWidth() - 1, rectangle.width)); - final ILayerDim dim= natLayer.getDim(VERTICAL); + final LayerDim dim= natLayer.getDim(VERTICAL); final long endPosition= Math.min(dim.getPositionCount(), dim.getPositionByPixel(rectangle.y + rectangle.height - 1) + 1); for (long position= dim.getPositionByPixel(rectangle.y); position < endPosition; position++) { final int size= dim.getPositionSize(position); @@ -85,11 +80,11 @@ public class GridLineCellLayerPainter extends CellLayerPainter { } } - private void drawVerticalLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { + protected void drawVerticalLines(final Layer natLayer, final GC gc, final Rectangle rectangle) { final int startY= safe(rectangle.y); final int endY= safe(rectangle.y + Math.min(natLayer.getHeight() - 1, rectangle.height)); - final ILayerDim dim= natLayer.getDim(HORIZONTAL); + final LayerDim dim= natLayer.getDim(HORIZONTAL); final long endPosition= Math.min(dim.getPositionCount(), dim.getPositionByPixel(rectangle.x + rectangle.width - 1) + 1); for (long position= dim.getPositionByPixel(rectangle.x); position < endPosition; position++) { final long size= dim.getPositionSize(position); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/NatGridLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/TableGridLayerPainter.java index 3a07c849..ef270ae8 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/NatGridLayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/TableGridLayerPainter.java @@ -11,40 +11,40 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.layer; +package org.eclipse.statet.ecommons.waltable.core.swt.painters; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; -public class NatGridLayerPainter extends NatLayerPainter { +@NonNullByDefault +public class TableGridLayerPainter extends TableLayerPainter { private final Color gridColor; - public NatGridLayerPainter(final NatTable natTable) { - this(natTable, GUIHelper.COLOR_GRAY); - } - - public NatGridLayerPainter(final NatTable natTable, final Color gridColor) { + public TableGridLayerPainter(final NatTable natTable, final Color gridColor) { super(natTable); this.gridColor= gridColor; } @Override - protected void paintBackground(final ILayer natLayer, final GC gc, final long xOffset, final long yOffset, final org.eclipse.swt.graphics.Rectangle rectangle, final IConfigRegistry configRegistry) { + protected void paintBackground(final Layer natLayer, final GC gc, final long xOffset, final long yOffset, + final Rectangle rectangle, final ConfigRegistry configRegistry) { super.paintBackground(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); gc.setForeground(this.gridColor); @@ -52,11 +52,12 @@ public class NatGridLayerPainter extends NatLayerPainter { drawVerticalLines(natLayer, gc, rectangle); } - private void drawHorizontalLines(final ILayer natLayer, final GC gc, final org.eclipse.swt.graphics.Rectangle rectangle) { + private void drawHorizontalLines(final Layer natLayer, final GC gc, + final Rectangle rectangle) { final int startX= rectangle.x; final int endX= rectangle.x + rectangle.width; - final ILayerDim dim= natLayer.getDim(VERTICAL); + final LayerDim dim= natLayer.getDim(VERTICAL); final long endPosition= CellLayerPainter.getEndPosition(dim, rectangle.y + rectangle.height); for (long position= dim.getPositionByPixel(rectangle.y); position < endPosition; position++) { final int size= dim.getPositionSize(position); @@ -67,11 +68,12 @@ public class NatGridLayerPainter extends NatLayerPainter { } } - private void drawVerticalLines(final ILayer natLayer, final GC gc, final org.eclipse.swt.graphics.Rectangle rectangle) { + private void drawVerticalLines(final Layer natLayer, final GC gc, + final Rectangle rectangle) { final int startY= rectangle.y; final int endY= rectangle.y + rectangle.height; - final ILayerDim dim= natLayer.getDim(HORIZONTAL); + final LayerDim dim= natLayer.getDim(HORIZONTAL); final long endPosition= CellLayerPainter.getEndPosition(dim, rectangle.x + rectangle.width); for (long position= dim.getPositionByPixel(rectangle.x); position < endPosition; position++) { final int size= dim.getPositionSize(position); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/NatLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/TableLayerPainter.java index 64b292e7..0fde1d7e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/layer/NatLayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/core/swt/painters/TableLayerPainter.java @@ -11,74 +11,83 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.painter.layer; +package org.eclipse.statet.ecommons.waltable.core.swt.painters; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.painter.IOverlayPainter; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.top.OverlayPainter; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; -public class NatLayerPainter implements ILayerPainter { +@NonNullByDefault +public class TableLayerPainter implements LayerPainter { private final NatTable natTable; - public NatLayerPainter(final NatTable natTable) { + public TableLayerPainter(final NatTable natTable) { this.natTable= natTable; } @Override - public void paintLayer(final ILayer natLayer, final GC gc, + public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, + final LRectangle cellBounds) { + final var layerPainter= this.natTable.getUnderlyingLayer().getLayerPainter(); + return layerPainter.adjustCellBounds(columnPosition, rowPosition, cellBounds); + } + + @Override + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, final Rectangle pixelRectangle, - final IConfigRegistry configRegistry) { + final ConfigRegistry configRegistry) { try { paintBackground(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry); gc.setForeground(this.natTable.getForeground()); - final Rectangle paintRectangle= pixelRectangle.intersection(SWTUtil.toSWT( + final Rectangle paintRectangle= pixelRectangle.intersection(SwtUtils.toSWT( new LRectangle(xOffset, yOffset, natLayer.getWidth(), natLayer.getHeight()) )); if (!paintRectangle.isEmpty()) { - this.natTable.getLayer().getLayerPainter().paintLayer(natLayer, gc, - xOffset, yOffset, paintRectangle, configRegistry ); + final var layerPainter= this.natTable.getUnderlyingLayer().getLayerPainter(); + layerPainter.paintLayer(natLayer, gc, xOffset, yOffset, + paintRectangle, configRegistry ); } paintOverlays(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry); - } catch (final Exception e) { + } + catch (final Exception e) { WaLTablePlugin.log(new Status(IStatus.ERROR, WaLTablePlugin.BUNDLE_ID, "An error occurred while painting the table.", e )); } } - protected void paintBackground(final ILayer natLayer, final GC gc, final long xOffset, final long yOffset, final org.eclipse.swt.graphics.Rectangle rectangle, final IConfigRegistry configRegistry) { + protected void paintBackground(final Layer natLayer, final GC gc, final long xOffset, final long yOffset, + final Rectangle rectangle, final ConfigRegistry configRegistry) { gc.setBackground(this.natTable.getBackground()); // Clean Background gc.fillRectangle(rectangle); } - protected void paintOverlays(final ILayer natLayer, final GC gc, final long xOffset, final long yOffset, final org.eclipse.swt.graphics.Rectangle rectangle, final IConfigRegistry configRegistry) { - for (final IOverlayPainter overlayPainter : this.natTable.getOverlayPainters()) { + protected void paintOverlays(final Layer natLayer, final GC gc, final long xOffset, final long yOffset, + final Rectangle rectangle, final ConfigRegistry configRegistry) { + for (final OverlayPainter overlayPainter : this.natTable.getOverlayPainters()) { overlayPainter.paintOverlay(gc, this.natTable); } } - @Override - public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, final LRectangle cellBounds) { - final ILayerPainter layerPainter= this.natTable.getLayer().getLayerPainter(); - return layerPainter.adjustCellBounds(columnPosition, rowPosition, cellBounds); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/AbstractFilterListDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/AbstractFilterListDataProvider.java deleted file mode 100644 index 04910351..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/AbstractFilterListDataProvider.java +++ /dev/null @@ -1,137 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.data; - -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; - - -/** - * Enables the use of a {@link List} containing POJO(s) as a backing data source. - * - * By default a bean at position 'X' in the list is displayed in - * row 'X' in the table. The properties of the bean are used to - * populate the columns. A {@link IColumnPropertyResolver} is used to - * retrieve column data from the bean properties. - * - * By implementing filter logic within {@link AbstractFilterListDataProvider#show(Object)} - * it is possible to create a static filter. All data access methods will skip invisible - * items within the wrapped list and delegate access to the visible items. - * - * NOTE: This way of static filtering can cause performance issues for huge data sets - * where a lot of items are filtered, because data access will always calculate the visible row - * position. Trying to use a caching mechanism would create some issues for deleting or inserting - * new data to the wrapped list. - * - * TODO add caching that reacts on insert/delete actions on the wrapped list - * - * @param <T> type of the Objects in the backing list. - * @see IColumnPropertyResolver - */ -public abstract class AbstractFilterListDataProvider<T> extends ListDataProvider<T> { - - public AbstractFilterListDataProvider(final List<T> list, final IColumnAccessor<T> columnAccessor) { - super(list, columnAccessor); - } - - /** - * Iterates over the whole list of data objects and checks the visibility for - * every object. The number of non visible items will be subtracted from the - * size of the wrapped list to return the number of visible items. - */ - @Override - public long getRowCount() { - long numberOfInvisible= 0; - for (final T object : this.list) { - if (!show(object)) { - numberOfInvisible++; - } - } - return this.list.size() - numberOfInvisible; - } - - /** - * Get the data value for the columnIndex and the visible rowIndex. - */ - @Override - public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, final IProgressMonitor monitor) { - final T rowObj= getRowObject(rowIndex); - return this.columnAccessor.getDataValue(rowObj, columnIndex); - } - - /** - * Set the data value for the columnIndex and the visible rowIndex. - */ - @Override - public void setDataValue(final long columnIndex, final long rowIndex, final Object newValue) { - final T rowObj= getRowObject(rowIndex); - this.columnAccessor.setDataValue(rowObj, columnIndex, newValue); - } - - /** - * Returns the object for the visible rowIndex. - * To do this it is iterated over the wrapped list, taking the invisible - * items into account, so the real row index for the given visible row index - * is calculated. - */ - @Override - public T getRowObject(final long rowIndex) { - if (rowIndex >= Integer.MAX_VALUE) { - return null; - } - T object= null; - long count= 0; - int realRowIndex= 0; - while (count <= rowIndex) { - object= this.list.get(realRowIndex); - if (show(object)) { - count++; - } - realRowIndex++; - } - - return object; - } - - /** - * Returns the visible rowIndex for the given object. - * To do this the real row index for the object within the wrapped list - * is searched and then all invisible items are subtracted from the - * real row index to calculate the visible row index. - */ - @Override - public long indexOfRowObject(final T rowObject) { - final int realRowIndex= this.list.indexOf(rowObject); - int filteredIndex= realRowIndex; - //now find number of not visible items - T vf= null; - for (int i= 0; i <= realRowIndex; i++) { - vf= this.list.get(i); - if (!show(vf)) { - filteredIndex--; - } - } - return filteredIndex; - } - - /** - * Within this method the filter logic should be applied. - * Return false if the object should not be visible within the grid. - * Return true if it should be visible. - * @param object The object that should be checked. - * @return true if the object should be visible, false if not - */ - protected abstract boolean show(T object); -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ExtendedReflectiveColumnPropertyAccessor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ExtendedReflectiveColumnPropertyAccessor.java deleted file mode 100644 index 1ae870cd..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ExtendedReflectiveColumnPropertyAccessor.java +++ /dev/null @@ -1,157 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.data; - -import java.lang.reflect.Method; -import java.util.Locale; - - -public class ExtendedReflectiveColumnPropertyAccessor<R> extends ReflectiveColumnPropertyAccessor<R> { - - /** - * @param propertyNames of the members of the row bean - */ - public ExtendedReflectiveColumnPropertyAccessor(final String[] propertyNames) { - super(propertyNames); - } - - @Override - public Object getDataValue(final R rowObj, final long columnIndex) { - final String propertyName= getColumnProperty(columnIndex); - if (propertyName.contains(".")) { //$NON-NLS-1$ - return getPropertyValue(rowObj, propertyName); - } - else { - return super.getDataValue(rowObj, columnIndex); - } - } - - @Override - public void setDataValue(final R rowObj, final long columnIndex, final Object newValue) { - final String propertyName= getColumnProperty(columnIndex); - if (propertyName.contains(".")) { //$NON-NLS-1$ - setPropertyValue(rowObj, propertyName, newValue); - } - else { - super.setDataValue(rowObj, columnIndex, newValue); - } - } - - - /** - * Reads the value of a property out of a given bean via reflection. - * @param object the bean out of which the property value should be read - * @param propertyName the name of the property which value should be read - * @return the property value of the bean - */ - private Object getPropertyValue(final Object object, final String propertyName) { - assert object != null : "object can not be null!"; //$NON-NLS-1$ - - String[] propertyChain= null; - if (propertyName.contains(".")) { //$NON-NLS-1$ - propertyChain= propertyName.split("\\."); //$NON-NLS-1$ - } - else { - propertyChain= new String[] {propertyName}; - } - - Object child= object; - Class<?> objectClass= object.getClass(); - String getterName= null; - Method getterMethod= null; - for (final String pc : propertyChain) { - getterName= "get" + pc.substring(0, 1).toUpperCase(Locale.ROOT) + pc.substring(1); //$NON-NLS-1$ - try { - getterMethod= objectClass.getMethod(getterName); - child= getterMethod.invoke(child); - } - catch (final NoSuchMethodException e) { - try { - getterName= "is" + pc.substring(0, 1).toUpperCase(Locale.ROOT) + pc.substring(1); //$NON-NLS-1$ - getterMethod= objectClass.getMethod(getterName); - child= getterMethod.invoke(child); - } - catch (final Exception e1) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - catch (final Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - if (child != null) { - objectClass= child.getClass(); - } - else { - //null is returned by reflection, therefore we can not go further - //and null is the correct return value - break; - } - } - - return child; - } - - /** - * Sets a value to the property of a bean via reflection. - * Also supports dot separated property names to access properties anywhere within the - * object graph. - * @param object the bean where the property value should be set - * @param propertyName the name of the property which should be set - * @param value the value to set - */ - private void setPropertyValue(final Object object, final String propertyName, final Object value) { - assert object != null : "object can not be null!"; //$NON-NLS-1$ - - try { - Object singlePropertyObject= null; - String singlePropertyName= null; - if (propertyName.contains(".")) { //$NON-NLS-1$ - singlePropertyObject= - getPropertyValue(object, propertyName.substring(0, propertyName.lastIndexOf("."))); //$NON-NLS-1$ - singlePropertyName= propertyName.substring(propertyName.lastIndexOf(".") + 1); //$NON-NLS-1$ - } - else { - singlePropertyObject= object; - singlePropertyName= propertyName; - } - - - final String setterName= "set" //$NON-NLS-1$ - + singlePropertyName.substring(0, 1).toUpperCase() - + singlePropertyName.substring(1); - Method setterMethod= null; - if (value != null) { - setterMethod= singlePropertyObject.getClass().getMethod(setterName, new Class<?>[] {value.getClass()}); - } - else { - //as the value is null we can not access the setter method directly - //and have to search for the method - final Method[] methods= singlePropertyObject.getClass().getMethods(); - for (final Method m : methods) { - if (m.getName().equals(setterName)) { - setterMethod= m; - } - } - } - setterMethod.invoke(singlePropertyObject, value); - } catch (final Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IRowDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IRowDataProvider.java deleted file mode 100644 index 41f783af..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IRowDataProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.data; - - -public interface IRowDataProvider<T> extends IDataProvider { - - - T getRowObject(long rowIndex); - - long indexOfRowObject(T rowObject); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/DisplayConverter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/DisplayConverter.java index 76e1b386..3e3dcbf9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/DisplayConverter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/DisplayConverter.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.data.convert; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public abstract class DisplayConverter implements IDisplayConverter { @@ -24,12 +24,12 @@ public abstract class DisplayConverter implements IDisplayConverter { public abstract Object displayToCanonicalValue(Object displayValue); @Override - public Object canonicalToDisplayValue(final ILayerCell cell, final IConfigRegistry configRegistry, final Object canonicalValue) { + public Object canonicalToDisplayValue(final LayerCell cell, final ConfigRegistry configRegistry, final Object canonicalValue) { return canonicalToDisplayValue(canonicalValue); } @Override - public Object displayToCanonicalValue(final ILayerCell cell, final IConfigRegistry configRegistry, final Object displayValue) { + public Object displayToCanonicalValue(final LayerCell cell, final ConfigRegistry configRegistry, final Object displayValue) { return displayToCanonicalValue(displayValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/IDisplayConverter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/IDisplayConverter.java index ffa51ea4..f247c04f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/IDisplayConverter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/IDisplayConverter.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.data.convert; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -35,7 +35,7 @@ public interface IDisplayConverter { * Typically converted to a String for display. * Use this method for contextual conversion. */ - public Object canonicalToDisplayValue(ILayerCell cell, IConfigRegistry configRegistry, Object canonicalValue); + public Object canonicalToDisplayValue(LayerCell cell, ConfigRegistry configRegistry, Object canonicalValue); /** * Convert from display value to value in the backing data structure. @@ -44,6 +44,6 @@ public interface IDisplayConverter { * in the setter of the backing bean/row object * Use this method for contextual conversion. */ - public Object displayToCanonicalValue(ILayerCell cell, IConfigRegistry configRegistry, Object displayValue); + public Object displayToCanonicalValue(LayerCell cell, ConfigRegistry configRegistry, Object displayValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/PercentageDisplayConverter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/PercentageDisplayConverter.java index b962e1a1..5df96a11 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/PercentageDisplayConverter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/convert/PercentageDisplayConverter.java @@ -34,7 +34,7 @@ public class PercentageDisplayConverter extends DisplayConverter { displayString= displayString.substring(0, displayString.length() - 1); } displayString= displayString.trim(); - final int displayInt= Integer.valueOf(displayString).intValue(); + final int displayInt= Integer.parseInt(displayString); final double percentageValue= (double) displayInt / 100; return Double.valueOf(percentageValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/ContextualDataValidator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/ContextualDataValidator.java index 6df5002b..07d1433f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/ContextualDataValidator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/ContextualDataValidator.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.data.validate; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public abstract class ContextualDataValidator implements IDataValidator { @@ -27,6 +27,6 @@ public abstract class ContextualDataValidator implements IDataValidator { } @Override - public abstract boolean validate(ILayerCell cell, IConfigRegistry configRegistry, Object newValue); + public abstract boolean validate(LayerCell cell, ConfigRegistry configRegistry, Object newValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/DataValidator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/DataValidator.java index 6427cdd3..cee4dca5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/DataValidator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/DataValidator.java @@ -13,18 +13,18 @@ package org.eclipse.statet.ecommons.waltable.data.validate; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public abstract class DataValidator implements IDataValidator { @Override - public boolean validate(final ILayerCell cell, final IConfigRegistry configRegistry, final Object newValue) { + public boolean validate(final LayerCell cell, final ConfigRegistry configRegistry, final Object newValue) { return validate(cell.getDim(HORIZONTAL).getId(), cell.getDim(VERTICAL).getId(), newValue ); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/IDataValidator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/IDataValidator.java index 9c859df6..e4e9b7b3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/IDataValidator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/validate/IDataValidator.java @@ -13,11 +13,11 @@ package org.eclipse.statet.ecommons.waltable.data.validate; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.edit.editor.TextCellEditor; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; public interface IDataValidator { @@ -31,7 +31,7 @@ public interface IDataValidator { * will be converted to the canonical value using the {@link IDisplayConverter} * before it hits this method * - * @see IDataProvider#getDataValue(int, int) + * @see DataProvider#getDataValue(int, int) * * @return true is newValue is valid. False otherwise. */ @@ -46,16 +46,16 @@ public interface IDataValidator { * will be converted to the canonical value using the {@link IDisplayConverter} * before it hits this method * - * @see IDataProvider#getDataValue(int, int) + * @see DataProvider#getDataValue(int, int) * * @return true is newValue is valid. False otherwise. */ - public boolean validate(ILayerCell cell, IConfigRegistry configRegistry, Object newValue); + public boolean validate(LayerCell cell, ConfigRegistry configRegistry, Object newValue); public static final IDataValidator ALWAYS_VALID= new IDataValidator() { @Override - public boolean validate(final ILayerCell cell, final IConfigRegistry configRegistry, final Object newValue) { + public boolean validate(final LayerCell cell, final ConfigRegistry configRegistry, final Object newValue) { return true; } @@ -69,7 +69,7 @@ public interface IDataValidator { public static final IDataValidator NEVER_VALID= new IDataValidator() { @Override - public boolean validate(final ILayerCell cell, final IConfigRegistry configRegistry, final Object newValue) { + public boolean validate(final LayerCell cell, final ConfigRegistry configRegistry, final Object newValue) { return false; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/DialogEditHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/DialogEditHandler.java index 24b65a49..872b716a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/DialogEditHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/DialogEditHandler.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.edit; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommand.java index e40abe68..f2f7accb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommand.java @@ -15,9 +15,9 @@ package org.eclipse.statet.ecommons.waltable.edit; import org.eclipse.swt.widgets.Composite; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -29,13 +29,13 @@ import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; public class EditCellCommand extends AbstractContextFreeCommand { /** - * The {@link IConfigRegistry} containing the configuration of the current NatTable + * The {@link ConfigRegistry} containing the configuration of the current NatTable * instance the command should be executed for. * <p> * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; /** * The parent Composite, needed for the creation of the editor control. */ @@ -43,28 +43,28 @@ public class EditCellCommand extends AbstractContextFreeCommand { /** * The cell that should be put in edit mode. */ - private final ILayerCell cell; + private final LayerCell cell; /** * * @param parent The parent Composite, needed for the creation of the editor control. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. * @param cell The cell that should be put into the edit mode. */ - public EditCellCommand(final Composite parent, final IConfigRegistry configRegistry, final ILayerCell cell) { + public EditCellCommand(final Composite parent, final ConfigRegistry configRegistry, final LayerCell cell) { this.configRegistry= configRegistry; this.parent= parent; this.cell= cell; } /** - * @return The {@link IConfigRegistry} containing the configuration of the current NatTable + * @return The {@link ConfigRegistry} containing the configuration of the current NatTable * instance the command should be executed for. */ - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } @@ -78,7 +78,7 @@ public class EditCellCommand extends AbstractContextFreeCommand { /** * @return The cell that should be put in edit mode. */ - public ILayerCell getCell() { + public LayerCell getCell() { return this.cell; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommandHandler.java index 355f19ee..a9d21ea4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditCellCommandHandler.java @@ -15,11 +15,11 @@ package org.eclipse.statet.ecommons.waltable.edit; import org.eclipse.swt.widgets.Composite; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IEditableRule; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -37,14 +37,14 @@ public class EditCellCommandHandler extends AbstractLayerCommandHandler<EditCell @Override public boolean doCommand(final EditCellCommand command) { - final ILayerCell cell= command.getCell(); + final LayerCell cell= command.getCell(); final Composite parent= command.getParent(); - final IConfigRegistry configRegistry= command.getConfigRegistry(); + final ConfigRegistry configRegistry= command.getConfigRegistry(); //check if the cell is editable - final IEditableRule rule= configRegistry.getConfigAttribute( + final IEditableRule rule= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, - DisplayMode.EDIT, cell.getConfigLabels().getLabels()); + DisplayMode.EDIT, cell.getLabels().getLabels()); if (rule.isEditable(cell, configRegistry)) { EditController.editCell(cell, parent, cell.getDataValue(0, null), configRegistry); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigAttributes.java index fd7b8b1f..85b4c54a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigAttributes.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigAttributes.java @@ -16,14 +16,14 @@ package org.eclipse.statet.ecommons.waltable.edit; import java.util.List; import java.util.Map; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IEditableRule; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; import org.eclipse.statet.ecommons.waltable.edit.editor.IEditErrorHandler; import org.eclipse.statet.ecommons.waltable.edit.gui.ICellEditDialog; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** @@ -70,7 +70,7 @@ public interface EditConfigAttributes { * Note: Currently this configuration attribute is only evaluated by the TextCellEditor in combination * with the RenderErrorHandling for just in time conversion error rendering. */ - public static final ConfigAttribute<IStyle> CONVERSION_ERROR_STYLE= new ConfigAttribute<>(); + public static final ConfigAttribute<Style> CONVERSION_ERROR_STYLE= new ConfigAttribute<>(); /** * The configuration attribute for the style that should be used on just in time validation error @@ -79,13 +79,13 @@ public interface EditConfigAttributes { * Note: Currently this configuration attribute is only evaluated by the TextCellEditor in combination * with the RenderErrorHandling for just in time validation error rendering. */ - public static final ConfigAttribute<IStyle> VALIDATION_ERROR_STYLE= new ConfigAttribute<>(); + public static final ConfigAttribute<Style> VALIDATION_ERROR_STYLE= new ConfigAttribute<>(); /** * The configuration attribute to specify if cell editors should be opened inline or in a dialog. * If this configuration is not set, the editors will open inline, unless the editors themself * specify different behaviour. - * @see ICellEditor#openInline(IConfigRegistry configRegistry, List configLabels) + * @see ICellEditor#openInline(ConfigRegistry configRegistry, List configLabels) */ public static final ConfigAttribute<Boolean> OPEN_IN_DIALOG= new ConfigAttribute<>(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigHelper.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigHelper.java index 13e59737..f12609c6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigHelper.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditConfigHelper.java @@ -15,36 +15,36 @@ package org.eclipse.statet.ecommons.waltable.edit; import java.util.List; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; import org.eclipse.statet.ecommons.waltable.edit.config.LoggingErrorHandling; import org.eclipse.statet.ecommons.waltable.edit.editor.IEditErrorHandler; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; /** - * Helper class that will retrieve edit configuration values out of the {@link IConfigRegistry}. + * Helper class that will retrieve edit configuration values out of the {@link ConfigRegistry}. */ public class EditConfigHelper { /** * Searches for the registered {@link IEditErrorHandler} that should be used by this editor. - * @param configRegistry The {@link ConfigRegistry} of the NatTable instance this editor is connected to. + * @param configRegistry The {@link BasicConfigRegistry} of the NatTable instance this editor is connected to. * @param configAttribute The config attribute specifying if the {@link IEditErrorHandler} for conversion * or validation errors is requested. * @param configLabels The config labels attached to the cell this editor is opened for, needed to - * find the registered {@link IEditErrorHandler} in {@link ConfigRegistry}. - * @return The registered {@link IEditErrorHandler} out of the specified {@link ConfigRegistry} for + * find the registered {@link IEditErrorHandler} in {@link BasicConfigRegistry}. + * @return The registered {@link IEditErrorHandler} out of the specified {@link BasicConfigRegistry} for * the config attribute and config labels, or the {@link LoggingErrorHandling} if no other * {@link IEditErrorHandler} is registered. * @see EditConfigAttributes#CONVERSION_ERROR_HANDLER * @see EditConfigAttributes#VALIDATION_ERROR_HANDLER */ public static IEditErrorHandler getEditErrorHandler( - final IConfigRegistry configRegistry, final ConfigAttribute<IEditErrorHandler> configAttribute, final List<String> configLabels) { + final ConfigRegistry configRegistry, final ConfigAttribute<IEditErrorHandler> configAttribute, final List<String> configLabels) { - IEditErrorHandler errorHandler= configRegistry.getConfigAttribute(configAttribute, DisplayMode.EDIT, configLabels); + IEditErrorHandler errorHandler= configRegistry.getAttribute(configAttribute, DisplayMode.EDIT, configLabels); if (errorHandler == null) { //set LoggingErrorHandling as default errorHandler= new LoggingErrorHandling(); @@ -61,8 +61,8 @@ public class EditConfigHelper { * <p>There might be editors that are only able to be opened in a dialog. These implementations * need to override this method to always return <code>false</code>, so the editor never * gets opened inline.</p> - * @param configRegistry The {@link IConfigRegistry} to retrieve the configuration for - * inline/dialog editing out of. Needed here because the instance {@link IConfigRegistry} + * @param configRegistry The {@link ConfigRegistry} to retrieve the configuration for + * inline/dialog editing out of. Needed here because the instance {@link ConfigRegistry} * might not be set on calling this method. * @param configLabels The labels out of the LabelStack of the cell whose editor should be activated. * Needed here because this method needs to be called prior to activation to determine @@ -71,8 +71,8 @@ public class EditConfigHelper { * if not. * @see EditConfigAttributes#OPEN_IN_DIALOG */ - public static boolean openInline(final IConfigRegistry configRegistry, final List<String> configLabels) { - final Boolean openInDialog= configRegistry.getConfigAttribute( + public static boolean openInline(final ConfigRegistry configRegistry, final List<String> configLabels) { + final Boolean openInDialog= configRegistry.getAttribute( EditConfigAttributes.OPEN_IN_DIALOG, DisplayMode.EDIT, configLabels); return (openInDialog == null || !openInDialog); } @@ -85,8 +85,8 @@ public class EditConfigHelper { * the configuration attribute {@link EditConfigAttributes#SUPPORT_MULTI_EDIT}. * <p>You should consider returning <code>false</code> e.g. if the update operation is complex or * you use conditional validation, where a value is validated against another value in the data model. - * @param configRegistry The {@link IConfigRegistry} to retrieve the configuration for - * multi edit support out of. Needed here because the instance {@link IConfigRegistry} + * @param configRegistry The {@link ConfigRegistry} to retrieve the configuration for + * multi edit support out of. Needed here because the instance {@link ConfigRegistry} * might not be set on calling this method. * @param configLabels The labels out of the LabelStack of the cell whose editor should be activated. * Needed here because this method needs to be called prior to activation to determine @@ -95,8 +95,8 @@ public class EditConfigHelper { * if the multi editing of this kind of cell editor is not supported. * @see EditConfigAttributes#SUPPORT_MULTI_EDIT */ - public static boolean supportMultiEdit(final IConfigRegistry configRegistry, final List<String> configLabels) { - final Boolean supportMultiEdit= configRegistry.getConfigAttribute( + public static boolean supportMultiEdit(final ConfigRegistry configRegistry, final List<String> configLabels) { + final Boolean supportMultiEdit= configRegistry.getAttribute( EditConfigAttributes.SUPPORT_MULTI_EDIT, DisplayMode.EDIT, configLabels); return (supportMultiEdit == null || supportMultiEdit); } @@ -112,8 +112,8 @@ public class EditConfigHelper { * <p> * Note: It only makes sense to call this method if the editor is already activated. Calling this * method on an editor that has not been activated already will lead to exceptions.</p> - * @param configRegistry The {@link IConfigRegistry} to retrieve the configuration for - * multi edit support out of. Needed here because the instance {@link IConfigRegistry} + * @param configRegistry The {@link ConfigRegistry} to retrieve the configuration for + * multi edit support out of. Needed here because the instance {@link ConfigRegistry} * might not be set on calling this method. * @param configLabels The labels out of the LabelStack of the cell whose editor should be activated. * Needed here because this method needs to be called prior to activation to determine @@ -122,8 +122,8 @@ public class EditConfigHelper { * commit, <code>false</code> if not. * @see EditConfigAttributes#OPEN_ADJACENT_EDITOR */ - public static boolean openAdjacentEditor(final IConfigRegistry configRegistry, final List<String> configLabels) { - final Boolean openAdjacentEditor= configRegistry.getConfigAttribute( + public static boolean openAdjacentEditor(final ConfigRegistry configRegistry, final List<String> configLabels) { + final Boolean openAdjacentEditor= configRegistry.getAttribute( EditConfigAttributes.OPEN_ADJACENT_EDITOR, DisplayMode.EDIT, configLabels); return (openAdjacentEditor != null && openAdjacentEditor); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditController.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditController.java index 19af7736..4ce8fb7c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditController.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditController.java @@ -20,18 +20,19 @@ import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; import org.eclipse.statet.ecommons.waltable.edit.gui.CellEditDialogFactory; import org.eclipse.statet.ecommons.waltable.edit.gui.ICellEditDialog; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -52,29 +53,29 @@ public class EditController { * <code>cell.getDataValue()</code>, but for the special case that an editor * should be activated pressing a letter or digit key on the current selection, * the initial value should be the Character representing that key. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ public static void editCell( - final ILayerCell cell, final Composite parent, - final Object initialCanonicalValue, final IConfigRegistry configRegistry) { + final LayerCell cell, final Composite parent, + final Object initialCanonicalValue, final ConfigRegistry configRegistry) { try { //determine the position of the cell to put into edit mode final LRectangle cellBounds= cell.getBounds(); - final ILayer layer= cell.getLayer(); + final Layer layer= cell.getLayer(); final long columnPosition= cell.getColumnPosition(); final long rowPosition= cell.getRowPosition(); //read the configuration for the specified cell for //- which editor to use for that cell - final List<String> configLabels= cell.getConfigLabels().getLabels(); + final List<String> configLabels= cell.getLabels().getLabels(); //check which editor to use - final ICellEditor cellEditor= configRegistry.getConfigAttribute( + final ICellEditor cellEditor= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels); if (cellEditor.openInline(configRegistry, configLabels)) { @@ -84,7 +85,7 @@ public class EditController { columnPosition, rowPosition); - org.eclipse.swt.graphics.Rectangle editorBounds= SWTUtil.toSWT( + Rectangle editorBounds= SwtUtils.toSWT( layer.getLayerPainter().adjustCellBounds( columnPosition, rowPosition, new LRectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height))); @@ -111,7 +112,7 @@ public class EditController { } } else { - final List<ILayerCell> cells= new ArrayList<>(); + final List<LayerCell> cells= new ArrayList<>(); cells.add(cell); editCells(cells, parent, initialCanonicalValue, configRegistry); } @@ -140,15 +141,15 @@ public class EditController { * control. Needed because for multi cell editing or editor activation by * letter/digit key will result in a different value to populate for some * editors than populating the value out of the cell/data model directly. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of + * @param configRegistry The {@link ConfigRegistry} containing the configuration of * the current NatTable instance the command should be executed for. This is * necessary because the edit controllers in the current architecture are not * aware of the instance they are running in and therefore it is needed for * activation of editors. */ public static void editCells( - final Collection<ILayerCell> cells, final Composite parent, - final Object initialCanonicalValue, final IConfigRegistry configRegistry) { + final Collection<LayerCell> cells, final Composite parent, + final Object initialCanonicalValue, final ConfigRegistry configRegistry) { if (cells != null && !cells.isEmpty()) { //get the editor to use, because the editor contains information if @@ -156,10 +157,10 @@ public class EditController { //Note: this works because previous to calling this method it is checked // if all cells have the same editor configured. Otherwise this method // will have serious issues further on. - final ICellEditor cellEditor= configRegistry.getConfigAttribute( + final ICellEditor cellEditor= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, - cells.iterator().next().getConfigLabels().getLabels()); + cells.iterator().next().getLabels().getLabels()); if (cells.size() == 1 || (cells.size() > 1 && supportMultiEdit(cells, cellEditor, configRegistry))) { @@ -174,12 +175,12 @@ public class EditController { final int returnValue= dialog.open(); if (returnValue == Window.OK) { - for (final ILayerCell selectedCell : cells) { + for (final LayerCell selectedCell : cells) { Object editorValue= dialog.getCommittedValue(); if (!(dialog.getEditType() == EditTypeEnum.SET)) { editorValue= dialog.calculateValue(selectedCell.getDataValue(0, null), editorValue); } - final ILayer layer= selectedCell.getLayer(); + final Layer layer= selectedCell.getLayer(); layer.doCommand(new UpdateDataCommand( layer, selectedCell.getColumnPosition(), selectedCell.getRowPosition(), editorValue)); @@ -193,7 +194,7 @@ public class EditController { //this only works for editors that have no interactive control for //editing, like for example the CheckBoxCellEditor that directly //changes the value and closes right away. - for (final ILayerCell cell : cells) { + for (final LayerCell cell : cells) { final ICellEditHandler editHandler= new InlineEditHandler( cell.getLayer(), cell.getColumnPosition(), @@ -218,7 +219,7 @@ public class EditController { * all cells are checked to be sure. * @param cells The selected cells that should be multi edited. * @param cellEditor The cell editor that is the same for every cell. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of + * @param configRegistry The {@link ConfigRegistry} containing the configuration of * the current NatTable instance the command should be executed for. This is * necessary because the edit controllers in the current architecture are not * aware of the instance they are running in and therefore it is needed for @@ -226,9 +227,9 @@ public class EditController { * @return <code>true</code> if the editor supports multi edit for all selected cells, * <code>false</code> if at least one cell does specify to not support multi edit. */ - private static boolean supportMultiEdit(final Collection<ILayerCell> cells, final ICellEditor cellEditor, final IConfigRegistry configRegistry) { - for (final ILayerCell cell : cells) { - if (!cellEditor.supportMultiEdit(configRegistry, cell.getConfigLabels().getLabels())) { + private static boolean supportMultiEdit(final Collection<LayerCell> cells, final ICellEditor cellEditor, final ConfigRegistry configRegistry) { + for (final LayerCell cell : cells) { + if (!cellEditor.supportMultiEdit(configRegistry, cell.getLabels().getLabels())) { return false; } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommand.java index c6633019..a6879890 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommand.java @@ -15,8 +15,8 @@ package org.eclipse.statet.ecommons.waltable.edit; import org.eclipse.swt.widgets.Composite; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; /** @@ -28,13 +28,13 @@ import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; public class EditSelectionCommand extends AbstractContextFreeCommand { /** - * The {@link IConfigRegistry} containing the configuration of the current NatTable + * The {@link ConfigRegistry} containing the configuration of the current NatTable * instance the command should be executed for. * <p> * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; /** * The Character represented by the key that was typed in case this command * should be executed because of typing a letter or digit key. Can be <code>null</code> @@ -49,18 +49,18 @@ public class EditSelectionCommand extends AbstractContextFreeCommand { /** * @param parent The parent Composite, needed for the creation of the editor control. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ - public EditSelectionCommand(final Composite parent, final IConfigRegistry configRegistry) { + public EditSelectionCommand(final Composite parent, final ConfigRegistry configRegistry) { this(parent, configRegistry, null); } /** * @param parent The parent Composite, needed for the creation of the editor control. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. @@ -69,17 +69,17 @@ public class EditSelectionCommand extends AbstractContextFreeCommand { * if this command should be executed because of a pressed control key (like F2) or a * programmatical execution. */ - public EditSelectionCommand(final Composite parent, final IConfigRegistry configRegistry, final Character character) { + public EditSelectionCommand(final Composite parent, final ConfigRegistry configRegistry, final Character character) { this.parent= parent; this.configRegistry= configRegistry; this.character= character; } /** - * @return The {@link IConfigRegistry} containing the configuration of the current NatTable + * @return The {@link ConfigRegistry} containing the configuration of the current NatTable * instance the command should be executed for. */ - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommandHandler.java index 165f8bb1..7fcbb866 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditSelectionCommandHandler.java @@ -17,11 +17,11 @@ import java.util.Collection; import org.eclipse.swt.widgets.Composite; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** @@ -46,21 +46,21 @@ public class EditSelectionCommandHandler extends AbstractLayerCommandHandler<Edi @Override public boolean doCommand(final EditSelectionCommand command) { final Composite parent= command.getParent(); - final IConfigRegistry configRegistry= command.getConfigRegistry(); + final ConfigRegistry configRegistry= command.getConfigRegistry(); final Character initialValue= command.getCharacter(); if (EditUtils.allCellsEditable(this.selectionLayer, configRegistry) && EditUtils.isEditorSame(this.selectionLayer, configRegistry) && EditUtils.isConverterSame(this.selectionLayer, configRegistry)) { //check how many cells are selected - final Collection<ILayerCell> selectedCells= this.selectionLayer.getSelectedCells(); + final Collection<LayerCell> selectedCells= this.selectionLayer.getSelectedCells(); if (selectedCells.size() == 1) { //editing is triggered by key for a single cell //we need to fire the InlineCellEditEvent here because we don't know the correct bounds //of the cell to edit inline corresponding to the NatTable. On firing the event, a //translation process is triggered, converting the information to the correct values //needed for inline editing - final ILayerCell cell= selectedCells.iterator().next(); + final LayerCell cell= selectedCells.iterator().next(); this.selectionLayer.fireLayerEvent( new InlineCellEditEvent( this.selectionLayer, @@ -73,7 +73,7 @@ public class EditSelectionCommandHandler extends AbstractLayerCommandHandler<Edi //determine the initial value Object initialEditValue= initialValue; if (initialValue == null && EditUtils.isValueSame(this.selectionLayer)) { - final ILayerCell cell= selectedCells.iterator().next(); + final LayerCell cell= selectedCells.iterator().next(); initialEditValue= cell.getDataValue(0, null); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditUtils.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditUtils.java index edf365e5..43b85ece 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditUtils.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/EditUtils.java @@ -19,15 +19,15 @@ import java.util.List; import java.util.Set; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IEditableRule; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** @@ -41,7 +41,7 @@ public class EditUtils { * @return The last cell of the current selection in the specified {@link SelectionLayer}. * Will return <code>null</code> if there is no selection. */ - public static ILayerCell getLastSelectedCell(final SelectionLayer selectionLayer) { + public static LayerCell getLastSelectedCell(final SelectionLayer selectionLayer) { final PositionCoordinate selectionAnchor= selectionLayer.getSelectionAnchor(); return selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition); } @@ -49,16 +49,16 @@ public class EditUtils { /** * * @param selectionLayer The {@link SelectionLayer} to retrieve the current selection from. - * @param configRegistry The {@link IConfigRegistry} needed to access the configured + * @param configRegistry The {@link ConfigRegistry} needed to access the configured * {@link ICellEditor}. * @return The {@link ICellEditor} of the last cell of the current selection in the specified * {@link SelectionLayer}. Will return <code>null</code> if there is no selection. */ - public static ICellEditor getLastSelectedCellEditor(final SelectionLayer selectionLayer, final IConfigRegistry configRegistry) { - final ILayerCell lastSelectedCell= EditUtils.getLastSelectedCell(selectionLayer); + public static ICellEditor getLastSelectedCellEditor(final SelectionLayer selectionLayer, final ConfigRegistry configRegistry) { + final LayerCell lastSelectedCell= EditUtils.getLastSelectedCell(selectionLayer); if (lastSelectedCell != null) { - final List<String> lastSelectedCellLabelsArray= lastSelectedCell.getConfigLabels().getLabels(); - return configRegistry.getConfigAttribute( + final List<String> lastSelectedCellLabelsArray= lastSelectedCell.getLabels().getLabels(); + return configRegistry.getAttribute( EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray); } return null; @@ -67,16 +67,16 @@ public class EditUtils { /** * For every cell that is selected it is checked whether the cell is editable or not. * @param selectionLayer The {@link SelectionLayer} to retrieve the current selection. - * @param configRegistry The {@link IConfigRegistry} needed to access the configured + * @param configRegistry The {@link ConfigRegistry} needed to access the configured * {@link IEditableRule}s. * @return <code>true</code> if all selected cells are editable, <code>false</code> if * at least one cell is not editable. */ - public static boolean allCellsEditable(final SelectionLayer selectionLayer, final IConfigRegistry configRegistry) { - final Collection<ILayerCell> selectedCells= selectionLayer.getSelectedCells(); - for (final ILayerCell layerCell : selectedCells) { - final LabelStack labelStack= layerCell.getConfigLabels(); - final IEditableRule editableRule= configRegistry.getConfigAttribute( + public static boolean allCellsEditable(final SelectionLayer selectionLayer, final ConfigRegistry configRegistry) { + final Collection<LayerCell> selectedCells= selectionLayer.getSelectedCells(); + for (final LayerCell layerCell : selectedCells) { + final LabelStack labelStack= layerCell.getLabels(); + final IEditableRule editableRule= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels()); @@ -93,18 +93,18 @@ public class EditUtils { * Note: The coordinates need to be related to the given SelectionLayer, otherwise * the wrong cell will be used for the check. * @param selectionLayer The {@link SelectionLayer} to check the cell coordinates against. - * @param configRegistry The {@link IConfigRegistry} needed to access the configured + * @param configRegistry The {@link ConfigRegistry} needed to access the configured * {@link IEditableRule}s. * @param cellCoords The coordinates of the cell to check the editable state, related to * the given {@link SelectionLayer} * @return <code>true</code> if the cell is editable, <code>false</code> if not */ public static boolean isCellEditable( - final SelectionLayer selectionLayer, final IConfigRegistry configRegistry, final PositionCoordinate cellCoords){ - final ILayerCell layerCell= selectionLayer.getCellByPosition(cellCoords.columnPosition, cellCoords.rowPosition); - final LabelStack labelStack= layerCell.getConfigLabels(); + final SelectionLayer selectionLayer, final ConfigRegistry configRegistry, final PositionCoordinate cellCoords){ + final LayerCell layerCell= selectionLayer.getCellByPosition(cellCoords.columnPosition, cellCoords.rowPosition); + final LabelStack labelStack= layerCell.getLabels(); - final IEditableRule editableRule= configRegistry.getConfigAttribute( + final IEditableRule editableRule= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, labelStack.getLabels()); if (editableRule == null) { @@ -118,21 +118,21 @@ public class EditUtils { * Checks if all selected cells have the same {@link ICellEditor} configured. This is needed for * the multi edit feature to determine if a multi edit is possible. * @param selectionLayer The {@link SelectionLayer} to retrieve the current selection. - * @param configRegistry The {@link IConfigRegistry} needed to access the configured + * @param configRegistry The {@link ConfigRegistry} needed to access the configured * {@link ICellEditor}s. * @return <code>true</code> if all selected cells have the same {@link ICellEditor} * configured, <code>false</code> if at least one cell has another {@link ICellEditor} * configured. */ - public static boolean isEditorSame(final SelectionLayer selectionLayer, final IConfigRegistry configRegistry) { + public static boolean isEditorSame(final SelectionLayer selectionLayer, final ConfigRegistry configRegistry) { final List<PositionCoordinate> selectedCells= selectionLayer.getSelectedCellPositions(); ICellEditor lastSelectedCellEditor= null; for (final PositionCoordinate selectedCell : selectedCells) { - final ILayerCell cell= selectionLayer.getCellByPosition( + final LayerCell cell= selectionLayer.getCellByPosition( selectedCell.columnPosition, selectedCell.rowPosition); - final ICellEditor cellEditor= configRegistry.getConfigAttribute( + final ICellEditor cellEditor= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITOR, - DisplayMode.EDIT, cell.getConfigLabels().getLabels() ); + DisplayMode.EDIT, cell.getLabels().getLabels() ); //The first time we get here we need to remember the editor so further checks can //use it. Getting the editor before by getLastSelectedCellEditor() might cause @@ -155,22 +155,22 @@ public class EditUtils { * Both have a TextCellEditor configured, so if only the editor is checked, the multi edit dialog * would open. On committing a changed value an error would occur because of wrong conversion. * @param selectionLayer The {@link SelectionLayer} to retrieve the current selection. - * @param configRegistry The {@link IConfigRegistry} needed to access the configured + * @param configRegistry The {@link ConfigRegistry} needed to access the configured * {@link IDisplayConverter}s. * @return <code>true</code> if all selected cells have the same {@link IDisplayConverter} * configured, <code>false</code> if at least one cell has another {@link IDisplayConverter} * configured. */ @SuppressWarnings("rawtypes") - public static boolean isConverterSame(final SelectionLayer selectionLayer, final IConfigRegistry configRegistry){ + public static boolean isConverterSame(final SelectionLayer selectionLayer, final ConfigRegistry configRegistry){ final List<PositionCoordinate> selectedCells= selectionLayer.getSelectedCellPositions(); final Set<Class> converterSet= new HashSet<>(); for (final PositionCoordinate selectedCell : selectedCells) { - final ILayerCell cell= selectionLayer.getCellByPosition( + final LayerCell cell= selectionLayer.getCellByPosition( selectedCell.columnPosition, selectedCell.rowPosition); - final IDisplayConverter dataTypeConverter= configRegistry.getConfigAttribute( - CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, cell.getConfigLabels().getLabels() ); + final IDisplayConverter dataTypeConverter= configRegistry.getAttribute( + CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, cell.getLabels().getLabels() ); if (dataTypeConverter != null) { converterSet.add(dataTypeConverter.getClass()); } @@ -190,8 +190,8 @@ public class EditUtils { */ public static boolean isValueSame(final SelectionLayer selectionLayer) { Object lastSelectedValue= null; - final Collection<ILayerCell> selectedCells= selectionLayer.getSelectedCells(); - for (final ILayerCell layerCell : selectedCells) { + final Collection<LayerCell> selectedCells= selectionLayer.getSelectedCells(); + for (final LayerCell layerCell : selectedCells) { final Object cellValue= layerCell.getDataValue(0, null); if (lastSelectedValue == null) { lastSelectedValue= cellValue; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/ICellEditHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/ICellEditHandler.java index ac4f0382..672cabff 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/ICellEditHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/ICellEditHandler.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.edit; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEvent.java index 7feec798..ac7ea540 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEvent.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEvent.java @@ -13,15 +13,17 @@ package org.eclipse.statet.ecommons.waltable.edit; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.widgets.Composite; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.jcommons.lang.Nullable; + import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; /** @@ -34,13 +36,13 @@ import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; * these informations are not known and need to be evaluated through the * layer event handlers. */ -public class InlineCellEditEvent implements ILayerEvent { +public class InlineCellEditEvent implements LayerEvent { /** * The layer the cellCoordinates rely on. The layer will change on * event processing to always match the translated coordinates. */ - private ILayer layer; + private Layer layer; /** * The coordinates of the cell to edit for the set layer. */ @@ -50,12 +52,12 @@ public class InlineCellEditEvent implements ILayerEvent { */ private final Composite parent; /** - * The {@link IConfigRegistry} containing the configuration of the + * The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; /** * The value that should be put to the activated editor control. */ @@ -66,14 +68,14 @@ public class InlineCellEditEvent implements ILayerEvent { * @param layer The layer the cellCoordinates rely on. * @param cellCoordinate The coordinates of the cell to edit for the set layer. * @param parent The parent Composite, needed for the creation of the editor control. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. * @param initialValue The value that should be put to the activated editor control. */ - public InlineCellEditEvent(final ILayer layer, final PositionCoordinate cellCoordinate, final Composite parent, - final IConfigRegistry configRegistry, final Object initialValue) { + public InlineCellEditEvent(final Layer layer, final PositionCoordinate cellCoordinate, final Composite parent, + final ConfigRegistry configRegistry, final Object initialValue) { this.layer= layer; this.cellCoordinate= cellCoordinate; @@ -83,7 +85,13 @@ public class InlineCellEditEvent implements ILayerEvent { } @Override - public boolean convertToLocal(final ILayer localLayer) { + public @Nullable InlineCellEditEvent toLayer(final Layer targetLayer) { + final InlineCellEditEvent event= new InlineCellEditEvent(this.layer, + new PositionCoordinate(this.cellCoordinate), this.parent, this.configRegistry, this.initialValue); + return (event.convertToLocal(targetLayer)) ? event : null; + } + + private boolean convertToLocal(final Layer localLayer) { this.cellCoordinate.columnPosition= localLayer.getDim(HORIZONTAL).underlyingToLocalPosition( this.layer.getDim(HORIZONTAL), this.cellCoordinate.columnPosition ); if (this.cellCoordinate.columnPosition < 0 || this.cellCoordinate.columnPosition >= localLayer.getColumnCount()) { @@ -99,7 +107,8 @@ public class InlineCellEditEvent implements ILayerEvent { this.layer= localLayer; return true; } - + + /** * @return The column position of the cell to edit. */ @@ -122,12 +131,12 @@ public class InlineCellEditEvent implements ILayerEvent { } /** - * @return The {@link IConfigRegistry} containing the configuration of the + * @return The {@link ConfigRegistry} containing the configuration of the * current NatTable instance the command should be executed for. * This is necessary because the edit controllers in the current architecture * are not aware of the instance they are running in. */ - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } @@ -138,9 +147,4 @@ public class InlineCellEditEvent implements ILayerEvent { return this.initialValue; } - @Override - public InlineCellEditEvent cloneEvent() { - return new InlineCellEditEvent(this.layer, new PositionCoordinate(this.cellCoordinate), this.parent, this.configRegistry, this.initialValue); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEventHandler.java index 3c6079e0..4e1c4d2a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEventHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineCellEditEventHandler.java @@ -13,9 +13,12 @@ package org.eclipse.statet.ecommons.waltable.edit; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerListener; /** @@ -25,33 +28,36 @@ import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; * @see InlineCellEditEvent * @see EditSelectionCommandHandler */ -public class InlineCellEditEventHandler implements ILayerEventHandler<InlineCellEditEvent> { +@NonNullByDefault +public class InlineCellEditEventHandler implements LayerListener { + /** * The layer this event handler is associated with. Needed for the conversion of * cell position coordinates.Usually this is a grid layer because this is the main * cause for this event handler is needed. */ - private final ILayer layer; - + private final Layer layer; + + /** * @param layer The layer this event handler is associated with. Needed for * the conversion of cell position coordinates. */ - public InlineCellEditEventHandler(final ILayer layer) { + public InlineCellEditEventHandler(final Layer layer) { this.layer= layer; } - - @Override - public Class<InlineCellEditEvent> getLayerEventClass() { - return InlineCellEditEvent.class; - } - + + @Override - public void handleLayerEvent(final InlineCellEditEvent event) { - if (event.convertToLocal(this.layer)) { - final ILayerCell cell= this.layer.getCellByPosition(event.getColumnPosition(), event.getRowPosition()); - EditController.editCell(cell, event.getParent(), event.getInitialValue(), event.getConfigRegistry()); + public void handleLayerEvent(final LayerEvent event) { + if (event instanceof InlineCellEditEvent) { + final var editEvent= (InlineCellEditEvent)event.toLayer(this.layer); + if (editEvent != null) { + final LayerCell cell= this.layer.getCellByPosition(editEvent.getColumnPosition(), editEvent.getRowPosition()); + EditController.editCell(cell, editEvent.getParent(), editEvent.getInitialValue(), editEvent.getConfigRegistry()); + } } } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineEditHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineEditHandler.java index 79dd635b..35e16bd6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineEditHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/InlineEditHandler.java @@ -13,9 +13,9 @@ package org.eclipse.statet.ecommons.waltable.edit; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.selection.SelectRelativeCellCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectRelativeCellCommand; /** @@ -26,10 +26,10 @@ import org.eclipse.statet.ecommons.waltable.selection.SelectRelativeCellCommand; public class InlineEditHandler implements ICellEditHandler { /** - * The {@link ILayer} to which the column and row positions are related to + * The {@link Layer} to which the column and row positions are related to * and on which the update command should be executed */ - private final ILayer layer; + private final Layer layer; /** * The column position of the cell that is edited */ @@ -41,12 +41,12 @@ public class InlineEditHandler implements ICellEditHandler { /** * - * @param layer The {@link ILayer} to which the column and row positions are related to + * @param layer The {@link Layer} to which the column and row positions are related to * and on which the update command should be executed * @param columnPosition The column position of the cell that is edited * @param rowPosition The row position of the cell that is edited */ - public InlineEditHandler(final ILayer layer, final long columnPosition, final long rowPosition) { + public InlineEditHandler(final Layer layer, final long columnPosition, final long rowPosition) { this.layer= layer; this.columnPosition= columnPosition; this.rowPosition= rowPosition; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommand.java index 0df4bbc3..320770fb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommand.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.edit; import org.eclipse.statet.ecommons.waltable.command.AbstractPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** @@ -29,7 +29,7 @@ public class UpdateDataCommand extends AbstractPositionCommand { /** * Create a new {@link UpdateDataCommand} based on the specified information. - * @param layer The {@link ILayer} to which the columnPosition and rowPosition are resolved + * @param layer The {@link Layer} to which the columnPosition and rowPosition are resolved * to. This is needed to support conversion of column and row positions from this * layer to NatTable coordinates, which may be different e.g. in case of grid * composition. @@ -37,7 +37,7 @@ public class UpdateDataCommand extends AbstractPositionCommand { * @param rowPosition The row position of the value to update. * @param newValue The value to update the data model value to. */ - public UpdateDataCommand(final ILayer layer, final long columnPosition, final long rowPosition, final Object newValue) { + public UpdateDataCommand(final Layer layer, final long columnPosition, final long rowPosition, final Object newValue) { super(layer, columnPosition, rowPosition); this.newValue= newValue; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommandHandler.java index f3237964..018c8567 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/UpdateDataCommandHandler.java @@ -16,16 +16,16 @@ package org.eclipse.statet.ecommons.waltable.edit; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; -import org.eclipse.statet.ecommons.waltable.layer.event.CellVisualChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.events.CellVisualChangeEvent; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; /** - * {@link ILayerCommandHandler} that handles {@link UpdateDataCommand}s by updating + * {@link LayerCommandHandler} that handles {@link UpdateDataCommand}s by updating * the data model. It is usually directly registered to the {@link DataLayer} this * command handler is associated with. */ @@ -54,7 +54,7 @@ public class UpdateDataCommandHandler extends AbstractLayerCommandHandler<Update try { final long columnPosition= command.getColumnPosition(); final long rowPosition= command.getRowPosition(); - final IDataProvider dataProvider= this.dataLayer.getDataProvider(); + final DataProvider dataProvider= this.dataLayer.getDataProvider(); final Object oldValue= dataProvider.getDataValue(columnPosition, rowPosition, 0, null); final Object newValue= command.getNewValue(); if ((oldValue != null) ? !oldValue.equals(newValue) : null != newValue) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/CellEditDragMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/CellEditDragMode.java index 7accd827..4cbbfbfc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/CellEditDragMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/CellEditDragMode.java @@ -17,7 +17,7 @@ import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.edit.EditCellCommand; -import org.eclipse.statet.ecommons.waltable.selection.action.CellSelectionDragMode; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.CellSelectionDragMode; /** @@ -81,7 +81,7 @@ public class CellEditDragMode extends CellSelectionDragMode { } natTable.doCommand(new EditCellCommand(natTable, - natTable.getConfigRegistry(), + natTable.getStyleRegistry(), natTable.getCellByPosition(columnPosition, rowPosition) )); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/KeyEditAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/KeyEditAction.java index c68ac79a..b8f67cf9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/KeyEditAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/KeyEditAction.java @@ -38,7 +38,7 @@ public class KeyEditAction implements IKeyAction { public void run(final NatTable natTable, final KeyEvent event) { natTable.doCommand(new EditSelectionCommand( natTable, - natTable.getConfigRegistry(), + natTable.getStyleRegistry(), convertCharToCharacterObject(event) )); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/MouseEditAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/MouseEditAction.java index ce3ed448..22210f1b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/MouseEditAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/MouseEditAction.java @@ -44,7 +44,7 @@ public class MouseEditAction implements IMouseClickAction { } natTable.doCommand(new EditCellCommand(natTable, - natTable.getConfigRegistry(), + natTable.getStyleRegistry(), natTable.getCellByPosition(columnPosition, rowPosition) )); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/ToggleCheckBoxColumnAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/ToggleCheckBoxColumnAction.java index 08b049da..ce845cdc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/ToggleCheckBoxColumnAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/action/ToggleCheckBoxColumnAction.java @@ -16,9 +16,9 @@ package org.eclipse.statet.ecommons.waltable.edit.action; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; import org.eclipse.statet.ecommons.waltable.edit.UpdateDataCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; import org.eclipse.statet.ecommons.waltable.painter.cell.ColumnHeaderCheckBoxPainter; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; @@ -26,9 +26,9 @@ import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; public class ToggleCheckBoxColumnAction implements IMouseAction { private final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter; - private final ILayer bodyDataLayer; + private final Layer bodyDataLayer; - public ToggleCheckBoxColumnAction(final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter, final ILayer bodyDataLayer) { + public ToggleCheckBoxColumnAction(final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter, final Layer bodyDataLayer) { this.columnHeaderCheckBoxPainter= columnHeaderCheckBoxPainter; this.bodyDataLayer= bodyDataLayer; } @@ -36,9 +36,9 @@ public class ToggleCheckBoxColumnAction implements IMouseAction { @Override public void run(final NatTable natTable, final MouseEvent event) { final long sourceColumnPosition= natTable.getColumnPositionByX(event.x); - final long columnPosition= LayerUtil.convertColumnPosition(natTable, sourceColumnPosition, this.bodyDataLayer); + final long columnPosition= LayerUtils.convertColumnPosition(natTable, sourceColumnPosition, this.bodyDataLayer); - final long checkedCellsCount= this.columnHeaderCheckBoxPainter.getCheckedCellsCount(columnPosition, natTable.getConfigRegistry()); + final long checkedCellsCount= this.columnHeaderCheckBoxPainter.getCheckedCellsCount(columnPosition, natTable.getStyleRegistry()); final boolean targetState= checkedCellsCount < this.bodyDataLayer.getRowCount(); for (long rowPosition= 0; rowPosition < this.bodyDataLayer.getRowCount(); rowPosition++) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditBindings.java index 2fd26d11..ec6495ea 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditBindings.java @@ -21,7 +21,7 @@ import org.eclipse.statet.ecommons.waltable.edit.action.CellEditDragMode; import org.eclipse.statet.ecommons.waltable.edit.action.KeyEditAction; import org.eclipse.statet.ecommons.waltable.edit.action.MouseEditAction; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.painter.cell.CheckBoxPainter; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.CellEditorMouseEventMatcher; @@ -36,7 +36,7 @@ import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; * Default configuration for edit related bindings. Adds bindings that support opening * cell editors via keypress and mouse click. * <p> - * By default {@link GridRegion#BODY} is used for the matchers to evaluate if an editor + * By default {@link GridLabels#BODY} is used for the matchers to evaluate if an editor * should be activated. By doing this only the editing in the body layer stack of a grid * is enabled. * </p> @@ -62,19 +62,19 @@ public class DefaultEditBindings extends AbstractUiBindingConfiguration { uiBindingRegistry.registerKeyBinding(new LetterOrDigitKeyEventMatcher(SWT.MOD2), new KeyEditAction()); uiBindingRegistry.registerSingleClickBinding( - new CellEditorMouseEventMatcher(GridRegion.BODY), + new CellEditorMouseEventMatcher(GridLabels.BODY), new MouseEditAction()); uiBindingRegistry.registerMouseDragMode( - new CellEditorMouseEventMatcher(GridRegion.BODY), + new CellEditorMouseEventMatcher(GridLabels.BODY), new CellEditDragMode()); uiBindingRegistry.registerFirstSingleClickBinding( - new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class), + new CellPainterMouseEventMatcher(GridLabels.BODY, MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class), new MouseEditAction()); uiBindingRegistry.registerFirstMouseDragMode( - new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class), + new CellPainterMouseEventMatcher(GridLabels.BODY, MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class), new CellEditDragMode()); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditConfiguration.java index b1f3c2bc..143d16e4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/DefaultEditConfiguration.java @@ -14,14 +14,14 @@ package org.eclipse.statet.ecommons.waltable.edit.config; import org.eclipse.statet.ecommons.waltable.config.AbstractLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IEditableRule; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; import org.eclipse.statet.ecommons.waltable.data.validate.DefaultDataValidator; import org.eclipse.statet.ecommons.waltable.edit.EditCellCommandHandler; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.InlineCellEditEventHandler; import org.eclipse.statet.ecommons.waltable.edit.editor.TextCellEditor; -import org.eclipse.statet.ecommons.waltable.layer.AbstractLayer; /** @@ -50,10 +50,10 @@ public class DefaultEditConfiguration extends AbstractLayerConfiguration<Abstrac } @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE); - configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor()); - configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator()); + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE); + configRegistry.registerAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor()); + configRegistry.registerAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator()); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/RenderErrorHandling.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/RenderErrorHandling.java index 682fa6a3..79406233 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/RenderErrorHandling.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/config/RenderErrorHandling.java @@ -17,13 +17,13 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.widgets.Control; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.edit.editor.AbstractEditErrorHandler; import org.eclipse.statet.ecommons.waltable.edit.editor.ControlDecorationProvider; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; import org.eclipse.statet.ecommons.waltable.edit.editor.IEditErrorHandler; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.style.Style; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -36,10 +36,10 @@ public class RenderErrorHandling extends AbstractEditErrorHandler { /** * The default error styling used for rendering an error. */ - protected IStyle defaultErrorStyle; + protected Style defaultErrorStyle; { - this.defaultErrorStyle= new Style(); - this.defaultErrorStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, GUIHelper.COLOR_RED); + this.defaultErrorStyle= new BasicStyle(); + this.defaultErrorStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, GUIHelper.COLOR_RED); } /** @@ -60,7 +60,7 @@ public class RenderErrorHandling extends AbstractEditErrorHandler { /** * The style that should be used to render an error. */ - protected IStyle errorStyle; + protected Style errorStyle; /** * The decoration provider that should be used for decorating the * editor control on error. @@ -157,9 +157,9 @@ public class RenderErrorHandling extends AbstractEditErrorHandler { this.originalFont= editorControl.getFont(); //set the rendering information out of the error style - editorControl.setBackground(this.errorStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); - editorControl.setForeground(this.errorStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); - editorControl.setFont(this.errorStyle.getAttributeValue(CellStyleAttributes.FONT)); + editorControl.setBackground(this.errorStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); + editorControl.setForeground(this.errorStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR)); + editorControl.setFont(this.errorStyle.getAttributeValue(CellStyling.FONT)); if (this.decorationProvider != null) { this.decorationProvider.showDecoration(); @@ -173,7 +173,7 @@ public class RenderErrorHandling extends AbstractEditErrorHandler { * @param errorStyle The style that should be used to render an error. * Supported style attributes are foreground color, background color and font. */ - public void setErrorStyle(final IStyle errorStyle) { + public void setErrorStyle(final Style errorStyle) { this.errorStyle= errorStyle != null ? errorStyle : this.defaultErrorStyle; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/AbstractCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/AbstractCellEditor.java index 87e57096..0d419b02 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/AbstractCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/AbstractCellEditor.java @@ -29,8 +29,13 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.statet.ecommons.waltable.Messages; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.RegistryStyle; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.data.convert.ConversionFailedException; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; @@ -41,11 +46,6 @@ import org.eclipse.statet.ecommons.waltable.edit.EditConfigHelper; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.EditSelectionCommand; import org.eclipse.statet.ecommons.waltable.edit.ICellEditHandler; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleProxy; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -83,7 +83,7 @@ public abstract class AbstractCellEditor implements ICellEditor { * the editor control supports further styles, this needs to be specified * be the ICellEditor implementation itself. */ - protected IStyle cellStyle; + protected Style cellStyle; /** * The {@link IDisplayConverter} that should be used to convert the input value * to the canonical value and vice versa. @@ -104,7 +104,7 @@ public abstract class AbstractCellEditor implements ICellEditor { /** * The cell whose editor should be activated. */ - protected ILayerCell layerCell; + protected LayerCell layerCell; /** * The {@link LabelStack} of the cell whose editor should be activated. */ @@ -118,12 +118,12 @@ public abstract class AbstractCellEditor implements ICellEditor { */ protected IEditErrorHandler validationEditErrorHandler; /** - * The {@link IConfigRegistry} containing the configuration of the + * The {@link ConfigRegistry} containing the configuration of the * current NatTable instance. This is necessary because the editors in * the current architecture are not aware of the NatTable instance they * are running in. */ - protected IConfigRegistry configRegistry; + protected ConfigRegistry configRegistry; /** * The {@link FocusListener} that will be added to the created editor control @@ -139,7 +139,7 @@ public abstract class AbstractCellEditor implements ICellEditor { @Override public final Control activateCell(final Composite parent, final Object originalCanonicalValue, final EditMode editMode, - final ICellEditHandler editHandler, final ILayerCell cell, final IConfigRegistry configRegistry) { + final ICellEditHandler editHandler, final LayerCell cell, final ConfigRegistry configRegistry) { this.closed= false; this.parent= parent; @@ -147,12 +147,13 @@ public abstract class AbstractCellEditor implements ICellEditor { this.editMode= editMode; this.layerCell= cell; this.configRegistry= configRegistry; - this.labelStack= cell.getConfigLabels(); + this.labelStack= cell.getLabels(); final List<String> configLabels= this.labelStack.getLabels(); - this.displayConverter= configRegistry.getConfigAttribute( + this.displayConverter= configRegistry.getAttribute( CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels); - this.cellStyle= new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels); - this.dataValidator= configRegistry.getConfigAttribute( + this.cellStyle= new RegistryStyle(configRegistry, CellConfigAttributes.CELL_STYLE, + DisplayMode.EDIT, configLabels); + this.dataValidator= configRegistry.getAttribute( EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels); this.conversionEditErrorHandler= EditConfigHelper.getEditErrorHandler( @@ -165,7 +166,7 @@ public abstract class AbstractCellEditor implements ICellEditor { /** * This method will be called by {@link AbstractCellEditor#activateCell(Composite, Object, EditMode, - * ICellEditHandler, ILayerCell, IConfigRegistry)} after initializing the activation values and before + * ICellEditHandler, LayerCell, ConfigRegistry)} after initializing the activation values and before * adding the default listeners. In this method the underlying editor control should be created and * initialized, hiding default configuration from editor implementors. * @param parent The parent Composite, needed for the creation of the editor control. @@ -176,7 +177,7 @@ public abstract class AbstractCellEditor implements ICellEditor { /** - * @see ILayerCell#getColumnPosition() + * @see LayerCell#getColumnPosition() */ @Override public long getColumnPosition() { @@ -184,7 +185,7 @@ public abstract class AbstractCellEditor implements ICellEditor { } /** - * @see ILayerCell#getRowPosition() + * @see LayerCell#getRowPosition() */ @Override public long getRowPosition() { @@ -386,12 +387,12 @@ public abstract class AbstractCellEditor implements ICellEditor { } @Override - public boolean openInline(final IConfigRegistry configRegistry, final List<String> configLabels) { + public boolean openInline(final ConfigRegistry configRegistry, final List<String> configLabels) { return EditConfigHelper.openInline(configRegistry, configLabels); } @Override - public boolean supportMultiEdit(final IConfigRegistry configRegistry, final List<String> configLabels) { + public boolean supportMultiEdit(final ConfigRegistry configRegistry, final List<String> configLabels) { return EditConfigHelper.supportMultiEdit(configRegistry, configLabels); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/CheckBoxCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/CheckBoxCellEditor.java index 3f0cac63..db63dc94 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/CheckBoxCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/CheckBoxCellEditor.java @@ -104,7 +104,7 @@ public class CheckBoxCellEditor extends AbstractCellEditor { if (value instanceof Boolean) { this.checked= ((Boolean)value).booleanValue(); } else if (value instanceof String) { - this.checked= Boolean.valueOf((String) value).booleanValue(); + this.checked= Boolean.parseBoolean((String) value); } else { this.checked= false; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ControlDecorationProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ControlDecorationProvider.java index d0afc196..8fee8863 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ControlDecorationProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ControlDecorationProvider.java @@ -20,6 +20,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Control; @@ -171,8 +172,8 @@ public class ControlDecorationProvider { controlToDecorate.removePaintListener(this); int position= SWT.TOP; - final org.eclipse.swt.graphics.Rectangle textBounds= controlToDecorate.getBounds(); - final org.eclipse.swt.graphics.Rectangle parentClientArea= controlToDecorate.getParent().getClientArea(); + final Rectangle textBounds= controlToDecorate.getBounds(); + final Rectangle parentClientArea= controlToDecorate.getParent().getClientArea(); if ((parentClientArea.x + parentClientArea.width) > (textBounds.x + textBounds.width + errorImage.getBounds().width)) { position |= SWT.RIGHT; } else { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/DateCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/DateCellEditor.java index fb324e46..3a6e28ca 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/DateCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/DateCellEditor.java @@ -23,9 +23,9 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DateTime; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.edit.EditMode; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; /** @@ -133,9 +133,9 @@ public class DateCellEditor extends AbstractCellEditor { final DateTime dateControl= new DateTime(parent, SWT.DATE | SWT.DROP_DOWN); //set style information configured in the associated cell style - dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); - dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); - dateControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT)); + dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); + dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR)); + dateControl.setFont(this.cellStyle.getAttributeValue(CellStyling.FONT)); //add a key listener that will commit or close the editor for special key strokes dateControl.addKeyListener(new KeyAdapter() { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ICellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ICellEditor.java index 98cdcb2f..98408f3d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ICellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/ICellEditor.java @@ -19,15 +19,15 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditController; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.ICellEditHandler; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.ui.matcher.IMouseEventMatcher; @@ -54,7 +54,7 @@ public interface ICellEditor { * than rendering the editor on a subdialog. * @param editHandler The {@link ICellEditHandler} that will be used on commit. * @param cell The cell whose corresponding editor should be activated. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of the + * @param configRegistry The {@link ConfigRegistry} containing the configuration of the * current NatTable instance. * This is necessary because the editors in the current architecture * are not aware of the NatTable instance they are running in. @@ -65,8 +65,8 @@ public interface ICellEditor { Object originalCanonicalValue, EditMode editMode, ICellEditHandler editHandler, - ILayerCell cell, - IConfigRegistry configRegistry + LayerCell cell, + ConfigRegistry configRegistry ); @@ -234,8 +234,8 @@ public interface ICellEditor { * <p>There might be editors that are only able to be opened in a dialog. These implementations * need to override this method to always return <code>false</code>, so the editor never * gets opened inline.</p> - * @param configRegistry The {@link IConfigRegistry} to retrieve the configuration for - * inline/dialog editing out of. Needed here because the instance {@link IConfigRegistry} + * @param configRegistry The {@link ConfigRegistry} to retrieve the configuration for + * inline/dialog editing out of. Needed here because the instance {@link ConfigRegistry} * might not be set on calling this method. * @param configLabels The labels out of the LabelStack of the cell whose editor should be activated. * Needed here because this method needs to be called prior to activation to determine @@ -244,7 +244,7 @@ public interface ICellEditor { * if not. * @see EditConfigAttributes#OPEN_IN_DIALOG */ - boolean openInline(IConfigRegistry configRegistry, List<String> configLabels); + boolean openInline(ConfigRegistry configRegistry, List<String> configLabels); /** * Determines whether this editor supports multi edit behaviour or not. If this method returns @@ -254,8 +254,8 @@ public interface ICellEditor { * the configuration attribute {@link EditConfigAttributes#SUPPORT_MULTI_EDIT}. * <p>You should consider returning <code>false</code> e.g. if the update operation is complex or * you use conditional validation, where a value is validated against another value in the data model. - * @param configRegistry The {@link IConfigRegistry} to retrieve the configuration for - * multi edit support out of. Needed here because the instance {@link IConfigRegistry} + * @param configRegistry The {@link ConfigRegistry} to retrieve the configuration for + * multi edit support out of. Needed here because the instance {@link ConfigRegistry} * might not be set on calling this method. * @param configLabels The labels out of the LabelStack of the cell whose editor should be activated. * Needed here because this method needs to be called prior to activation to determine @@ -264,7 +264,7 @@ public interface ICellEditor { * if the multi editing of this kind of cell editor is not supported. * @see EditConfigAttributes#SUPPORT_MULTI_EDIT */ - boolean supportMultiEdit(IConfigRegistry configRegistry, List<String> configLabels); + boolean supportMultiEdit(ConfigRegistry configRegistry, List<String> configLabels); /** * This is a very special configuration to tell whether an ICellEditor should open a multi @@ -327,8 +327,8 @@ public interface ICellEditor { * closing the editor, it needs to be ensured that the listeners are removed again. Otherwise * the listeners would be added again everytime the editor is activated.</li> * </ol> - * This method will be called automatically by {@link EditController#editCell(ILayerCell, Composite, - * Object, IConfigRegistry)}. + * This method will be called automatically by {@link EditController#editCell(LayerCell, Composite, + * Object, ConfigRegistry)}. */ void addEditorControlListeners(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/IEditErrorHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/IEditErrorHandler.java index 30fb3122..2d11b9af 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/IEditErrorHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/IEditErrorHandler.java @@ -13,14 +13,14 @@ package org.eclipse.statet.ecommons.waltable.edit.editor; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; /** * An {@link IEditErrorHandler} will be used if on data conversion or validation * while editing via {@link ICellEditor} an error occurs. Such a handler is usually - * registered in the {@link IConfigRegistry}, using the {@link EditConfigAttributes}. + * registered in the {@link ConfigRegistry}, using the {@link EditConfigAttributes}. * <p> * For some {@link ICellEditor}s they are also used for just in time conversion/validation * to render the wrong input immediately for feedback to the user. This is done e.g. in diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/PasswordCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/PasswordCellEditor.java index eae99622..f76dee99 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/PasswordCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/PasswordCellEditor.java @@ -17,16 +17,16 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.painter.cell.PasswordTextPainter; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; /** * Specialised {@link TextCellEditor} that sets the echo char of the text control used by * this editor to a configured character. You can configure the echo character by setting - * the attribute {@link CellStyleAttributes#PASSWORD_ECHO_CHAR} to the cell style to use. + * the attribute {@link CellStyling#PASSWORD_ECHO_CHAR} to the cell style to use. * If there is no echo character configured, the bullet character will be used. * * <p>As the anonymization of the inserted value only relates to the {@link Text} control, @@ -64,7 +64,7 @@ public class PasswordCellEditor extends TextCellEditor { parent, style); //search for the configured echo character within the ConfigRegistry - final Character configEchoChar= this.cellStyle.getAttributeValue(CellStyleAttributes.PASSWORD_ECHO_CHAR); + final Character configEchoChar= this.cellStyle.getAttributeValue(CellStyling.PASSWORD_ECHO_CHAR); //set the echo char of the Text control to the configured one or if there is //none configured, set the bullet char textControl.setEchoChar(configEchoChar != null ? configEchoChar : '\u2022'); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TableCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TableCellEditor.java index e8681cea..658884cf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TableCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TableCellEditor.java @@ -45,16 +45,16 @@ import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.data.convert.ConversionFailedException; import org.eclipse.statet.ecommons.waltable.data.validate.ValidationFailedException; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditMode; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.style.Style; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -132,10 +132,7 @@ public class TableCellEditor extends AbstractCellEditor { return Messages.getString("AbstractCellEditor.validationFailure"); //$NON-NLS-1$ } } - catch (final ConversionFailedException e) { - return e.getLocalizedMessage(); - } - catch (final ValidationFailedException e) { + catch (final ConversionFailedException | ValidationFailedException e) { return e.getLocalizedMessage(); } } @@ -270,7 +267,7 @@ public class TableCellEditor extends AbstractCellEditor { //set style information configured in the associated cell style final Table tableControl= this.viewer.getTable(); - tableControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); + tableControl.setBackground(this.cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); tableControl.setLinesVisible(true); @@ -626,33 +623,33 @@ public class TableCellEditor extends AbstractCellEditor { */ protected class InternalLabelProvider extends ColumnLabelProvider { - private final IStyle normalStyle; - private IStyle conversionErrorStyle; - private IStyle validationErrorStyle; + private final Style normalStyle; + private Style conversionErrorStyle; + private Style validationErrorStyle; public InternalLabelProvider() { this.normalStyle= TableCellEditor.this.cellStyle; - this.conversionErrorStyle= TableCellEditor.this.configRegistry.getConfigAttribute( + this.conversionErrorStyle= TableCellEditor.this.configRegistry.getAttribute( EditConfigAttributes.CONVERSION_ERROR_STYLE, DisplayMode.EDIT, TableCellEditor.this.labelStack.getLabels()); if (this.conversionErrorStyle == null) { - this.conversionErrorStyle= new Style(); + this.conversionErrorStyle= new BasicStyle(); this.conversionErrorStyle.setAttributeValue( - CellStyleAttributes.FOREGROUND_COLOR, + CellStyling.FOREGROUND_COLOR, GUIHelper.COLOR_RED); } - this.validationErrorStyle= TableCellEditor.this.configRegistry.getConfigAttribute( + this.validationErrorStyle= TableCellEditor.this.configRegistry.getAttribute( EditConfigAttributes.VALIDATION_ERROR_STYLE, DisplayMode.EDIT, TableCellEditor.this.labelStack.getLabels()); if (this.validationErrorStyle == null) { - this.validationErrorStyle= new Style(); + this.validationErrorStyle= new BasicStyle(); this.validationErrorStyle.setAttributeValue( - CellStyleAttributes.FOREGROUND_COLOR, + CellStyling.FOREGROUND_COLOR, GUIHelper.COLOR_RED); } } @@ -662,7 +659,7 @@ public class TableCellEditor extends AbstractCellEditor { * @param element The element for which the style should be searched * @return The IStyle for the current state of the given element */ - public IStyle getActiveCellStyle(final Object element) { + public Style getActiveCellStyle(final Object element) { if (!((ValueWrapper)element).isValid()) { return this.validationErrorStyle; } @@ -694,17 +691,17 @@ public class TableCellEditor extends AbstractCellEditor { @Override public Color getForeground(final Object element) { - return getActiveCellStyle(element).getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR); + return getActiveCellStyle(element).getAttributeValue(CellStyling.FOREGROUND_COLOR); } @Override public Color getBackground(final Object element) { - return getActiveCellStyle(element).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + return getActiveCellStyle(element).getAttributeValue(CellStyling.BACKGROUND_COLOR); } @Override public Font getFont(final Object element) { - return getActiveCellStyle(element).getAttributeValue(CellStyleAttributes.FONT); + return getActiveCellStyle(element).getAttributeValue(CellStyling.FONT); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TextCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TextCellEditor.java index c8c3cb46..c6dcea7f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TextCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/editor/TextCellEditor.java @@ -23,14 +23,14 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.config.RenderErrorHandling; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** @@ -160,7 +160,7 @@ public class TextCellEditor extends AbstractCellEditor { //Note: this is currently only implemented in here, as the TextCellEditor is // the only editor that supports just in time conversion/validation if (this.inputConversionErrorHandler instanceof RenderErrorHandling) { - final IStyle conversionErrorStyle= this.configRegistry.getConfigAttribute( + final Style conversionErrorStyle= this.configRegistry.getAttribute( EditConfigAttributes.CONVERSION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels()); @@ -169,7 +169,7 @@ public class TextCellEditor extends AbstractCellEditor { } if (this.inputValidationErrorHandler instanceof RenderErrorHandling) { - final IStyle validationErrorStyle= this.configRegistry.getConfigAttribute( + final Style validationErrorStyle= this.configRegistry.getAttribute( EditConfigAttributes.VALIDATION_ERROR_STYLE, DisplayMode.EDIT, this.labelStack.getLabels()); @@ -219,9 +219,9 @@ public class TextCellEditor extends AbstractCellEditor { final Text textControl= new Text(parent, style); //set style information configured in the associated cell style - textControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); - textControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); - textControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT)); + textControl.setBackground(this.cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); + textControl.setForeground(this.cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR)); + textControl.setFont(this.cellStyle.getAttributeValue(CellStyling.FONT)); textControl.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM)); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/AbstractDialogCellEditor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/AbstractDialogCellEditor.java index 28d44415..b2ebd4f9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/AbstractDialogCellEditor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/AbstractDialogCellEditor.java @@ -26,8 +26,10 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.statet.ecommons.waltable.Messages; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.ConversionFailedException; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; @@ -40,8 +42,6 @@ import org.eclipse.statet.ecommons.waltable.edit.EditTypeEnum; import org.eclipse.statet.ecommons.waltable.edit.ICellEditHandler; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; import org.eclipse.statet.ecommons.waltable.edit.editor.IEditErrorHandler; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -70,7 +70,7 @@ public abstract class AbstractDialogCellEditor implements ICellEditor, ICellEdit /** * The cell whose editor should be activated. */ - protected ILayerCell layerCell; + protected LayerCell layerCell; /** * The {@link ICellEditHandler} that will be used on commit. */ @@ -94,12 +94,12 @@ public abstract class AbstractDialogCellEditor implements ICellEditor, ICellEdit */ protected IEditErrorHandler validationEditErrorHandler; /** - * The {@link IConfigRegistry} containing the configuration of the + * The {@link ConfigRegistry} containing the configuration of the * current NatTable instance. This is necessary because the editors in * the current architecture are not aware of the NatTable instance they * are running in. */ - protected IConfigRegistry configRegistry; + protected ConfigRegistry configRegistry; /** * Map that contains custom configurations for this {@link CellEditDialog}. * We do not use the {@link IDialogSettings} provided by JFace, because they are @@ -139,17 +139,17 @@ public abstract class AbstractDialogCellEditor implements ICellEditor, ICellEdit @Override public Control activateCell(final Composite parent, final Object originalCanonicalValue, final EditMode editMode, - final ICellEditHandler editHandler, final ILayerCell cell, - final IConfigRegistry configRegistry) { + final ICellEditHandler editHandler, final LayerCell cell, + final ConfigRegistry configRegistry) { this.parent= parent; this.layerCell= cell; this.configRegistry= configRegistry; - final List<String> configLabels= cell.getConfigLabels().getLabels(); - this.displayConverter= configRegistry.getConfigAttribute( + final List<String> configLabels= cell.getLabels().getLabels(); + this.displayConverter= configRegistry.getAttribute( CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels); - this.dataValidator= configRegistry.getConfigAttribute( + this.dataValidator= configRegistry.getAttribute( EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels); this.conversionEditErrorHandler= EditConfigHelper.getEditErrorHandler( @@ -368,13 +368,13 @@ public abstract class AbstractDialogCellEditor implements ICellEditor, ICellEdit * @see org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor#openInline(org.eclipse.statet.ecommons.waltable.config.IConfigRegistry, java.util.List) */ @Override - public boolean openInline(final IConfigRegistry configRegistry, final List<String> configLabels) { + public boolean openInline(final ConfigRegistry configRegistry, final List<String> configLabels) { return false; } @Override - public boolean supportMultiEdit(final IConfigRegistry configRegistry, final List<String> configLabels) { - final Boolean supportMultiEdit= configRegistry.getConfigAttribute( + public boolean supportMultiEdit(final ConfigRegistry configRegistry, final List<String> configLabels) { + final Boolean supportMultiEdit= configRegistry.getAttribute( EditConfigAttributes.SUPPORT_MULTI_EDIT, DisplayMode.EDIT, configLabels); return (supportMultiEdit == null || supportMultiEdit); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialog.java index 68393142..4e4519b4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialog.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialog.java @@ -30,13 +30,13 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.edit.DialogEditHandler; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.EditTypeEnum; import org.eclipse.statet.ecommons.waltable.edit.ICellEditHandler; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -69,15 +69,15 @@ public class CellEditDialog extends Dialog implements ICellEditDialog { * The cell that should be edited. Needed because editor activation * retrieves the configuration for editing directly out of the cell. */ - protected final ILayerCell cell; + protected final LayerCell cell; /** - * The {@link IConfigRegistry} containing the configuration of the current NatTable + * The {@link ConfigRegistry} containing the configuration of the current NatTable * instance the command should be executed for. This is necessary because the edit * controllers in the current architecture are not aware of the instance they are * running in and therefore it is needed for activation of editors. */ - protected final IConfigRegistry configRegistry; + protected final ConfigRegistry configRegistry; /** * Map that contains custom configurations for this {@link CellEditDialog}. @@ -97,7 +97,7 @@ public class CellEditDialog extends Dialog implements ICellEditDialog { * retrieves the configuration for editing directly out of the cell. * @param cellEditor The {@link ICellEditor} that will be used as editor control * within the dialog. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of + * @param configRegistry The {@link ConfigRegistry} containing the configuration of * the current NatTable instance the command should be executed for. This is * necessary because the edit controllers in the current architecture are not * aware of the instance they are running in and therefore it is needed for @@ -105,9 +105,9 @@ public class CellEditDialog extends Dialog implements ICellEditDialog { */ public CellEditDialog(final Shell parentShell, final Object originalCanonicalValue, - final ILayerCell cell, + final LayerCell cell, final ICellEditor cellEditor, - final IConfigRegistry configRegistry) { + final ConfigRegistry configRegistry) { super(parentShell); this.originalCanonicalValue= originalCanonicalValue; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialogFactory.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialogFactory.java index 20ed98ed..42c68c1e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialogFactory.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/CellEditDialogFactory.java @@ -15,13 +15,13 @@ package org.eclipse.statet.ecommons.waltable.edit.gui; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.edit.DialogEditHandler; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; import org.eclipse.statet.ecommons.waltable.tickupdate.ITickUpdateHandler; import org.eclipse.statet.ecommons.waltable.tickupdate.TickUpdateConfigAttributes; @@ -48,7 +48,7 @@ public class CellEditDialogFactory { * @param cell The cell that should be edited. Needed because editor activation * retrieves the configuration for editing directly out of the cell. * @param cellEditor The cell editor that should be used for multi cell editing. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of + * @param configRegistry The {@link ConfigRegistry} containing the configuration of * the current NatTable instance the command should be executed for. This is * necessary because the edit controllers in the current architecture are not * aware of the instance they are running in and therefore it is needed for @@ -57,9 +57,9 @@ public class CellEditDialogFactory { */ public static ICellEditDialog createCellEditDialog(final Shell parentShell, final Object originalCanonicalValue, - final ILayerCell cell, + final LayerCell cell, final ICellEditor cellEditor, - final IConfigRegistry configRegistry) { + final ConfigRegistry configRegistry) { ICellEditDialog result= null; @@ -72,10 +72,10 @@ public class CellEditDialogFactory { result= (ICellEditDialog) cellEditor; } else { - final ITickUpdateHandler tickUpdateHandler= configRegistry.getConfigAttribute( + final ITickUpdateHandler tickUpdateHandler= configRegistry.getAttribute( TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); if (tickUpdateHandler != null && tickUpdateHandler.isApplicableFor(cell.getDataValue(0, null))) { //if a tick update handler is applicable, return the TickUpdateCellEditDialog result= new TickUpdateCellEditDialog( @@ -88,10 +88,10 @@ public class CellEditDialogFactory { } //check if there are custom edit dialog settings registered - result.setDialogSettings(configRegistry.getConfigAttribute( + result.setDialogSettings(configRegistry.getAttribute( EditConfigAttributes.EDIT_DIALOG_SETTINGS, DisplayMode.EDIT, - cell.getConfigLabels().getLabels())); + cell.getLabels().getLabels())); return result; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/ICellEditDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/ICellEditDialog.java index 5571fa1d..b75fb0a5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/ICellEditDialog.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/ICellEditDialog.java @@ -15,7 +15,7 @@ package org.eclipse.statet.ecommons.waltable.edit.gui; import java.util.Map; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditTypeEnum; @@ -101,7 +101,7 @@ public interface ICellEditDialog { * Allows to customize the appearance of the dialog. This method will be called by the * framework at creation time of the dialog via the {@link CellEditDialogFactory}. * <p> - * The map containing the settings can be registered to the {@link IConfigRegistry} for + * The map containing the settings can be registered to the {@link ConfigRegistry} for * the key {@link org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes#EDIT_DIALOG_SETTINGS}. The keys that are valid * for this map are specified below. * diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/TickUpdateCellEditDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/TickUpdateCellEditDialog.java index 65e03282..f8c66c33 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/TickUpdateCellEditDialog.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/edit/gui/TickUpdateCellEditDialog.java @@ -26,15 +26,15 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditMode; import org.eclipse.statet.ecommons.waltable.edit.EditTypeEnum; import org.eclipse.statet.ecommons.waltable.edit.editor.AbstractCellEditor; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; import org.eclipse.statet.ecommons.waltable.tickupdate.ITickUpdateHandler; import org.eclipse.statet.ecommons.waltable.tickupdate.TickUpdateConfigAttributes; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -96,7 +96,7 @@ public class TickUpdateCellEditDialog extends CellEditDialog { * retrieves the configuration for editing directly out of the cell. * @param cellEditor The {@link ICellEditor} that will be used as editor control * within the dialog. - * @param configRegistry The {@link IConfigRegistry} containing the configuration of + * @param configRegistry The {@link ConfigRegistry} containing the configuration of * the current NatTable instance the command should be executed for. This is * necessary because the edit controllers in the current architecture are not * aware of the instance they are running in and therefore it is needed for @@ -106,18 +106,18 @@ public class TickUpdateCellEditDialog extends CellEditDialog { */ public TickUpdateCellEditDialog(final Shell parentShell, final Object originalCanonicalValue, - final ILayerCell cell, + final LayerCell cell, final ICellEditor cellEditor, - final IConfigRegistry configRegistry, + final ConfigRegistry configRegistry, final ITickUpdateHandler tickUpdateHandler) { super(parentShell, originalCanonicalValue, cell, cellEditor, configRegistry); this.tickUpdateHandler= tickUpdateHandler; - final Boolean useAdjustByConfig= configRegistry.getConfigAttribute( + final Boolean useAdjustByConfig= configRegistry.getAttribute( TickUpdateConfigAttributes.USE_ADJUST_BY, DisplayMode.EDIT, - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); this.useAdjustBy= useAdjustByConfig != null ? useAdjustByConfig : false; } @@ -141,10 +141,10 @@ public class TickUpdateCellEditDialog extends CellEditDialog { this.cell, this.configRegistry); - this.validator= this.configRegistry.getConfigAttribute( + this.validator= this.configRegistry.getAttribute( EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, - this.cell.getConfigLabels().getLabels()); + this.cell.getLabels().getLabels()); if (this.cellEditor instanceof AbstractCellEditor) { //need to override the validator because increase decrease adjust don't need to validate immediately @@ -218,7 +218,7 @@ public class TickUpdateCellEditDialog extends CellEditDialog { @Override public Object calculateValue(final Object currentValue, final Object processValue) { final double delta= processValue instanceof Number - ? ((Number)processValue).doubleValue() : Double.valueOf((String)processValue).doubleValue(); + ? ((Number)processValue).doubleValue() : Double.parseDouble((String)processValue); if (this.editType == EditTypeEnum.ADJUST) { if(delta >= 0) { this.editType= EditTypeEnum.INCREASE; @@ -279,7 +279,7 @@ public class TickUpdateCellEditDialog extends CellEditDialog { } @Override - public boolean validate(final ILayerCell cell, final IConfigRegistry configRegistry, final Object newValue) { + public boolean validate(final LayerCell cell, final ConfigRegistry configRegistry, final Object newValue) { if (TickUpdateCellEditDialog.this.editType == EditTypeEnum.SET) { return this.wrappedValidator.validate(cell, configRegistry, newValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/CompositeFreezeLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/CompositeFreezeLayer.java deleted file mode 100644 index b67aad22..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/CompositeFreezeLayer.java +++ /dev/null @@ -1,198 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; -import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; - -import java.util.Properties; -import java.util.StringTokenizer; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.freeze.config.DefaultFreezeGridBindings; -import org.eclipse.statet.ecommons.waltable.grid.ClientAreaResizeCommand; -import org.eclipse.statet.ecommons.waltable.grid.layer.DimensionallyDependentLayer; -import org.eclipse.statet.ecommons.waltable.layer.AbstractLayer; -import org.eclipse.statet.ecommons.waltable.layer.CompositeLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportLayer; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportSelectDimPositionsCommandHandler; - - -public class CompositeFreezeLayer extends CompositeLayer { - - - private final FreezeLayer freezeLayer; - private final ViewportLayer viewportLayer; - private final SelectionLayer selectionLayer; - - - public CompositeFreezeLayer(final FreezeLayer freezeLayer, final ViewportLayer viewportLayer, final SelectionLayer selectionLayer) { - this(freezeLayer, viewportLayer, selectionLayer, true); - } - - public CompositeFreezeLayer(final FreezeLayer freezeLayer, final ViewportLayer viewportLayer, final SelectionLayer selectionLayer, - final boolean useDefaultConfiguration) { - super(2, 2); - this.freezeLayer= freezeLayer; - this.viewportLayer= viewportLayer; - this.selectionLayer= selectionLayer; - - setChildLayer("FROZEN_REGION", freezeLayer, 0, 0); //$NON-NLS-1$ - setChildLayer("FROZEN_ROW_REGION", new DimensionallyDependentLayer(viewportLayer.getScrollableLayer(), viewportLayer, freezeLayer), 1, 0); //$NON-NLS-1$ - setChildLayer("FROZEN_COLUMN_REGION", new DimensionallyDependentLayer(viewportLayer.getScrollableLayer(), freezeLayer, viewportLayer), 0, 1); //$NON-NLS-1$ - setChildLayer("NONFROZEN_REGION", viewportLayer, 1, 1); //$NON-NLS-1$ - - registerCommandHandlers(); - - if (useDefaultConfiguration) { - addConfiguration(new DefaultFreezeGridBindings()); - } - } - - - @Override - protected ILayerPainter createPainter() { - return new FreezableLayerPainter(); - } - - - public boolean isFrozen() { - return this.freezeLayer.isFrozen(); - } - - @Override - public ILayerPainter getLayerPainter() { - return this.layerPainter; - } - - @Override - protected void registerCommandHandlers() { - registerCommandHandler(new FreezeCommandHandler(this.freezeLayer, this.viewportLayer, this.selectionLayer)); - - final AbstractLayer frozenRowLayer= (AbstractLayer) getChildLayerByLayoutCoordinate(1, 0); - frozenRowLayer.registerCommandHandler(new ViewportSelectDimPositionsCommandHandler( - frozenRowLayer, VERTICAL )); - - final AbstractLayer frozenColumnLayer= (AbstractLayer) getChildLayerByLayoutCoordinate(0, 1); - frozenColumnLayer.registerCommandHandler(new ViewportSelectDimPositionsCommandHandler( - frozenRowLayer, HORIZONTAL )); - } - - - @Override - public boolean doCommand(final ILayerCommand command) { - //if this layer should handle a ClientAreaResizeCommand we have to ensure that - //it is only called on the ViewportLayer, as otherwise an undefined behaviour - //could occur because the ViewportLayer isn't informed about potential refreshes - if (command instanceof ClientAreaResizeCommand) { - this.viewportLayer.doCommand(command); - } - return super.doCommand(command); - } - - - // Persistence - - @Override - public void saveState(final String prefix, final Properties properties) { - PositionCoordinate coord= this.freezeLayer.getTopLeftPosition(); - properties.setProperty(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION, - coord.columnPosition + IPersistable.VALUE_SEPARATOR + coord.rowPosition); - - coord= this.freezeLayer.getBottomRightPosition(); - properties.setProperty(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION, - coord.columnPosition + IPersistable.VALUE_SEPARATOR + coord.rowPosition); - - super.saveState(prefix, properties); - } - - @Override - public void loadState(final String prefix, final Properties properties) { - String property= properties.getProperty(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION); - PositionCoordinate topLeftPosition= null; - if (property != null) { - final StringTokenizer tok= new StringTokenizer(property, IPersistable.VALUE_SEPARATOR); - final String columnPosition= tok.nextToken(); - final String rowPosition= tok.nextToken(); - topLeftPosition= new PositionCoordinate(this.freezeLayer, - Long.valueOf(columnPosition), Long.valueOf(rowPosition)); - } - - property= properties.getProperty(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION); - PositionCoordinate bottomRightPosition= null; - if (property != null) { - final StringTokenizer tok= new StringTokenizer(property, IPersistable.VALUE_SEPARATOR); - final String columnPosition= tok.nextToken(); - final String rowPosition= tok.nextToken(); - bottomRightPosition= new PositionCoordinate(this.freezeLayer, - Long.valueOf(columnPosition), Long.valueOf(rowPosition)); - } - - //only restore a freeze state if there is one persisted - if (topLeftPosition != null && bottomRightPosition != null) { - if (topLeftPosition.columnPosition == -1 && topLeftPosition.rowPosition == -1 - && bottomRightPosition.columnPosition == -1 && bottomRightPosition.rowPosition == -1) { - FreezeHelper.unfreeze(this.freezeLayer, this.viewportLayer); - } else { - FreezeHelper.freeze(this.freezeLayer, this.viewportLayer, topLeftPosition, bottomRightPosition); - } - } - - super.loadState(prefix, properties); - } - - - class FreezableLayerPainter extends CompositeLayerPainter { - - public FreezableLayerPainter() { - } - - @Override - public void paintLayer(final ILayer natLayer, final GC gc, final int xOffset, final int yOffset, final org.eclipse.swt.graphics.Rectangle rectangle, final IConfigRegistry configRegistry) { - super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); - - Color separatorColor= configRegistry.getConfigAttribute(IFreezeConfigAttributes.SEPARATOR_COLOR, DisplayMode.NORMAL); - if (separatorColor == null) { - separatorColor= GUIHelper.COLOR_BLUE; - } - - gc.setClipping(rectangle); - final Color oldFg= gc.getForeground(); - gc.setForeground(separatorColor); - final long freezeWidth= CompositeFreezeLayer.this.freezeLayer.getWidth() - 1; - if (freezeWidth > 0) { - gc.drawLine(safe(xOffset + freezeWidth), yOffset, safe(xOffset + freezeWidth), safe(yOffset + getHeight() - 1)); - } - final long freezeHeight= CompositeFreezeLayer.this.freezeLayer.getHeight() - 1; - if (freezeHeight > 0) { - gc.drawLine(xOffset, safe(yOffset + freezeHeight), safe(xOffset + getWidth() - 1), safe(yOffset + freezeHeight)); - } - gc.setForeground(oldFg); - } - - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEvent.java deleted file mode 100644 index 117ef0c7..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; - - -public class FreezeEvent extends StructuralRefreshEvent { - - public FreezeEvent(final ILayer layer) { - super(layer); - } - - protected FreezeEvent(final FreezeEvent event) { - super(event); - } - - @Override - public FreezeEvent cloneEvent() { - return new FreezeEvent(this); - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - return null; - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - return null; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java deleted file mode 100644 index 2cfe00ca..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java +++ /dev/null @@ -1,126 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; -import org.eclipse.statet.ecommons.waltable.layer.event.IStructuralChangeEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; - - -public class FreezeEventHandler implements ILayerEventHandler<IStructuralChangeEvent> { - - private final FreezeLayer freezeLayer; - - public FreezeEventHandler(final FreezeLayer freezeLayer) { - this.freezeLayer= freezeLayer; - } - - @Override - public Class<IStructuralChangeEvent> getLayerEventClass() { - return IStructuralChangeEvent.class; - } - - @Override - public void handleLayerEvent(final IStructuralChangeEvent event) { - final PositionCoordinate topLeftPosition= this.freezeLayer.getTopLeftPosition(); - final PositionCoordinate bottomRightPosition= this.freezeLayer.getBottomRightPosition(); - - // The handling of diffs have to be in sync with ViewportLayerDim#handleStructuralChanges - final Collection<StructuralDiff> columnDiffs= event.getColumnDiffs(); - if (columnDiffs != null) { - int leftOffset= 0; - int rightOffset= 0; - int freezeMove= 0; // 0= unset, 1 == true, -1 == false - - for (final StructuralDiff diff : columnDiffs) { - final long start= diff.getBeforePositionRange().start; - switch (diff.getDiffType()) { - case ADD: - if (start < topLeftPosition.columnPosition) { - leftOffset+= diff.getAfterPositionRange().size(); - } - if (start <= bottomRightPosition.columnPosition - || (freezeMove == 1 && start == bottomRightPosition.columnPosition + 1) ) { - rightOffset+= diff.getAfterPositionRange().size(); - } - continue; - case DELETE: - if (start < topLeftPosition.columnPosition) { - leftOffset-= Math.min(diff.getBeforePositionRange().end, topLeftPosition.columnPosition + 1) - start; - } - if (start <= bottomRightPosition.columnPosition) { - rightOffset-= Math.min(diff.getBeforePositionRange().end, bottomRightPosition.columnPosition + 1) - start; - if (freezeMove == 0) { - freezeMove= 1; - } - } - else { - freezeMove= -1; - } - continue; - default: - continue; - } - } - - topLeftPosition.columnPosition+= leftOffset; - bottomRightPosition.columnPosition+= rightOffset; - } - - final Collection<StructuralDiff> rowDiffs= event.getRowDiffs(); - if (rowDiffs != null) { - int leftOffset= 0; - int rightOffset= 0; - int freezeMove= 0; // 0= unset, 1 == true, -1 == false - - for (final StructuralDiff diff : rowDiffs) { - final long start= diff.getBeforePositionRange().start; - switch (diff.getDiffType()) { - case ADD: - if (start < topLeftPosition.rowPosition) { - leftOffset+= diff.getAfterPositionRange().size(); - } - if (start <= bottomRightPosition.rowPosition - || (freezeMove == 1 && start == bottomRightPosition.rowPosition + 1) ) { - rightOffset+= diff.getAfterPositionRange().size(); - } - continue; - case DELETE: - if (start < topLeftPosition.rowPosition) { - leftOffset-= Math.min(diff.getBeforePositionRange().end, topLeftPosition.rowPosition + 1) - start; - } - if (start <= bottomRightPosition.rowPosition) { - rightOffset-= Math.min(diff.getBeforePositionRange().end, bottomRightPosition.rowPosition + 1) - start; - if (freezeMove == 0) { - freezeMove= 1; - } - } - else { - freezeMove= -1; - } - continue; - default: - continue; - } - } - - topLeftPosition.rowPosition+= leftOffset; - bottomRightPosition.rowPosition+= rightOffset; - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommand.java deleted file mode 100644 index c9e36552..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public class ReorderFrozenAreaCommand implements ILayerCommand { - - @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - // TODO Auto-generated method stub - return true; - } - - @Override - public ReorderFrozenAreaCommand cloneCommand() { - return this; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommandHandler.java deleted file mode 100644 index baf3e7d7..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/ReorderFrozenAreaCommandHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; - - -public class ReorderFrozenAreaCommandHandler extends AbstractLayerCommandHandler<ReorderFrozenAreaCommand> { - - - @Override - public boolean doCommand(final ReorderFrozenAreaCommand command) { - return false; - } - - @Override - public Class<ReorderFrozenAreaCommand> getCommandClass() { - return ReorderFrozenAreaCommand.class; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/UnfreezeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/UnfreezeEvent.java deleted file mode 100644 index 7a87e7a7..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/UnfreezeEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.freeze; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; - - -public class UnfreezeEvent extends StructuralRefreshEvent { - - public UnfreezeEvent(final ILayer layer) { - super(layer); - } - - protected UnfreezeEvent(final UnfreezeEvent event) { - super(event); - } - - @Override - public UnfreezeEvent cloneEvent() { - return new UnfreezeEvent(this); - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - return null; - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - return null; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/InitializeGridCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/InitializeGridCommand.java deleted file mode 100644 index ec1c649b..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/InitializeGridCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.grid; - -import org.eclipse.swt.widgets.Composite; - -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; - - -/** - * Command that is propagated when NatTable starts up. This gives every layer a - * chance to initialize itself and compute its structural caches. - */ -public class InitializeGridCommand extends AbstractContextFreeCommand { - - private final Composite tableComposite; - - public InitializeGridCommand(final Composite tableComposite) { - this.tableComposite= tableComposite; - } - - public Composite getTableComposite() { - return this.tableComposite; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultBodyDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultBodyDataProvider.java deleted file mode 100644 index e35e6cd6..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultBodyDataProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.grid.data; - -import java.util.List; - -import org.eclipse.statet.ecommons.waltable.data.ListDataProvider; -import org.eclipse.statet.ecommons.waltable.data.ReflectiveColumnPropertyAccessor; - - -public class DefaultBodyDataProvider<T> extends ListDataProvider<T> { - - public DefaultBodyDataProvider(final List<T> rowData, final String[] propertyNames) { - super(rowData, new ReflectiveColumnPropertyAccessor<T>(propertyNames)); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/CornerGridLineCellLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/CornerGridLineCellLayerPainter.java deleted file mode 100644 index e78fee56..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/CornerGridLineCellLayerPainter.java +++ /dev/null @@ -1,122 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.grid.labeled; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; -import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Rectangle; - -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.CellLayerPainter; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; - - -public class CornerGridLineCellLayerPainter extends CellLayerPainter { - - - private final Color gridColor; - - public CornerGridLineCellLayerPainter(final Color gridColor) { - this.gridColor= gridColor; - } - - public CornerGridLineCellLayerPainter() { - this.gridColor= GUIHelper.COLOR_GRAY; - } - - - public Color getGridColor() { - return this.gridColor; - } - - private ILayer getCornerLayer(final ILayer layer) { - return layer.getUnderlyingLayerByPosition(0, 0).getUnderlyingLayerByPosition(0, 0); - } - - - @Override - public void paintLayer(final ILayer natLayer, final GC gc, final int xOffset, final int yOffset, final Rectangle rectangle, final IConfigRegistry configRegistry) { - //Draw GridLines - drawGridLines(natLayer, gc, rectangle); - - super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); - } - - @Override - public LRectangle adjustCellBounds(final long columnPosition, final long rowPosition, final LRectangle bounds) { - return new LRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); - } - - protected void drawGridLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { - gc.setForeground(this.gridColor); - - drawHorizontalLines(natLayer, gc, rectangle); - drawVerticalLines(natLayer, gc, rectangle); - } - - private void drawHorizontalLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { - final int startX, endX; - { final ILayerDim colDim= natLayer.getDim(HORIZONTAL); - startX= safe(rectangle.x + colDim.getPositionStart( - getCornerLayer(natLayer).getColumnCount() - 1 ) - 1 ); - endX= safe(rectangle.x + Math.min(colDim.getSize() - 1, rectangle.width)); - } - final ILayerDim dim= natLayer.getDim(VERTICAL); - final long lastPosition= getEndPosition(dim, rectangle.y + rectangle.height) - 1; - if (startX < endX) { - for (long position= dim.getPositionByPixel(rectangle.y); position < lastPosition; position++) { - final int size= dim.getPositionSize(position); - if (size > 0) { - final int y= safe(dim.getPositionStart(position) + dim.getPositionSize(position) - 1); - gc.drawLine(startX, y, endX, y); - } - } - } - { final int y= safe(dim.getPositionStart(lastPosition) + dim.getPositionSize(lastPosition) - 1); - gc.drawLine(safe(rectangle.x), y, endX, y); - } - } - - private void drawVerticalLines(final ILayer natLayer, final GC gc, final Rectangle rectangle) { - final int startY, endY; - { final ILayerDim rowDim= natLayer.getDim(VERTICAL); - startY= safe(rectangle.y + rowDim.getPositionStart( - getCornerLayer(natLayer).getRowCount() - 1 ) - 1 ); - endY= safe(rectangle.y + Math.min(rowDim.getSize() - 1, rectangle.height)); - } - - final ILayerDim dim= natLayer.getDim(HORIZONTAL); - final long lastPosition= getEndPosition(dim, rectangle.x + rectangle.width) - 1; - if (startY < endY) { - for (long position= dim.getPositionByPixel(rectangle.x); position < lastPosition; position++) { - final int size= dim.getPositionSize(position); - if (size > 0) { - final int x= safe(dim.getPositionStart(position) + size - 1); - gc.drawLine(x, startY, x, endY); - } - } - } - { final int x= safe(dim.getPositionStart(lastPosition) + dim.getPositionSize(lastPosition) - 1); - gc.drawLine(x, safe(rectangle.y), x, endY); - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/LabelCornerLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/LabelCornerLayer.java deleted file mode 100644 index 89120139..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/LabelCornerLayer.java +++ /dev/null @@ -1,120 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Stephan Wahlbrink and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 - # which is available at https://www.apache.org/licenses/LICENSE-2.0. - # - # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 - # - # Contributors: - # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.grid.labeled; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.CornerLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; - - -public class LabelCornerLayer extends CornerLayer { - - - private final IDataProvider columnHeaderLabelProvider; - private final IDataProvider rowHeaderLabelProvider; - - - /** - * @param baseLayer - * The data provider for this layer - * @param horizontalLayerDependency - * The layer to link the horizontal dimension to, typically the row header layer - * @param verticalLayerDependency - * The layer to link the vertical dimension to, typically the column header layer - * @param useDefaultConfiguration - * If default configuration should be applied to this layer (at moment none) - * @param layerPainter - * The painter for this layer or <code>null</code> to use the painter of the base layer - */ - public LabelCornerLayer(final ILayer baseLayer, - final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency, - final IDataProvider columnHeaderLabelProvider, final IDataProvider rowHeaderLabelProvider, - final boolean useDefaultConfiguration, final ILayerPainter layerPainter) { - super(baseLayer, horizontalLayerDependency, verticalLayerDependency, - useDefaultConfiguration, layerPainter ); - - this.columnHeaderLabelProvider= columnHeaderLabelProvider; - this.rowHeaderLabelProvider= rowHeaderLabelProvider; - } - - - @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerDim hDim= getDim(HORIZONTAL); - final ILayerDim vDim= getDim(VERTICAL); - final long columnId= hDim.getPositionId(columnPosition, columnPosition); - final long rowId= vDim.getPositionId(rowPosition, rowPosition); - - final long columnCount= getColumnCount(); - final long rowCount= getRowCount(); - if (rowPosition < rowCount - 1) { - return new LayerCell(this, - new LayerCellDim(HORIZONTAL, columnId, columnPosition, 0, columnCount), - new LayerCellDim(VERTICAL, rowId, rowPosition) ) { - @Override - public LabelStack getConfigLabels() { - return new LabelStack(GridRegion.COLUMN_HEADER_LABEL); - } - @Override - public Object getDataValue(final int flags, final IProgressMonitor monitor) { - return (LabelCornerLayer.this.columnHeaderLabelProvider != null) ? - LabelCornerLayer.this.columnHeaderLabelProvider.getDataValue( - 0, getRowPosition(), flags, monitor ) : - ""; //$NON-NLS-1$ - } - }; - } - else if (columnPosition < columnCount - 1) { - return new LayerCell(this, - new LayerCellDim(HORIZONTAL, columnId, columnPosition), - new LayerCellDim(VERTICAL, rowId, rowPosition) ) { - @Override - public LabelStack getConfigLabels() { - return new LabelStack(GridRegion.ROW_HEADER_LABEL); - } - @Override - public Object getDataValue(final int flags, final IProgressMonitor monitor) { - return (LabelCornerLayer.this.rowHeaderLabelProvider != null) ? - LabelCornerLayer.this.rowHeaderLabelProvider.getDataValue( - getColumnPosition(), 0, flags, monitor) : - ""; //$NON-NLS-1$ - } - }; - } - else { - return new LayerCell(this, - new LayerCellDim(HORIZONTAL, columnId, columnPosition), - new LayerCellDim(VERTICAL, rowId, rowPosition) ) { - @Override - public LabelStack getConfigLabels() { - return new LabelStack(GridRegion.HEADER_PLACEHOLDER); - } - }; - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/CornerLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/CornerLayer.java deleted file mode 100644 index ab687f25..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/CornerLayer.java +++ /dev/null @@ -1,84 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.grid.layer; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.CellLayerPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; - - -/** - * Layer for the top left header corner of the grid layer - */ -public class CornerLayer extends DimensionallyDependentLayer { - - - /** - * Creates a corner header layer using the default configuration and painter - * - * @param baseLayer - * The data provider for this layer - * @param horizontalLayerDependency - * The layer to link the horizontal dimension to, typically the row header layer - * @param verticalLayerDependency - * The layer to link the vertical dimension to, typically the column header layer - */ - public CornerLayer(final ILayer baseLayer, - final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency) { - this(baseLayer, horizontalLayerDependency, verticalLayerDependency, true, new CellLayerPainter()); - } - - /** - * @param baseLayer - * The data provider for this layer - * @param horizontalLayerDependency - * The layer to link the horizontal dimension to, typically the row header layer - * @param verticalLayerDependency - * The layer to link the vertical dimension to, typically the column header layer - * @param useDefaultConfiguration - * If default configuration should be applied to this layer (at moment none) - * @param layerPainter - * The painter for this layer or <code>null</code> to use the painter of the base layer - */ - public CornerLayer(final ILayer baseLayer, - final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency, - final boolean useDefaultConfiguration, final ILayerPainter layerPainter) { - super(baseLayer, horizontalLayerDependency, verticalLayerDependency); - - this.layerPainter= layerPainter; - } - - - @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerDim hDim= getDim(HORIZONTAL); - final ILayerDim vDim= getDim(VERTICAL); - final long columnId= hDim.getPositionId(columnPosition, columnPosition); - final long rowId= vDim.getPositionId(rowPosition, rowPosition); - - return new LayerCell(this, - new LayerCellDim(HORIZONTAL, columnId, - columnPosition, 0, hDim.getPositionCount() ), - new LayerCellDim(VERTICAL, rowId, - rowPosition, 0, getVerticalLayerDependency().getRowCount()) ); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/AbstractLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/AbstractLayer.java deleted file mode 100644 index e8b3327a..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/AbstractLayer.java +++ /dev/null @@ -1,348 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.config.IConfiguration; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PixelOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; -import org.eclipse.statet.ecommons.waltable.painter.layer.GridLineCellLayerPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; -import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; -import org.eclipse.statet.internal.ecommons.waltable.LayerListenerList; - - -/** - * Base layer implementation with common methods for managing listeners and caching, etc. - */ -public abstract class AbstractLayer implements ILayer { - - - private ILayerDim hDim; - private ILayerDim vDim; - - protected ILayerPainter layerPainter; - private IClientAreaProvider clientAreaProvider= IClientAreaProvider.DEFAULT; - - private final Map<Class<? extends ILayerCommand>, ILayerCommandHandler<? extends ILayerCommand>> commandHandlers= new LinkedHashMap<>(); - private final Map<Class<? extends ILayerEvent>, ILayerEventHandler<? extends ILayerEvent>> eventHandlers= new HashMap<>(); - - private final List<IPersistable> persistables= new LinkedList<>(); - private final LayerListenerList listeners= new LayerListenerList(); - private final Collection<IConfiguration> configurations= new ArrayList<>(); - - - protected AbstractLayer() { - initDims(); - - this.layerPainter= createPainter(); - } - - - // Dims - - /** - * Updates the layer dimensions. - * - * Override this method to set custom layer dimension implementations. - */ - protected abstract void initDims(); - - - /** - * Sets the layer dimension of this layer for the orientation of the given dimension. - * - * This method use usually called in {@link #initDims()}. - * - * @param dim the layer dimension - */ - protected void setDim(/*@NonNull*/ final ILayerDim dim) { - if (dim == null) { - throw new NullPointerException("dim"); //$NON-NLS-1$ - } - - if (dim.getOrientation() == HORIZONTAL) { - this.hDim= dim; - } - else { - this.vDim= dim; - } - } - - @Override - public ILayerDim getDim(final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - - return (orientation == HORIZONTAL) ? this.hDim : this.vDim; - } - - - protected ILayerPainter createPainter() { - return null; - } - - - // Dispose - - @Override - public void dispose() { - } - - - // Regions - - @Override - public LabelStack getRegionLabelsByXY(final long x, final long y) { - return new LabelStack(); - } - - // Persistence - - @Override - public void saveState(final String prefix, final Properties properties) { - for (final IPersistable persistable : this.persistables) { - persistable.saveState(prefix, properties); - } - } - - @Override - public void loadState(final String prefix, final Properties properties) { - for (final IPersistable persistable : this.persistables) { - persistable.loadState(prefix, properties); - } - } - - @Override - public void registerPersistable(final IPersistable persistable){ - this.persistables.add(persistable); - } - - @Override - public void unregisterPersistable(final IPersistable persistable){ - this.persistables.remove(persistable); - } - - // Configuration - - public void addConfiguration(final IConfiguration configuration) { - this.configurations.add(configuration); - } - - public void clearConfiguration() { - this.configurations.clear(); - } - - @Override - public void configure(final ConfigRegistry configRegistry, final UiBindingRegistry uiBindingRegistry) { - for (final IConfiguration configuration : this.configurations) { - configuration.configureLayer(this); - configuration.configureRegistry(configRegistry); - configuration.configureUiBindings(uiBindingRegistry); - } - } - - // Commands - - @Override - @SuppressWarnings("unchecked") - public boolean doCommand(final ILayerCommand command) { - for (final Class<? extends ILayerCommand> commandClass : this.commandHandlers.keySet()) { - if (commandClass.isInstance(command)) { - final ILayerCommandHandler commandHandler= this.commandHandlers.get(commandClass); - if (commandHandler.doCommand(this, command.cloneCommand())) { - return true; - } - } - } - - return false; - } - - // Command handlers - - /** - * Layers should use this method to register their command handlers - * and call it from their constructor. This allows easy overriding if - * required of command handlers - */ - protected void registerCommandHandlers() { - // No op - } - - @Override - public void registerCommandHandler(final ILayerCommandHandler<?> commandHandler) { - this.commandHandlers.put(commandHandler.getCommandClass(), commandHandler); - } - - @Override - public void unregisterCommandHandler(final Class<? extends ILayerCommand> commandClass) { - this.commandHandlers.remove(commandClass); - } - - // Events - - @Override - public void addLayerListener(final ILayerListener listener) { - this.listeners.add(listener); - } - - @Override - public void removeLayerListener(final ILayerListener listener) { - this.listeners.remove(listener); - } - - /** - * Handle layer event notification. Convert it to your context - * and propagate <i>UP</i>. - * - * If you override this method you <strong>MUST NOT FORGET</strong> to raise - * the event up the layer stack by calling <code>super.fireLayerEvent(event)</code> - * - unless you plan to eat the event yourself. - **/ - @Override - @SuppressWarnings("unchecked") - public void handleLayerEvent(final ILayerEvent event) { - for (final Class<? extends ILayerEvent> eventClass : this.eventHandlers.keySet()) { - if (eventClass.isInstance(event)) { - final ILayerEventHandler eventHandler= this.eventHandlers.get(eventClass); - eventHandler.handleLayerEvent(event); - } - } - - // Pass on the event to our parent - if (event.convertToLocal(this)) { - fireLayerEvent(event); - } - } - - public void registerEventHandler(final ILayerEventHandler<?> eventHandler) { - this.eventHandlers.put(eventHandler.getLayerEventClass(), eventHandler); - } - - public void unregisterEventHandler(final ILayerEventHandler<?> eventHandler) { - this.eventHandlers.remove(eventHandler.getLayerEventClass()); - } - - /** - * Pass the event to all the {@link ILayerListener} registered on this layer. - * A cloned copy is passed to each listener. - */ - @Override - public void fireLayerEvent(final ILayerEvent event) { - final ILayerListener[] currentListeners= this.listeners.getListeners(); - final int last= currentListeners.length - 1; - if (last >= 0) { - // Fire cloned event to first n-1 listeners; fire original event to last listener - for (int i= 0; i < last; i++) { - currentListeners[i].handleLayerEvent(event.cloneEvent()); - } - currentListeners[last].handleLayerEvent(event); - } - } - - /** - * @return {@link ILayerPainter}. Defaults to {@link GridLineCellLayerPainter} - */ - @Override - public ILayerPainter getLayerPainter() { - if (this.layerPainter == null) { - this.layerPainter= new GridLineCellLayerPainter(); - } - return this.layerPainter; - } - - protected void setLayerPainter(final ILayerPainter layerPainter) { - this.layerPainter= layerPainter; - } - - // Client area - - @Override - public IClientAreaProvider getClientAreaProvider() { - return this.clientAreaProvider; - } - - @Override - public void setClientAreaProvider(final IClientAreaProvider clientAreaProvider) { - this.clientAreaProvider= clientAreaProvider; - } - - - @Override - public final long getColumnCount() { - return this.hDim.getPositionCount(); - } - - @Override - public final long getWidth() { - return this.hDim.getSize(); - } - - @Override - public final long getColumnPositionByX(final long x) { - try { - return this.hDim.getPositionByPixel(x); - } - catch (final PixelOutOfBoundsException e) { - return Long.MIN_VALUE; - } - } - - - @Override - public final long getRowCount() { - return this.vDim.getPositionCount(); - } - - @Override - public final long getHeight() { - return this.vDim.getSize(); - } - - @Override - public final long getRowPositionByY(final long y) { - try { - return this.vDim.getPositionByPixel(y); - } - catch (final PixelOutOfBoundsException e) { - return Long.MIN_VALUE; - } - } - - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ForwardLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ForwardLayer.java deleted file mode 100644 index a4684e75..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/ForwardLayer.java +++ /dev/null @@ -1,162 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - -import java.util.Properties; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.layer.event.IStructuralChangeEvent; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; -import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; - - -public abstract class ForwardLayer extends AbstractLayer { - - - private final ILayer underlyingLayer; - - - public ForwardLayer(/*@NonNull*/ final ILayer underlyingLayer) { - if (underlyingLayer == null) { - throw new NullPointerException("underlyingLayer"); //$NON-NLS-1$ - } - this.underlyingLayer= underlyingLayer; - this.underlyingLayer.setClientAreaProvider(getClientAreaProvider()); - this.underlyingLayer.addLayerListener(this); - - initDims(); - } - - - @Override - protected void initDims() { - final ILayer underlying= getUnderlyingLayer(); - if (underlying == null) { - return; - } - setDim(new ForwardLayerDim<>(this, underlying.getDim(HORIZONTAL))); - setDim(new ForwardLayerDim<>(this, underlying.getDim(VERTICAL))); - } - - protected void setUnderlyingLayer(/*@NonNull*/ final ILayer underlyingLayer) { - } - - protected final ILayer getUnderlyingLayer() { - return this.underlyingLayer; - } - - // Dispose - - @Override - public void dispose() { - this.underlyingLayer.dispose(); - } - - // Persistence - - @Override - public void saveState(final String prefix, final Properties properties) { - this.underlyingLayer.saveState(prefix, properties); - super.saveState(prefix, properties); - } - - /** - * Underlying layers <i>must</i> load state first. - * If this is not done, {@link IStructuralChangeEvent} from underlying - * layers will reset caches after state has been loaded - */ - @Override - public void loadState(final String prefix, final Properties properties) { - this.underlyingLayer.loadState(prefix, properties); - super.loadState(prefix, properties); - } - - // Configuration - - @Override - public void configure(final ConfigRegistry configRegistry, final UiBindingRegistry uiBindingRegistry) { - this.underlyingLayer.configure(configRegistry, uiBindingRegistry); - super.configure(configRegistry, uiBindingRegistry); - } - - @Override - public ILayerPainter getLayerPainter() { - return (this.layerPainter != null) ? this.layerPainter : this.underlyingLayer.getLayerPainter(); - } - - // Command - - @Override - public boolean doCommand(final ILayerCommand command) { - if (super.doCommand(command)) { - return true; - } - - if (this.underlyingLayer != null) { - return this.underlyingLayer.doCommand(command); - } - - return false; - } - - // Client area - - @Override - public void setClientAreaProvider(final IClientAreaProvider clientAreaProvider) { - super.setClientAreaProvider(clientAreaProvider); - if (getUnderlyingLayer() != null) { - getUnderlyingLayer().setClientAreaProvider(clientAreaProvider); - } - } - - - // Cell features - - @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerCell underlyingCell= this.underlyingLayer.getCellByPosition( - columnPosition, rowPosition ); - - return createCell( - underlyingCell.getDim(HORIZONTAL), - underlyingCell.getDim(VERTICAL), - underlyingCell ); - } - - protected ILayerCell createCell(final ILayerCellDim hDim, final ILayerCellDim vDim, - final ILayerCell underlyingCell) { - return new ForwardLayerCell(this, hDim, vDim, underlyingCell); - } - - // IRegionResolver - - @Override - public LabelStack getRegionLabelsByXY(final long x, final long y) { - return this.underlyingLayer.getRegionLabelsByXY(x, y); - } - - @Override - public ILayer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { - return this.underlyingLayer; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AbstractOverrider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AbstractOverrider.java index a21875e5..12d434e4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AbstractOverrider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AbstractOverrider.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -public abstract class AbstractOverrider implements IConfigLabelAccumulator { +public abstract class AbstractOverrider implements CellLabelContributor { private final Map<Serializable, List<String>> overrides= new HashMap<>(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AggregrateConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AggregrateConfigLabelAccumulator.java index 66e68a4e..2c345250 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AggregrateConfigLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/AggregrateConfigLabelAccumulator.java @@ -17,18 +17,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; /** - * An {@link IConfigLabelAccumulator} that can aggregate labels from other <code>IConfigLabelAccumulator</code>s. + * An {@link CellLabelContributor} that can aggregate labels from other <code>IConfigLabelAccumulator</code>s. * All the labels provided by the aggregated accumulators are applied to the cell. */ -public class AggregrateConfigLabelAccumulator implements IConfigLabelAccumulator { +public class AggregrateConfigLabelAccumulator implements CellLabelContributor { - private final List<IConfigLabelAccumulator> accumulators= new ArrayList<>(); + private final List<CellLabelContributor> accumulators= new ArrayList<>(); - public void add(final IConfigLabelAccumulator r) { + public void add(final CellLabelContributor r) { if (r == null) { throw new IllegalArgumentException("null"); //$NON-NLS-1$ @@ -36,7 +36,7 @@ public class AggregrateConfigLabelAccumulator implements IConfigLabelAccumulator this.accumulators.add(r); } - public void add(final IConfigLabelAccumulator... r) { + public void add(final CellLabelContributor... r) { if (r == null) { throw new IllegalArgumentException("null"); //$NON-NLS-1$ @@ -45,9 +45,9 @@ public class AggregrateConfigLabelAccumulator implements IConfigLabelAccumulator } @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { - for (final IConfigLabelAccumulator accumulator : this.accumulators) { - accumulator.accumulateConfigLabels(configLabels, columnPosition, rowPosition); + public void addLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { + for (final CellLabelContributor accumulator : this.accumulators) { + accumulator.addLabels(configLabels, columnPosition, rowPosition); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/BodyOverrideConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/BodyOverrideConfigLabelAccumulator.java deleted file mode 100644 index edf7320b..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/BodyOverrideConfigLabelAccumulator.java +++ /dev/null @@ -1,43 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.cell; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; - - -/** - * Applies the given labels to all the cells in the grid. - * Used to apply styles to the entire grid. - */ -public class BodyOverrideConfigLabelAccumulator implements IConfigLabelAccumulator { - - private List<String> configLabels; - - @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { - configLabels.getLabels().addAll(this.configLabels); - } - - public void registerOverrides(final String... configLabels) { - this.configLabels= Arrays.asList(configLabels); - } - - public void addOverride(final String configLabel) { - this.configLabels.add(configLabel); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellDisplayConversionUtils.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellDisplayConversionUtils.java index 605ebfa4..35a28026 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellDisplayConversionUtils.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellDisplayConversionUtils.java @@ -14,24 +14,25 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; public final class CellDisplayConversionUtils { - public static String convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) { + public static String convertDataType(final LayerCell cell, final ConfigRegistry configRegistry) { return convertDataType(cell, cell.getDataValue(0, null), configRegistry); } - public static String convertDataType(final ILayerCell cell, final Object canonicalValue, final IConfigRegistry configRegistry) { + public static String convertDataType(final LayerCell cell, final Object canonicalValue, final ConfigRegistry configRegistry) { Object displayValue; - final IDisplayConverter displayConverter= configRegistry.getConfigAttribute( + final IDisplayConverter displayConverter= configRegistry.getAttribute( CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); if (displayConverter != null) { displayValue= displayConverter.canonicalToDisplayValue(cell, configRegistry, canonicalValue); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/IConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellLabelContributor.java index 1bd539bf..c841d6ee 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/IConfigLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellLabelContributor.java @@ -13,16 +13,20 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; /** * Resolves the configuration/config label(s) which are tied to a given cell. - * Various attributes can be registered in the {@link IConfigRegistry} against this + * Various attributes can be registered in the {@link ConfigRegistry} against this * label */ -public interface IConfigLabelAccumulator { +@NonNullByDefault +public interface CellLabelContributor { + /** * Add labels applicable to this cell position @@ -31,6 +35,6 @@ public interface IConfigLabelAccumulator { * @param columnPosition of the cell for which labels are being gathered * @param rowPosition of the cell for which labels are being gathered */ - public void accumulateConfigLabels(LabelStack configLabels, long columnPosition, long rowPosition); + void addLabels(LabelStack configLabels, long columnPosition, long rowPosition); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellOverrideLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellOverrideLabelAccumulator.java index 7c8527cf..51a421b0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellOverrideLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/CellOverrideLabelAccumulator.java @@ -16,8 +16,8 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; import java.io.Serializable; import java.util.List; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; /** @@ -30,16 +30,16 @@ import org.eclipse.statet.ecommons.waltable.layer.LabelStack; public class CellOverrideLabelAccumulator<T> extends AbstractOverrider { - private final IDataProvider dataProvider; + private final DataProvider dataProvider; - public CellOverrideLabelAccumulator(final IDataProvider dataProvider) { + public CellOverrideLabelAccumulator(final DataProvider dataProvider) { this.dataProvider= dataProvider; } @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnIndex, final long rowIndex) { + public void addLabels(final LabelStack configLabels, final long columnIndex, final long rowIndex) { final List<String> cellLabels= getConfigLabels( this.dataProvider.getDataValue(columnIndex, rowIndex, 0, null), columnIndex); if (cellLabels == null) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ClassNameConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ClassNameConfigLabelAccumulator.java index 45f43346..4328fdfe 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ClassNameConfigLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ClassNameConfigLabelAccumulator.java @@ -13,25 +13,25 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; -import org.eclipse.statet.ecommons.waltable.data.IRowDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; /** * Adds the Java class name of the cell's data value as a label. */ -public class ClassNameConfigLabelAccumulator implements IConfigLabelAccumulator { +public class ClassNameConfigLabelAccumulator implements CellLabelContributor { - private final IRowDataProvider<?> dataProvider; + private final DataProvider dataProvider; - public ClassNameConfigLabelAccumulator(final IRowDataProvider<?> dataProvider) { + public ClassNameConfigLabelAccumulator(final DataProvider dataProvider) { this.dataProvider= dataProvider; } @Override - public void accumulateConfigLabels(final LabelStack configLabel, final long columnPosition, final long rowPosition) { + public void addLabels(final LabelStack configLabel, final long columnPosition, final long rowPosition) { final Object value= this.dataProvider.getDataValue(columnPosition, rowPosition, 0, null); if (value != null) { configLabel.addLabel(value.getClass().getName()); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnLabelAccumulator.java deleted file mode 100644 index ea9e0968..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnLabelAccumulator.java +++ /dev/null @@ -1,37 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.cell; - -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; - - -/** - * Accumulator for column labels allowing to configure cells by their column position. - * - * The label of a column is {@link #COLUMN_LABEL_PREFIX} + column position. - */ -public class ColumnLabelAccumulator implements IConfigLabelAccumulator { - - /** - * The common prefix of column labels (value is {@value}). - */ - public static final String COLUMN_LABEL_PREFIX= "COLUMN_"; //$NON-NLS-1$ - - - @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { - configLabels.addLabel(COLUMN_LABEL_PREFIX + columnPosition); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnOverrideLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnOverrideLabelAccumulator.java index 63cfd696..98e1878a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnOverrideLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/ColumnOverrideLabelAccumulator.java @@ -13,46 +13,44 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.io.Serializable; import java.util.List; import java.util.Map; -import java.util.Properties; -import java.util.Set; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** * Registers/Adds configuration labels for a given column (by index). - * Custom {@link ICellEditor}, {@link ICellPainter}, {@link IStyle} can then - * be registered in the {@link IConfigRegistry} against these labels. + * Custom {@link ICellEditor}, {@link LayerCellPainter}, {@link Style} can then + * be registered in the {@link ConfigRegistry} against these labels. * * Also @see {@link RowOverrideLabelAccumulator} */ -public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements IPersistable { +public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements Persistable { public static final String PERSISTENCE_KEY= ".columnOverrideLabelAccumulator"; //$NON-NLS-1$ - private final ILayer layer; + private final Layer layer; - public ColumnOverrideLabelAccumulator(final ILayer layer) { + public ColumnOverrideLabelAccumulator(final Layer layer) { this.layer= layer; } @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { + public void addLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { final long columnIndex= this.layer.getDim(HORIZONTAL) .getPositionId(columnPosition, columnPosition); final List<String> overrides= getOverrides(Long.valueOf(columnIndex)); @@ -86,7 +84,7 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements * prefix.columnOverrideLabelAccumulator.0= LABEL1,LABEL2 */ @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { final Map<Serializable, List<String>> overrides= getOverrides(); for (final Map.Entry<Serializable, List<String>> entry : overrides.entrySet()) { @@ -101,22 +99,21 @@ public class ColumnOverrideLabelAccumulator extends AbstractOverrider implements propertyValue= propertyValue.substring(0, propertyValue.length() - 1); } final String propertyKey= prefix + PERSISTENCE_KEY + DOT + entry.getKey(); - properties.setProperty(propertyKey, propertyValue); + properties.put(propertyKey, propertyValue); } } /** * Load the overrides state from the given properties file. - * @see #saveState(String, Properties) + * @see #saveState(String, Map) */ @Override - public void loadState(final String prefix, final Properties properties) { - final Set<Object> keySet= properties.keySet(); - for (final Object key : keySet) { - final String keyString= (String) key; - if(keyString.contains(PERSISTENCE_KEY)){ - final String labelsFromPropertyValue= properties.getProperty(keyString).trim(); - final String columnIndexFromKey= keyString.substring(keyString.lastIndexOf(DOT) + 1); + public void loadState(final String prefix, final Map<String, String> properties) { + for (final var entry : properties.entrySet()) { + final var key= entry.getKey(); + if (key.contains(PERSISTENCE_KEY)){ + final String labelsFromPropertyValue= entry.getValue().trim(); + final String columnIndexFromKey= key.substring(key.lastIndexOf(DOT) + 1); registerColumnOverrides(Long.parseLong(columnIndexFromKey), labelsFromPropertyValue.split(VALUE_SEPARATOR)); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/SimpleConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/SimpleLabelContributor.java index cafe3100..3619d170 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/SimpleConfigLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/cell/SimpleLabelContributor.java @@ -13,19 +13,25 @@ package org.eclipse.statet.ecommons.waltable.layer.cell; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; -public class SimpleConfigLabelAccumulator implements IConfigLabelAccumulator { +@NonNullByDefault +public class SimpleLabelContributor implements CellLabelContributor { + + private final String configLabel; - - public SimpleConfigLabelAccumulator(final String configLabel) { + + + public SimpleLabelContributor(final String configLabel) { this.configLabel= configLabel; } - + + @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { + public void addLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { configLabels.addLabel(this.configLabel); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderLayerConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderLayerConfiguration.java index 3728658e..93b8b404 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderLayerConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderLayerConfiguration.java @@ -14,8 +14,8 @@ package org.eclipse.statet.ecommons.waltable.layer.config; import org.eclipse.statet.ecommons.waltable.config.AggregateConfiguration; -import org.eclipse.statet.ecommons.waltable.grid.layer.ColumnHeaderLayer; -import org.eclipse.statet.ecommons.waltable.resize.config.DefaultColumnResizeBindings; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.ColumnHeaderLayer; +import org.eclipse.statet.ecommons.waltable.resize.ui.action.DefaultColumnResizeBindings; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderStyleConfiguration.java index 808ec795..02907edd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderStyleConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultColumnHeaderStyleConfiguration.java @@ -20,17 +20,17 @@ import org.eclipse.swt.graphics.FontData; import org.eclipse.statet.ecommons.waltable.config.AbstractRegistryConfiguration; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.painter.cell.TextPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.BeveledBorderDecorator; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -44,30 +44,30 @@ public class DefaultColumnHeaderStyleConfiguration extends AbstractRegistryConfi public Color bgColor= GUIHelper.COLOR_WIDGET_BACKGROUND; public Color fgColor= GUIHelper.COLOR_WIDGET_FOREGROUND; public Color gradientBgColor= GUIHelper.COLOR_WHITE; - public Color gradientFgColor= GUIHelper.getColor(136, 212, 215); + public Color gradientFgColor= new Color(136, 212, 215); public HorizontalAlignment hAlign= HorizontalAlignment.CENTER; public VerticalAlignment vAlign= VerticalAlignment.MIDDLE; public BorderStyle borderStyle= null; - public ICellPainter cellPainter= new BeveledBorderDecorator(new TextPainter()); + public LayerCellPainter layerCellPainter= new BeveledBorderDecorator(new TextPainter()); @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter, DisplayMode.NORMAL, GridRegion.CORNER); + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter, DisplayMode.NORMAL, GridLabels.COLUMN_HEADER); + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter, DisplayMode.NORMAL, GridLabels.CORNER); // Normal - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.bgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.fgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); - cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, this.hAlign); - cellStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, this.vAlign); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.borderStyle); - cellStyle.setAttributeValue(CellStyleAttributes.FONT, this.font); + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.bgColor); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.fgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); + cellStyle.setAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT, this.hAlign); + cellStyle.setAttributeValue(CellStyling.VERTICAL_ALIGNMENT, this.vAlign); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.borderStyle); + cellStyle.setAttributeValue(CellStyling.FONT, this.font); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.CORNER); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridLabels.COLUMN_HEADER); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridLabels.CORNER); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderLayerConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderLayerConfiguration.java index 812c9327..5504ca87 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderLayerConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderLayerConfiguration.java @@ -14,16 +14,16 @@ package org.eclipse.statet.ecommons.waltable.layer.config; import org.eclipse.statet.ecommons.waltable.config.AggregateConfiguration; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.RowHeaderLayer; -import org.eclipse.statet.ecommons.waltable.resize.config.DefaultRowResizeBindings; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.RowHeaderLayer; +import org.eclipse.statet.ecommons.waltable.resize.ui.action.DefaultRowResizeBindings; /** * Default setup for the Row header area. Added by the {@link RowHeaderLayer} * Override the methods in this class to customize style / UI bindings. * - * @see GridRegion + * @see GridLabels */ public class DefaultRowHeaderLayerConfiguration extends AggregateConfiguration { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderStyleConfiguration.java index ef03bc0a..3b55b20f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderStyleConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/config/DefaultRowHeaderStyleConfiguration.java @@ -20,16 +20,16 @@ import org.eclipse.swt.graphics.FontData; import org.eclipse.statet.ecommons.waltable.config.AbstractRegistryConfiguration; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.painter.cell.TextPainter; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -39,35 +39,35 @@ public class DefaultRowHeaderStyleConfiguration extends AbstractRegistryConfigur public Color bgColor= GUIHelper.COLOR_WIDGET_BACKGROUND; public Color fgColor= GUIHelper.COLOR_WIDGET_FOREGROUND; public Color gradientBgColor= GUIHelper.COLOR_WHITE; - public Color gradientFgColor= GUIHelper.getColor(136, 212, 215); + public Color gradientFgColor= new Color(136, 212, 215); public HorizontalAlignment hAlign= HorizontalAlignment.CENTER; public VerticalAlignment vAlign= VerticalAlignment.MIDDLE; public BorderStyle borderStyle= null; - public ICellPainter cellPainter= new TextPainter(); + public LayerCellPainter layerCellPainter= new TextPainter(); @Override - public void configureRegistry(final IConfigRegistry configRegistry) { + public void configureRegistry(final ConfigRegistry configRegistry) { configureRowHeaderCellPainter(configRegistry); configureRowHeaderStyle(configRegistry); } - protected void configureRowHeaderStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.bgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.fgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); - cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, this.hAlign); - cellStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, this.vAlign); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.borderStyle); - cellStyle.setAttributeValue(CellStyleAttributes.FONT, this.font); + protected void configureRowHeaderStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.bgColor); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.fgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_BACKGROUND_COLOR, this.gradientBgColor); + cellStyle.setAttributeValue(CellStyling.GRADIENT_FOREGROUND_COLOR, this.gradientFgColor); + cellStyle.setAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT, this.hAlign); + cellStyle.setAttributeValue(CellStyling.VERTICAL_ALIGNMENT, this.vAlign); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.borderStyle); + cellStyle.setAttributeValue(CellStyling.FONT, this.font); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridRegion.ROW_HEADER); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, GridLabels.ROW_HEADER); } - protected void configureRowHeaderCellPainter(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter, DisplayMode.NORMAL, GridRegion.ROW_HEADER); + protected void configureRowHeaderCellPainter(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter, DisplayMode.NORMAL, GridLabels.ROW_HEADER); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/AbstractContextFreeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/AbstractContextFreeEvent.java deleted file mode 100644 index 530c4c7d..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/AbstractContextFreeEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public abstract class AbstractContextFreeEvent implements ILayerEvent { - - @Override - public boolean convertToLocal(final ILayer localLayer) { - return true; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualChangeEvent.java deleted file mode 100644 index 84b3bce0..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualChangeEvent.java +++ /dev/null @@ -1,82 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public class CellVisualChangeEvent implements IVisualChangeEvent { - - protected ILayer layer; - - protected long columnPosition; - - protected long rowPosition; - - public CellVisualChangeEvent(final ILayer layer, final long columnPosition, final long rowPosition) { - this.layer= layer; - this.columnPosition= columnPosition; - this.rowPosition= rowPosition; - } - - protected CellVisualChangeEvent(final CellVisualChangeEvent event) { - this.layer= event.layer; - this.columnPosition= event.columnPosition; - this.rowPosition= event.rowPosition; - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - public long getColumnPosition() { - return this.columnPosition; - } - - public long getRowPosition() { - return this.rowPosition; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.columnPosition= localLayer.getDim(HORIZONTAL).underlyingToLocalPosition( - this.layer.getDim(HORIZONTAL), this.columnPosition ); - this.rowPosition= localLayer.getDim(VERTICAL).underlyingToLocalPosition( - this.layer.getDim(VERTICAL), this.rowPosition ); - - this.layer= localLayer; - - return this.columnPosition >= 0 && this.rowPosition >= 0 - && this.columnPosition < this.layer.getColumnCount() && this.rowPosition < this.layer.getRowCount(); - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - return Arrays.asList(new LRectangle[] { new LRectangle(this.columnPosition, this.rowPosition, 1, 1) }); - } - - @Override - public CellVisualChangeEvent cloneEvent() { - return new CellVisualChangeEvent(this); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualUpdateEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualUpdateEvent.java deleted file mode 100644 index 49394fd4..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/CellVisualUpdateEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2013, 2021 Dirk Fauth and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * Specialization of the CellVisualChangeEvent. The only difference is the handling - * of this type of event in the NatTable event handling. While the CellVisualChangeEvent - * causes a whole redraw operation of the visible part (which is necessary to update everything - * if a data value has change, for example important for conditional styling), this event - * only forces to redraw the specified cell itself. This is for example necessary for hover styling, - * where redrawing everything is not necessary and would cause lags in applying hover styling. - */ -public class CellVisualUpdateEvent extends CellVisualChangeEvent { - - /** - * Create a new CellVisualUpdateEvent based on the given information. - * - * @param layer The layer to which the given column and row position belong. - * @param columnPosition The column position of the cell that needs to be redrawn. - * @param rowPosition The row position of the cell that needs to be redrawn. - */ - public CellVisualUpdateEvent(final ILayer layer, final int columnPosition, final int rowPosition) { - super(layer, columnPosition, rowPosition); - } - - /** - * Create a new CellVisualUpdateEvent out of the given event. - * Used internally for cloning purposes. - * - * @param event The event to create the clone from. - */ - protected CellVisualUpdateEvent(final CellVisualChangeEvent event) { - super(event); - } - - @Override - public CellVisualUpdateEvent cloneEvent() { - return new CellVisualUpdateEvent(this); - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { -// if (!(localLayer instanceof DimensionallyDependentLayer)) { -// columnPosition= localLayer.underlyingToLocalColumnPosition(getLayer(), columnPosition); -// rowPosition= localLayer.underlyingToLocalRowPosition(getLayer(), rowPosition); -// } - - this.layer= localLayer; - - return this.columnPosition >= 0 && this.rowPosition >= 0 - && this.columnPosition < this.layer.getColumnCount() && this.rowPosition < this.layer.getRowCount(); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralChangeEvent.java deleted file mode 100644 index 4c52726c..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralChangeEvent.java +++ /dev/null @@ -1,94 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * Event indicating a change in the structure of the columns. - * This event carried ColumnDiffs (Collection<StructuralDiff>) indicating the columns which have changed. - */ -public abstract class ColumnStructuralChangeEvent extends ColumnVisualChangeEvent implements IStructuralChangeEvent { - - /** - * Creates a new ColumnStructuralChangeEvent based on the given information. - * @param layer The ILayer to which the given column positions match. - * @param columnPositionRanges The column position ranges for the columns that have changed. - */ - public ColumnStructuralChangeEvent(final ILayer layer, final LRange...columnPositionRanges) { - this(layer, Arrays.asList(columnPositionRanges)); - } - - /** - * Creates a new ColumnStructuralChangeEvent based on the given information. - * @param layer The ILayer to which the given column positions match. - * @param columnPositionRanges The column position ranges for the columns that have changed. - */ - public ColumnStructuralChangeEvent(final ILayer layer, final Collection<LRange> columnPositionRanges) { - super(layer, columnPositionRanges); - } - - /** - * Creates a new ColumnStructuralChangeEvent based on the given instance. - * Mainly needed for cloning. - * @param event The ColumnStructuralChangeEvent out of which the new instance should be created. - */ - protected ColumnStructuralChangeEvent(final ColumnStructuralChangeEvent event) { - super(event); - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); - - final Collection<LRange> columnPositionRanges= getColumnPositionRanges(); - if (columnPositionRanges != null && columnPositionRanges.size() > 0) { - long leftmostColumnPosition= Long.MAX_VALUE; - for (final LRange lRange : columnPositionRanges) { - if (lRange.start < leftmostColumnPosition) { - leftmostColumnPosition= lRange.start; - } - } - - final long columnCount= getLayer().getColumnCount(); - final long rowCount= getLayer().getRowCount(); - changedPositionRectangles.add(new LRectangle(leftmostColumnPosition, 0, columnCount - leftmostColumnPosition, rowCount)); - } - - return changedPositionRectangles; - } - - @Override - public boolean isHorizontalStructureChanged() { - return true; - } - - @Override - public boolean isVerticalStructureChanged() { - return false; - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - return null; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralRefreshEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralRefreshEvent.java deleted file mode 100644 index b9ed0ff4..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnStructuralRefreshEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * General event indicating that columns cached by the layers need refreshing. - * - * Note: As opposed to the the {@link ColumnStructuralChangeEvent} this event does not - * indicate the specific columns which have changed. - */ -public class ColumnStructuralRefreshEvent extends StructuralRefreshEvent { - - public ColumnStructuralRefreshEvent(final ILayer layer) { - super(layer); - } - - @Override - public boolean isHorizontalStructureChanged() { - return true; - } - - @Override - public boolean isVerticalStructureChanged() { - return false; - } -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnVisualChangeEvent.java deleted file mode 100644 index bb1e89f7..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ColumnVisualChangeEvent.java +++ /dev/null @@ -1,119 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * An event that indicates a visible change to one ore more columns in the layer. - */ -public abstract class ColumnVisualChangeEvent implements IVisualChangeEvent { - - /** - * The ILayer to which the given column positions match - */ - private ILayer layer; - /** - * The column position ranges for the columns that have changed. - * They are related to the set ILayer. - */ - private Collection<LRange> columnPositionRanges; - - /** - * Creates a new ColumnVisualChangeEvent based on the given information. - * @param layer The ILayer to which the given column positions match. - * @param columnPositionRanges The column position ranges for the columns that have changed. - */ - public ColumnVisualChangeEvent(final ILayer layer, final LRange...columnPositionRanges) { - this(layer, Arrays.asList(columnPositionRanges)); - } - - /** - * Creates a new ColumnVisualChangeEvent based on the given information. - * @param layer The ILayer to which the given column positions match. - * @param columnPositionRanges The column position ranges for the columns that have changed. - */ - public ColumnVisualChangeEvent(final ILayer layer, final Collection<LRange> columnPositionRanges) { - this.layer= layer; - this.columnPositionRanges= columnPositionRanges; - } - - /** - * Creates a new ColumnVisualChangeEvent based on the given instance. - * Mainly needed for cloning. - * @param event The ColumnVisualChangeEvent out of which the new instance should be created. - */ - protected ColumnVisualChangeEvent(final ColumnVisualChangeEvent event) { - this.layer= event.layer; - this.columnPositionRanges= event.columnPositionRanges; - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - /** - * @return The column position ranges for the columns that have changed. - */ - public Collection<LRange> getColumnPositionRanges() { - return this.columnPositionRanges; - } - - /** - * Sets the column position ranges for the columns that have changed. - * Only for internal use in cases where the constructor needs to calculate the column - * position ranges within the child constructor. - * @param columnPositionRanges The column position ranges for the columns that have changed. - */ - protected void setColumnPositionRanges(final Collection<LRange> columnPositionRanges) { - this.columnPositionRanges= columnPositionRanges; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.columnPositionRanges= localLayer.getDim(HORIZONTAL).underlyingToLocalPositions( - this.layer.getDim(HORIZONTAL), this.columnPositionRanges ); - this.layer= localLayer; - - return this.columnPositionRanges != null && this.columnPositionRanges.size() > 0; - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); - - final long rowCount= this.layer.getRowCount(); - for (final LRange lRange : this.columnPositionRanges) { - changedPositionRectangles.add(new LRectangle(lRange.start, 0, lRange.end - lRange.start, rowCount)); - } - - return changedPositionRectangles; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEvent.java deleted file mode 100644 index c0bddd77..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEvent.java +++ /dev/null @@ -1,42 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * Event fired by the {@link ILayerCommandHandler} classes (usually to signal to handling of a {@link ILayerCommand}). - * Every layer in the grid is given a chance to respond to an event via {@link ILayer#handleLayerEvent(ILayerEvent)}. - * - * @see ILayerEventHandler - */ -public interface ILayerEvent { - - /** - * Convert the column/row positions carried by the event to the layer about to - * handle the event. - * @param localLayer layer about to receive the event - * @return TRUE if successfully converted, FALSE otherwise - */ - public boolean convertToLocal(ILayer localLayer); - - /** - * @return A cloned copy of the event. This cloned copy is provided to each listener. - */ - public ILayerEvent cloneEvent(); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEventHandler.java deleted file mode 100644 index 18b5fd5f..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ILayerEventHandler.java +++ /dev/null @@ -1,23 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - - -public interface ILayerEventHandler <T extends ILayerEvent> { - - public void handleLayerEvent(T event); - - public Class<T> getLayerEventClass(); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/PropertyUpdateEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/PropertyUpdateEvent.java deleted file mode 100644 index b31475dc..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/PropertyUpdateEvent.java +++ /dev/null @@ -1,86 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.beans.PropertyChangeEvent; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public class PropertyUpdateEvent<T> implements IVisualChangeEvent { - - private final PropertyChangeEvent propertyChangeEvent= null; - private final T sourceBean; - private final String propertyName; - private final Object newValue; - private final Object oldValue; - - private ILayer layer; - - public PropertyUpdateEvent(final ILayer layer, final T sourceBean, final String propertyName, final Object oldValue, final Object newValue) { - this.layer= layer; - this.sourceBean= sourceBean; - this.propertyName= propertyName; - this.oldValue= oldValue; - this.newValue= newValue; - } - - // Interface methods - - @Override - public ILayerEvent cloneEvent() { - return new PropertyUpdateEvent<>(this.layer, this.sourceBean, this.propertyName, this.oldValue, this.newValue); - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.layer= localLayer; - return true; - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - return Arrays.asList(new LRectangle(0, 0, this.layer.getWidth(), this.layer.getHeight())); - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - // Accessors - - public PropertyChangeEvent getPropertyChangeEvent() { - return this.propertyChangeEvent; - } - - public T getSourceBean() { - return this.sourceBean; - } - - public String getPropertyName() { - return this.propertyName; - } - - public Object getNewValue() { - return this.newValue; - } - - public Object getOldValue() { - return this.oldValue; - } -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ResizeStructuralRefreshEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ResizeStructuralRefreshEvent.java deleted file mode 100644 index 77ea7bf4..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/ResizeStructuralRefreshEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Dirk Fauth and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Dirk Fauth - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * Special {@link StructuralRefreshEvent} that returns empty lists for column and - * row diffs to avoid complete resetting of changes made to the NatTable by the user - * (e.g. resetting changed column order like reported in https://bugs.eclipse.org/bugs/show_bug.cgi?id=384795). - * - * <p>This event should only be fired be the {@link DataLayer} if columns or rows are configured - * to use percentage sizing. - */ -public class ResizeStructuralRefreshEvent extends StructuralRefreshEvent { - - public ResizeStructuralRefreshEvent(final ILayer layer) { - super(layer); - } - - protected ResizeStructuralRefreshEvent(final ResizeStructuralRefreshEvent event) { - super(event); - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - return new ArrayList<>(); - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - return new ArrayList<>(); - } -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralChangeEvent.java deleted file mode 100644 index 03ef0d3a..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralChangeEvent.java +++ /dev/null @@ -1,70 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * @see ColumnStructuralChangeEvent - */ -public abstract class RowStructuralChangeEvent extends RowVisualChangeEvent implements IStructuralChangeEvent { - - public RowStructuralChangeEvent(final ILayer layer, final LRange...rowPositionRanges) { - this(layer, Arrays.asList(rowPositionRanges)); - } - - public RowStructuralChangeEvent(final ILayer layer, final Collection<LRange> rowPositionRanges) { - super(layer, rowPositionRanges); - } - - protected RowStructuralChangeEvent(final RowStructuralChangeEvent event) { - super(event); - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); - - final long columnCount= getLayer().getColumnCount(); - final long rowCount= getLayer().getRowCount(); - for (final LRange lRange : getRowPositionRanges()) { - changedPositionRectangles.add(new LRectangle(0, lRange.start, columnCount, rowCount - lRange.start)); - } - - return changedPositionRectangles; - } - - @Override - public boolean isHorizontalStructureChanged() { - return false; - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - return null; - } - - @Override - public boolean isVerticalStructureChanged() { - return true; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralRefreshEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralRefreshEvent.java deleted file mode 100644 index b3b9b621..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowStructuralRefreshEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * @see ColumnStructuralRefreshEvent - */ -public class RowStructuralRefreshEvent extends StructuralRefreshEvent { - - public RowStructuralRefreshEvent(final ILayer layer) { - super(layer); - } - - @Override - public boolean isVerticalStructureChanged() { - return true; - } - - @Override - public boolean isHorizontalStructureChanged() { - return false; - } -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowUpdateEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowUpdateEvent.java deleted file mode 100644 index cce92f75..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowUpdateEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public class RowUpdateEvent extends RowVisualChangeEvent { - - public RowUpdateEvent(final ILayer layer, final long rowPosition) { - this(layer, new LRange(rowPosition)); - } - - public RowUpdateEvent(final ILayer layer, final LRange rowPositionRange) { - super(layer, rowPositionRange); - } - - public RowUpdateEvent(final RowUpdateEvent event) { - super(event); - } - - @Override - public RowUpdateEvent cloneEvent() { - return new RowUpdateEvent(this); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowVisualChangeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowVisualChangeEvent.java deleted file mode 100644 index 0bf8fd5d..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/RowVisualChangeEvent.java +++ /dev/null @@ -1,83 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public abstract class RowVisualChangeEvent implements IVisualChangeEvent { - - private ILayer layer; - - private Collection<LRange> rowPositionRanges= new ArrayList<>(); - - public RowVisualChangeEvent(final ILayer layer, final LRange...rowPositionRanges) { - this(layer, Arrays.asList(rowPositionRanges)); - } - - public RowVisualChangeEvent(final ILayer layer, final Collection<LRange> rowPositionRanges) { - this.layer= layer; - this.rowPositionRanges= rowPositionRanges; - } - - // Copy constructor - protected RowVisualChangeEvent(final RowVisualChangeEvent event) { - this.layer= event.layer; - this.rowPositionRanges= event.rowPositionRanges; - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - public Collection<LRange> getRowPositionRanges() { - return this.rowPositionRanges; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.rowPositionRanges= localLayer.getDim(VERTICAL).underlyingToLocalPositions( - this.layer.getDim(VERTICAL), this.rowPositionRanges ); - this.layer= localLayer; - - return this.rowPositionRanges != null && this.rowPositionRanges.size() > 0; - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - final Collection<LRectangle> changedPositionRectangles= new ArrayList<>(); - - final long columnCount= this.layer.getColumnCount(); - for (final LRange lRange : this.rowPositionRanges) { - changedPositionRectangles.add(new LRectangle(0, lRange.start, columnCount, lRange.end - lRange.start)); - } - - return changedPositionRectangles; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/StructuralRefreshEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/StructuralRefreshEvent.java deleted file mode 100644 index d3e80d0f..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/StructuralRefreshEvent.java +++ /dev/null @@ -1,82 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -/** - * General event indicating that structures cached by the layers need refreshing. - * <p> - * TIP: Consider throwing a more focused event (subclass) if you need to do this. - */ -public class StructuralRefreshEvent implements IStructuralChangeEvent { - - private ILayer layer; - - public StructuralRefreshEvent(final ILayer layer) { - this.layer= layer; - } - - protected StructuralRefreshEvent(final StructuralRefreshEvent event) { - this.layer= event.layer; - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.layer= localLayer; - - return true; - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - return Arrays.asList(new LRectangle[] { new LRectangle(0, 0, this.layer.getColumnCount(), this.layer.getRowCount()) }); - } - - @Override - public boolean isHorizontalStructureChanged() { - return true; - } - - @Override - public boolean isVerticalStructureChanged() { - return true; - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - return null; - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - return null; - } - - @Override - public ILayerEvent cloneEvent() { - return this; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/VisualRefreshEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/VisualRefreshEvent.java deleted file mode 100644 index aab43c4d..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/event/VisualRefreshEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.layer.event; - -import java.util.Arrays; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; - - -public class VisualRefreshEvent implements IVisualChangeEvent { - - private ILayer layer; - - public VisualRefreshEvent(final ILayer layer) { - this.layer= layer; - } - - protected VisualRefreshEvent(final VisualRefreshEvent event) { - this.layer= event.layer; - } - - @Override - public ILayer getLayer() { - return this.layer; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - this.layer= localLayer; - - return true; - } - - @Override - public Collection<LRectangle> getChangedPositionRectangles() { - return Arrays.asList(new LRectangle[] { new LRectangle(0, 0, this.layer.getColumnCount(), this.layer.getRowCount()) }); - } - - @Override - public ILayerEvent cloneEvent() { - return new VisualRefreshEvent(this); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractCellPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractCellPainter.java index e453d801..c3a6bf0a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractCellPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractCellPainter.java @@ -15,16 +15,17 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; -public abstract class AbstractCellPainter implements ICellPainter { +public abstract class AbstractCellPainter implements LayerCellPainter { @Override - public ICellPainter getCellPainterAt(final long x, final long y, final ILayerCell cell, final GC gc, - final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LayerCellPainter getCellPainterAt(final long x, final long y, final LayerCell cell, final GC gc, + final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { return this; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractTextPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractTextPainter.java index 224a75e5..3c977129 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractTextPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AbstractTextPainter.java @@ -22,14 +22,14 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.TextDecorationLine; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.layer.cell.CellDisplayConversionUtils; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.style.TextDecorationEnum; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -51,7 +51,7 @@ public abstract class AbstractTextPainter extends BackgroundPainter { */ private static final Pattern NEW_LINE_PATTERN= Pattern.compile("\\n\\r|\\r\\n|\\n|\\r"); //$NON-NLS-1$ - private static final String NEW_LINE_SEPARATOR= System.getProperty("line.separator"); //$NON-NLS-1$ + private static final String NEW_LINE_SEPARATOR= System.lineSeparator(); private static final int DEFAULT_SPACING= 3; @@ -164,9 +164,9 @@ public abstract class AbstractTextPainter extends BackgroundPainter { } /** - * Convert the data value of the cell using the {@link IDisplayConverter} from the {@link IConfigRegistry} + * Convert the data value of the cell using the {@link IDisplayConverter} from the {@link ConfigRegistry} */ - protected String convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected String convertDataType(final LayerCell cell, final ConfigRegistry configRegistry) { return CellDisplayConversionUtils.convertDataType(cell, configRegistry); } @@ -175,10 +175,10 @@ public abstract class AbstractTextPainter extends BackgroundPainter { * @param gc * @param cellStyle */ - protected void setupGCFromConfig(final GC gc, final IStyle cellStyle) { - final Color fg= cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR); - final Color bg= cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); - final Font font= cellStyle.getAttributeValue(CellStyleAttributes.FONT); + protected void setupGCFromConfig(final GC gc, final Style cellStyle) { + final Color fg= cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR); + final Color bg= cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); + final Font font= cellStyle.getAttributeValue(CellStyling.FONT); gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS); gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS); @@ -193,11 +193,10 @@ public abstract class AbstractTextPainter extends BackgroundPainter { * @return <code>true</code> if there is a underline text decoration configured, * <code>false</code> otherwise. */ - protected boolean renderUnderlined(final IStyle cellStyle) { - final TextDecorationEnum decoration= cellStyle.getAttributeValue(CellStyleAttributes.TEXT_DECORATION); - if (decoration != null) { - return (decoration.equals(TextDecorationEnum.UNDERLINE) - || decoration.equals(TextDecorationEnum.UNDERLINE_STRIKETHROUGH)); + protected boolean renderUnderlined(final Style cellStyle) { + final var lines= cellStyle.getAttributeValue(CellStyling.TEXT_DECORATION_LINES); + if (lines != null) { + return (lines.contains(TextDecorationLine.UNDERLINE)); } return this.underline; } @@ -208,11 +207,10 @@ public abstract class AbstractTextPainter extends BackgroundPainter { * @return <code>true</code> if there is a strikethrough text decoration configured, * <code>false</code> otherwise. */ - protected boolean renderStrikethrough(final IStyle cellStyle) { - final TextDecorationEnum decoration= cellStyle.getAttributeValue(CellStyleAttributes.TEXT_DECORATION); - if (decoration != null) { - return (decoration.equals(TextDecorationEnum.STRIKETHROUGH) - || decoration.equals(TextDecorationEnum.UNDERLINE_STRIKETHROUGH)); + protected boolean renderStrikethrough(final Style cellStyle) { + final var lines= cellStyle.getAttributeValue(CellStyling.TEXT_DECORATION_LINES); + if (lines != null) { + return (lines.contains(TextDecorationLine.STRIKETHROUGH)); } return this.strikethrough; } @@ -274,7 +272,7 @@ public abstract class AbstractTextPainter extends BackgroundPainter { * @param text the text that should be modified for display * @return the modified text */ - protected String getTextToDisplay(final ILayerCell cell, final GC gc, final long availableLength, String text) { + protected String getTextToDisplay(final LayerCell cell, final GC gc, final long availableLength, String text) { final StringBuilder output= new StringBuilder(); text= text.trim(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AutomaticRowHeightTextPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AutomaticRowHeightTextPainter.java index 31ab61fc..65c42942 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AutomaticRowHeightTextPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/AutomaticRowHeightTextPainter.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundImagePainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundImagePainter.java index d06d488e..ce5da6d9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundImagePainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundImagePainter.java @@ -21,9 +21,10 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Pattern; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; /** @@ -41,24 +42,24 @@ public class BackgroundImagePainter extends CellPainterWrapper { * @param separatorColor to be used for drawing left and right borders for the cell. * Set to null if the borders are not required. */ - public BackgroundImagePainter(final ICellPainter interiorPainter, final Image bgImage, final Color separatorColor) { + public BackgroundImagePainter(final LayerCellPainter interiorPainter, final Image bgImage, final Color separatorColor) { super(interiorPainter); this.bgImage= bgImage; this.separatorColor= separatorColor; } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredWidth(cell, gc, configRegistry) + 4; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredHeight(cell, gc, configRegistry) + 4; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { // Save GC settings final Color originalBackground= gc.getBackground(); final Color originalForeground= gc.getForeground(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundPainter.java index dd1a9be9..4b604d5b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BackgroundPainter.java @@ -18,17 +18,18 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; /** * Paints the background of the cell using the color from the cell style. - * If no background color is registered in the {@link ConfigRegistry} the painting + * If no background color is registered in the {@link BasicConfigRegistry} the painting * is skipped. * <p> * Example: The {@link TextPainter} inherits this and uses the paint method @@ -40,12 +41,12 @@ public class BackgroundPainter extends CellPainterWrapper { public BackgroundPainter() {} - public BackgroundPainter(final ICellPainter painter) { + public BackgroundPainter(final LayerCellPainter painter) { super(painter); } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { final Color backgroundColor= getBackgroundColour(cell, configRegistry); if (backgroundColor != null) { final Color originalBackground= gc.getBackground(); @@ -59,8 +60,8 @@ public class BackgroundPainter extends CellPainterWrapper { super.paintCell(cell, gc, bounds, configRegistry); } - protected Color getBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry) { - return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + protected Color getBackgroundColour(final LayerCell cell, final ConfigRegistry configRegistry) { + return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.BACKGROUND_COLOR); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BlendedBackgroundPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BlendedBackgroundPainter.java index aa44ca7f..62834ca7 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BlendedBackgroundPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/BlendedBackgroundPainter.java @@ -18,13 +18,14 @@ import java.util.List; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.CellStyleProxy; +import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.RegistryStyle; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -56,7 +57,7 @@ public class BlendedBackgroundPainter extends TextPainter { } @Override - protected Color getBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Color getBackgroundColour(final LayerCell cell, final ConfigRegistry configRegistry) { return blendBackgroundColour(cell, configRegistry, this.gridBackgroundColour); } @@ -65,22 +66,23 @@ public class BlendedBackgroundPainter extends TextPainter { * have been registered, they are all blended together. * * @param cell - * the {@link org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell} to get a background colour for. + * the {@link org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell} to get a background colour for. * @param configRegistry - * an {@link org.eclipse.statet.ecommons.waltable.config.IConfigRegistry}. + * an {@link org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry}. * @param baseColor * Colours are not blended with this colour. * @return A blended background colour. */ - public static Color blendBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry, final RGB baseColor) { + public static Color blendBackgroundColour(final LayerCell cell, final ConfigRegistry configRegistry, final RGB baseColor) { // Get all of the background colours registered for the cell in normal mode. final List<Color> colours= CellStyleUtil.getAllBackgroundColors(cell, configRegistry, DisplayMode.NORMAL); // If the cell is selected, get it's selected background colour and add to the blending mix. - if (cell.getDisplayMode().equals(DisplayMode.SELECT)) { - final IStyle cellStyle= new CellStyleProxy(configRegistry, DisplayMode.SELECT, cell.getConfigLabels().getLabels()); - colours.add(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); + if (cell.getDisplayMode().equals(DisplayMode.SELECTED)) { + final Style cellStyle= new RegistryStyle(configRegistry, CellConfigAttributes.CELL_STYLE, + DisplayMode.SELECTED, cell.getLabels().getLabels()); + colours.add(cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); } if (colours.size() == 0) { @@ -102,7 +104,7 @@ public class BlendedBackgroundPainter extends TextPainter { } } - return GUIHelper.getColor(rgb); + return new Color(rgb); } } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ButtonCellPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ButtonCellPainter.java index b3acc9ea..4935404f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ButtonCellPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ButtonCellPainter.java @@ -23,11 +23,12 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.swt.widgets.Display; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.event.CellVisualChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.events.CellVisualChangeEvent; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.BeveledBorderDecorator; import org.eclipse.statet.ecommons.waltable.ui.NatEventData; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; @@ -37,8 +38,8 @@ import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; * Paints a button and simulates a button click. It also notifies its listeners when it is clicked. */ public class ButtonCellPainter extends AbstractCellPainter implements IMouseAction { - private final ICellPainter buttonRaisedPainter; - private final ICellPainter buttonPressedPainter; + private final LayerCellPainter buttonRaisedPainter; + private final LayerCellPainter buttonPressedPainter; private int buttonFlashTime= 150; @@ -51,7 +52,7 @@ public class ButtonCellPainter extends AbstractCellPainter implements IMouseActi * @param interiorPainter to paint the contents of the cell. * This will be decorated with a button like look and feel. */ - public ButtonCellPainter(final ICellPainter interiorPainter) { + public ButtonCellPainter(final LayerCellPainter interiorPainter) { this.buttonPressedPainter= new BeveledBorderDecorator(interiorPainter, false); this.buttonRaisedPainter= new BeveledBorderDecorator(interiorPainter); } @@ -60,13 +61,13 @@ public class ButtonCellPainter extends AbstractCellPainter implements IMouseActi * @param buttonRaisedPainter cell painter to use for painting the button raised state. * @param buttonPressedPainter cell painter to use for painting the button pressed state. */ - public ButtonCellPainter(final ICellPainter buttonRaisedPainter, final ICellPainter buttonPressedPainter) { + public ButtonCellPainter(final LayerCellPainter buttonRaisedPainter, final LayerCellPainter buttonPressedPainter) { this.buttonRaisedPainter= buttonRaisedPainter; this.buttonPressedPainter= buttonPressedPainter; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { if (this.recentlyClicked && this.columnPosClicked == cell.getColumnPosition() && this.rowPosClicked == cell.getRowPosition()){ this.buttonPressedPainter.paintCell(cell, gc, bounds, configRegistry); } else { @@ -75,16 +76,16 @@ public class ButtonCellPainter extends AbstractCellPainter implements IMouseActi } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return cell.getBounds().height; } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return cell.getBounds().width; } - private TimerTask getButtonFlashTimerTask(final ILayer layer){ + private TimerTask getButtonFlashTimerTask(final Layer layer){ return new TimerTask() { @Override public void run() { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CellPainterWrapper.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CellPainterWrapper.java index 41218d4e..1eb5563d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CellPainterWrapper.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CellPainterWrapper.java @@ -15,35 +15,36 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; public abstract class CellPainterWrapper extends AbstractCellPainter { - private ICellPainter wrappedPainter; + private LayerCellPainter wrappedPainter; public CellPainterWrapper() {} - public CellPainterWrapper(final ICellPainter painter) { + public CellPainterWrapper(final LayerCellPainter painter) { this.wrappedPainter= painter; } - public void setWrappedPainter(final ICellPainter painter) { + public void setWrappedPainter(final LayerCellPainter painter) { this.wrappedPainter= painter; } - public ICellPainter getWrappedPainter() { + public LayerCellPainter getWrappedPainter() { return this.wrappedPainter; } - public LRectangle getWrappedPainterBounds(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public LRectangle getWrappedPainterBounds(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { return bounds; } @Override - public ICellPainter getCellPainterAt(final long x, final long y, final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LayerCellPainter getCellPainterAt(final long x, final long y, final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final LRectangle wrappedPainterBounds= getWrappedPainterBounds(cell, gc, adjustedCellBounds, configRegistry); if (this.wrappedPainter != null && wrappedPainterBounds.contains(x, y)) { return this.wrappedPainter.getCellPainterAt(x, y, cell, gc, wrappedPainterBounds, configRegistry); @@ -53,17 +54,17 @@ public abstract class CellPainterWrapper extends AbstractCellPainter { } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return this.wrappedPainter != null ? this.wrappedPainter.getPreferredWidth(cell, gc, configRegistry) : 0; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return this.wrappedPainter != null ? this.wrappedPainter.getPreferredHeight(cell, gc, configRegistry) : 0; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { if (this.wrappedPainter != null) { this.wrappedPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CheckBoxPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CheckBoxPainter.java index 054ca81e..936f539a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CheckBoxPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/CheckBoxPainter.java @@ -16,9 +16,9 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.Image; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -47,19 +47,19 @@ public class CheckBoxPainter extends ImagePainter { } @Override - protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Image getImage(final LayerCell cell, final ConfigRegistry configRegistry) { return isChecked(cell, configRegistry) ? this.checkedImg : this.uncheckedImg; } - protected boolean isChecked(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected boolean isChecked(final LayerCell cell, final ConfigRegistry configRegistry) { return convertDataType(cell, configRegistry).booleanValue(); } - protected Boolean convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Boolean convertDataType(final LayerCell cell, final ConfigRegistry configRegistry) { if (cell.getDataValue(0, null) instanceof Boolean) { return (Boolean) cell.getDataValue(0, null); } - final IDisplayConverter displayConverter= configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); + final IDisplayConverter displayConverter= configRegistry.getAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getLabels().getLabels()); Boolean convertedValue= null; if (displayConverter != null) { convertedValue= (Boolean) displayConverter.canonicalToDisplayValue(cell, configRegistry, cell.getDataValue(0, null)); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ColumnHeaderCheckBoxPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ColumnHeaderCheckBoxPainter.java index 7ce2f68c..d2612d8e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ColumnHeaderCheckBoxPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ColumnHeaderCheckBoxPainter.java @@ -16,11 +16,11 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.Image; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -31,9 +31,9 @@ public class ColumnHeaderCheckBoxPainter extends ImagePainter { private final Image semicheckedImg; private final Image uncheckedImg; - private final ILayer columnDataLayer; + private final Layer columnDataLayer; - public ColumnHeaderCheckBoxPainter(final ILayer columnDataLayer) { + public ColumnHeaderCheckBoxPainter(final Layer columnDataLayer) { this( columnDataLayer, GUIHelper.getImage("checked"), //$NON-NLS-1$ @@ -42,7 +42,7 @@ public class ColumnHeaderCheckBoxPainter extends ImagePainter { ); } - public ColumnHeaderCheckBoxPainter(final ILayer columnLayer, final Image checkedImg, final Image semicheckedImage, final Image uncheckedImg) { + public ColumnHeaderCheckBoxPainter(final Layer columnLayer, final Image checkedImg, final Image semicheckedImage, final Image uncheckedImg) { this.columnDataLayer= columnLayer; this.checkedImg= checkedImg; this.semicheckedImg= semicheckedImage; @@ -58,8 +58,8 @@ public class ColumnHeaderCheckBoxPainter extends ImagePainter { } @Override - protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) { - final long columnPosition= LayerUtil.convertColumnPosition(cell.getLayer(), cell.getColumnPosition(), this.columnDataLayer); + protected Image getImage(final LayerCell cell, final ConfigRegistry configRegistry) { + final long columnPosition= LayerUtils.convertColumnPosition(cell.getLayer(), cell.getColumnPosition(), this.columnDataLayer); final long checkedCellsCount= getCheckedCellsCount(columnPosition, configRegistry); @@ -74,11 +74,11 @@ public class ColumnHeaderCheckBoxPainter extends ImagePainter { } } - public long getCheckedCellsCount(final long columnPosition, final IConfigRegistry configRegistry) { + public long getCheckedCellsCount(final long columnPosition, final ConfigRegistry configRegistry) { long checkedCellsCount= 0; for (long rowPosition= 0; rowPosition < this.columnDataLayer.getRowCount(); rowPosition++) { - final ILayerCell columnCell= this.columnDataLayer.getCellByPosition(columnPosition, rowPosition); + final LayerCell columnCell= this.columnDataLayer.getCellByPosition(columnPosition, rowPosition); if (isChecked(columnCell, configRegistry)) { checkedCellsCount++; } @@ -86,15 +86,15 @@ public class ColumnHeaderCheckBoxPainter extends ImagePainter { return checkedCellsCount; } - protected boolean isChecked(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected boolean isChecked(final LayerCell cell, final ConfigRegistry configRegistry) { return convertDataType(cell, configRegistry).booleanValue(); } - protected Boolean convertDataType(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Boolean convertDataType(final LayerCell cell, final ConfigRegistry configRegistry) { if (cell.getDataValue(0, null) instanceof Boolean) { return (Boolean) cell.getDataValue(0, null); } - final IDisplayConverter displayConverter= configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); + final IDisplayConverter displayConverter= configRegistry.getAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getLabels().getLabels()); Boolean convertedValue= null; if (displayConverter != null) { try { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/DiagCellPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/DiagCellPainter.java index 2d21683b..1405a78d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/DiagCellPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/DiagCellPainter.java @@ -20,9 +20,9 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -41,7 +41,7 @@ public class DiagCellPainter extends BackgroundPainter { @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { super.paintCell(cell, gc, bounds, configRegistry); gc.setForeground(this.color); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GradientBackgroundPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GradientBackgroundPainter.java index e9b1874f..b2c88f29 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GradientBackgroundPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GradientBackgroundPainter.java @@ -15,24 +15,26 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.ConfigRegistry; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; /** * Paints the background of the cell with a gradient sweeping using the style configuration. * To configure the gradient sweeping the following style attributes need to be configured - * in the {@link ConfigRegistry}: + * in the {@link BasicConfigRegistry}: * <ul> - * <li>{@link CellStyleAttributes#GRADIENT_FOREGROUND_COLOR} or {@link CellStyleAttributes#FOREGROUND_COLOR}</li> - * <li>{@link CellStyleAttributes#GRADIENT_BACKGROUND_COLOR} or {@link CellStyleAttributes#BACKGROUND_COLOR}</li> + * <li>{@link CellStyling#GRADIENT_FOREGROUND_COLOR} or {@link CellStyling#FOREGROUND_COLOR}</li> + * <li>{@link CellStyling#GRADIENT_BACKGROUND_COLOR} or {@link CellStyling#BACKGROUND_COLOR}</li> * </ul> - * If none of these values are registered in the {@link ConfigRegistry} the painting is skipped. + * If none of these values are registered in the {@link BasicConfigRegistry} the painting is skipped. * <p> * Can be used as a cell painter or a decorator. */ @@ -65,26 +67,26 @@ public class GradientBackgroundPainter extends CellPainterWrapper { /** * Creates a {@link GradientBackgroundPainter} as wrapper for the given painter with a gradient sweeping from * left to right. - * @param painter The {@link ICellPainter} that is wrapped by this {@link GradientBackgroundPainter} + * @param painter The {@link LayerCellPainter} that is wrapped by this {@link GradientBackgroundPainter} */ - public GradientBackgroundPainter(final ICellPainter painter) { + public GradientBackgroundPainter(final LayerCellPainter painter) { this(painter, false); } /** * Creates a {@link GradientBackgroundPainter} as wrapper for the given painter where the sweeping direction * can be set. - * @param painter The {@link ICellPainter} that is wrapped by this {@link GradientBackgroundPainter} + * @param painter The {@link LayerCellPainter} that is wrapped by this {@link GradientBackgroundPainter} * @param vertical if <code>true</code> sweeps from top to bottom, else * sweeps from left to right. <code>false</code> is default */ - public GradientBackgroundPainter(final ICellPainter painter, final boolean vertical) { + public GradientBackgroundPainter(final LayerCellPainter painter, final boolean vertical) { super(painter); this.vertical= vertical; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { final Color foregroundColor= getForeGroundColour(cell, configRegistry); final Color backgroundColor= getBackgroundColour(cell, configRegistry); if (backgroundColor != null && foregroundColor != null) { @@ -93,7 +95,7 @@ public class GradientBackgroundPainter extends CellPainterWrapper { gc.setForeground(foregroundColor); gc.setBackground(backgroundColor); - final org.eclipse.swt.graphics.Rectangle rect= GraphicsUtils.safe(bounds); + final Rectangle rect= GraphicsUtils.safe(bounds); gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height, this.vertical); gc.setForeground(originalForeground); @@ -104,33 +106,33 @@ public class GradientBackgroundPainter extends CellPainterWrapper { } /** - * Searches the foreground color to be used for gradient sweeping. First checks the {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} if there - * is a value for the attribute {@link CellStyleAttributes#GRADIENT_FOREGROUND_COLOR} is registered. If there is one - * this value will be returned, if not it is checked if there is a value registered for {@link CellStyleAttributes#FOREGROUND_COLOR} + * Searches the foreground color to be used for gradient sweeping. First checks the {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} if there + * is a value for the attribute {@link CellStyling#GRADIENT_FOREGROUND_COLOR} is registered. If there is one + * this value will be returned, if not it is checked if there is a value registered for {@link CellStyling#FOREGROUND_COLOR} * and returned. If there is no value registered for any of these attributes, <code>null</code> will be returned which * will skip the painting. - * @param cell The {@link org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell} for which the style attributes should be retrieved out of the {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} - * @param configRegistry The {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} to retrieve the attribute values from. + * @param cell The {@link org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell} for which the style attributes should be retrieved out of the {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} + * @param configRegistry The {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} to retrieve the attribute values from. * @return The {@link Color} to use as foreground color of the gradient sweeping or <code>null</code> if none was configured. */ - protected Color getForeGroundColour(final ILayerCell cell, final IConfigRegistry configRegistry) { - final Color fgColor= CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.GRADIENT_FOREGROUND_COLOR); - return fgColor != null ? fgColor : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR); + protected Color getForeGroundColour(final LayerCell cell, final ConfigRegistry configRegistry) { + final Color fgColor= CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.GRADIENT_FOREGROUND_COLOR); + return fgColor != null ? fgColor : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.FOREGROUND_COLOR); } /** - * Searches the background color to be used for gradient sweeping. First checks the {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} if there - * is a value for the attribute {@link CellStyleAttributes#GRADIENT_BACKGROUND_COLOR} is registered. If there is one - * this value will be returned, if not it is checked if there is a value registered for {@link CellStyleAttributes#BACKGROUND_COLOR} + * Searches the background color to be used for gradient sweeping. First checks the {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} if there + * is a value for the attribute {@link CellStyling#GRADIENT_BACKGROUND_COLOR} is registered. If there is one + * this value will be returned, if not it is checked if there is a value registered for {@link CellStyling#BACKGROUND_COLOR} * and returned. If there is no value registered for any of these attributes, <code>null</code> will be returned which * will skip the painting. - * @param cell The {@link org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell} for which the style attributes should be retrieved out of the {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} - * @param configRegistry The {@link org.eclipse.statet.ecommons.waltable.config.ConfigRegistry} to retrieve the attribute values from. + * @param cell The {@link org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell} for which the style attributes should be retrieved out of the {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} + * @param configRegistry The {@link org.eclipse.statet.ecommons.waltable.core.config.BasicConfigRegistry} to retrieve the attribute values from. * @return The {@link Color} to use as background color of the gradient sweeping or <code>null</code> if none was configured. */ - protected Color getBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry) { - final Color bgColor= CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.GRADIENT_BACKGROUND_COLOR); - return bgColor != null ? bgColor : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + protected Color getBackgroundColour(final LayerCell cell, final ConfigRegistry configRegistry) { + final Color bgColor= CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.GRADIENT_BACKGROUND_COLOR); + return bgColor != null ? bgColor : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.BACKGROUND_COLOR); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GraphicsUtils.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GraphicsUtils.java index cff1e2d0..d7f3cb75 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GraphicsUtils.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/GraphicsUtils.java @@ -23,6 +23,8 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; + /** * This class contains utility methods for drawing graphics @@ -32,13 +34,6 @@ import org.eclipse.swt.widgets.Display; public class GraphicsUtils { - public static final int check(final long pixel) { - if (pixel < Integer.MIN_VALUE || pixel > Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - return (int) pixel; - } - public static final int safe(final long pixel) { return (pixel <= Integer.MIN_VALUE) ? Integer.MIN_VALUE : ((pixel >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) pixel); @@ -50,7 +45,7 @@ public class GraphicsUtils { return new Rectangle(sx, sy, safe(x + width) - sx, safe(y + height) - sy); } - public static final Rectangle safe(final org.eclipse.statet.ecommons.waltable.coordinate.LRectangle rect) { + public static final Rectangle safe(final LRectangle rect) { return safe(rect.x, rect.y, rect.width, rect.height); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ImagePainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ImagePainter.java index a05997de..8f6e8f31 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ImagePainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/ImagePainter.java @@ -17,13 +17,15 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** @@ -48,7 +50,7 @@ public class ImagePainter extends BackgroundPainter { } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { final Image image= getImage(cell, configRegistry); if (image != null) { return image.getBounds().width; @@ -58,7 +60,7 @@ public class ImagePainter extends BackgroundPainter { } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { final Image image= getImage(cell, configRegistry); if (image != null) { return image.getBounds().height; @@ -68,11 +70,11 @@ public class ImagePainter extends BackgroundPainter { } @Override - public ICellPainter getCellPainterAt(final long x, final long y, final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public LayerCellPainter getCellPainterAt(final long x, final long y, final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { final Image image= getImage(cell, configRegistry); if (image != null) { - final org.eclipse.swt.graphics.Rectangle imageBounds= image.getBounds(); - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + final Rectangle imageBounds= image.getBounds(); + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); final long x0= bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width); final long y0= bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height); if ( x >= x0 && @@ -86,23 +88,23 @@ public class ImagePainter extends BackgroundPainter { } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { if (this.paintBg) { super.paintCell(cell, gc, bounds, configRegistry); } final Image image= getImage(cell, configRegistry); if (image != null) { - final org.eclipse.swt.graphics.Rectangle imageBounds= image.getBounds(); - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + final Rectangle imageBounds= image.getBounds(); + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); gc.drawImage(image, safe(bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width)), safe(bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height))); } } - protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) { - return this.image != null ? this.image : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.IMAGE); + protected Image getImage(final LayerCell cell, final ConfigRegistry configRegistry) { + return this.image != null ? this.image : CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.IMAGE); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PasswordTextPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PasswordTextPainter.java index f88cb257..54026a4b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PasswordTextPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PasswordTextPainter.java @@ -15,20 +15,20 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; import org.eclipse.statet.ecommons.waltable.edit.editor.PasswordCellEditor; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** * Specialized {@link TextPainter} that will paint the text that should be showed within * a cell anonymized. Like in {@link PasswordCellEditor} every character will be replaced * with another echo character. The echo character can be configured by setting the - * attribute {@link CellStyleAttributes#PASSWORD_ECHO_CHAR} to the cell style to use. + * attribute {@link CellStyling#PASSWORD_ECHO_CHAR} to the cell style to use. * If no echo character is configured, the bullet character will be used as echo character. * * @see PasswordCellEditor @@ -66,10 +66,10 @@ public class PasswordTextPainter extends TextPainter { @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { //check for the configuration of a echo character in the corresponding cell style - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); - final Character configEchoChar= cellStyle.getAttributeValue(CellStyleAttributes.PASSWORD_ECHO_CHAR); + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + final Character configEchoChar= cellStyle.getAttributeValue(CellStyling.PASSWORD_ECHO_CHAR); if (configEchoChar != null) { this.echoChar= configEchoChar; } @@ -77,7 +77,7 @@ public class PasswordTextPainter extends TextPainter { } @Override - protected String getTextToDisplay(final ILayerCell cell, final GC gc, final long availableLength, final String text) { + protected String getTextToDisplay(final LayerCell cell, final GC gc, final long availableLength, final String text) { final String result= super.getTextToDisplay(cell, gc, availableLength, text); //replace all characters with the configured echo character return result.replaceAll(".", this.echoChar.toString()); //$NON-NLS-1$ diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PercentageBarCellPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PercentageBarCellPainter.java index 541f3add..b0f348d3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PercentageBarCellPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/PercentageBarCellPainter.java @@ -13,10 +13,12 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle.LineStyle; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.LineBorderDecorator; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.PaddingDecorator; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.PercentageBarDecorator; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.util.GUIHelper; public class PercentageBarCellPainter extends CellPainterWrapper { @@ -26,6 +28,8 @@ public class PercentageBarCellPainter extends CellPainterWrapper { } public PercentageBarCellPainter(final long outerPadding) { - super(new PaddingDecorator(new LineBorderDecorator(new PercentageBarDecorator(new TextPainter(false, false)), new BorderStyle()), outerPadding)); + super(new PaddingDecorator(new LineBorderDecorator(new PercentageBarDecorator(new TextPainter(false, false)), + new BorderStyle(1, GUIHelper.COLOR_BLACK, LineStyle.SOLID)), + outerPadding)); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TextPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TextPainter.java index 62a4a276..826bebf0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TextPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TextPainter.java @@ -13,19 +13,20 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.resize.DimPositionResizeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.resize.core.DimPositionResizeCommand; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.IStyle; /** @@ -93,29 +94,29 @@ public class TextPainter extends AbstractTextPainter { @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry){ + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry){ setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry)); return getWidthFromCache(gc, convertDataType(cell, configRegistry)) + (this.spacing*2) + 1; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { setupGCFromConfig(gc, CellStyleUtil.getCellStyle(cell, configRegistry)); return gc.textExtent(convertDataType(cell, configRegistry)).y + (this.spacing*2) + 1; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { if (this.paintBg) { super.paintCell(cell, gc, lRectangle, configRegistry); } if (this.paintFg) { - final org.eclipse.swt.graphics.Rectangle originalClipping= gc.getClipping(); + final Rectangle originalClipping= gc.getClipping(); gc.setClipping(safe(lRectangle).intersection(originalClipping)); - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); final boolean underline= renderUnderlined(cellStyle); @@ -135,7 +136,7 @@ public class TextPainter extends AbstractTextPainter { final long contentToCellDiff= (cell.getBounds().height - lRectangle.height); if (performRowResize(contentHeight, lRectangle)) { - final ILayer layer= cell.getLayer(); + final Layer layer= cell.getLayer(); layer.doCommand(new DimPositionResizeCommand(layer.getDim(VERTICAL), cell.getRowPosition(), (int) Math.min(contentHeight + contentToCellDiff, 0x7fff) )); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TreeCheckBoxPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TreeCheckBoxPainter.java index 9b45b600..a8ec71dd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TreeCheckBoxPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/TreeCheckBoxPainter.java @@ -15,9 +15,9 @@ package org.eclipse.statet.ecommons.waltable.painter.cell; import org.eclipse.swt.graphics.Image; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.edit.CheckBoxStateEnum; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -50,7 +50,7 @@ public abstract class TreeCheckBoxPainter extends ImagePainter { } @Override - protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Image getImage(final LayerCell cell, final ConfigRegistry configRegistry) { switch (getCheckBoxState(cell)) { case CHECKED: return this.checkedImg; @@ -61,6 +61,6 @@ public abstract class TreeCheckBoxPainter extends ImagePainter { } } - protected abstract CheckBoxStateEnum getCheckBoxState(ILayerCell cell); + protected abstract CheckBoxStateEnum getCheckBoxState(LayerCell cell); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/BeveledBorderDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/BeveledBorderDecorator.java index d51dec1c..72f12e0e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/BeveledBorderDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/BeveledBorderDecorator.java @@ -17,12 +17,13 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -42,7 +43,7 @@ public class BeveledBorderDecorator extends CellPainterWrapper { * * @param interiorPainter The painter which should be wrapped by this decorator. */ - public BeveledBorderDecorator(final ICellPainter interiorPainter) { + public BeveledBorderDecorator(final LayerCellPainter interiorPainter) { super(interiorPainter); } @@ -53,28 +54,28 @@ public class BeveledBorderDecorator extends CellPainterWrapper { * By default this flag is set to <code>true</code>. Set it to <code>false</code> if * the cell should be rendered sunk. */ - public BeveledBorderDecorator(final ICellPainter interiorPainter, final boolean uplift) { + public BeveledBorderDecorator(final LayerCellPainter interiorPainter, final boolean uplift) { super(interiorPainter); this.uplift= uplift; } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredWidth(cell, gc, configRegistry) + 4; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredHeight(cell, gc, configRegistry) + 4; } @Override - public LRectangle getWrappedPainterBounds(final ILayerCell cell, final GC gc, final LRectangle bounds, final IConfigRegistry configRegistry) { + public LRectangle getWrappedPainterBounds(final LayerCell cell, final GC gc, final LRectangle bounds, final ConfigRegistry configRegistry) { return new LRectangle(bounds.x + 2, bounds.y + 2, bounds.width - 4, bounds.height - 4); } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final LRectangle interiorBounds= getWrappedPainterBounds(cell, gc, adjustedCellBounds, configRegistry); super.paintCell(cell, gc, interiorBounds, configRegistry); @@ -83,7 +84,7 @@ public class BeveledBorderDecorator extends CellPainterWrapper { //TODO: Need to look at the border style - final org.eclipse.swt.graphics.Rectangle rect= safe(adjustedCellBounds); + final Rectangle rect= safe(adjustedCellBounds); // Up gc.setForeground(this.uplift ? GUIHelper.COLOR_WIDGET_LIGHT_SHADOW : GUIHelper.COLOR_WIDGET_DARK_SHADOW); gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CellPainterDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CellPainterDecorator.java index c3fb9880..60141c45 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CellPainterDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CellPainterDecorator.java @@ -18,11 +18,11 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum; @@ -30,20 +30,20 @@ import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum; /** * Decorates a cell painter with another cell painter. */ -public class CellPainterDecorator implements ICellPainter { +public class CellPainterDecorator implements LayerCellPainter { /** - * The base {@link ICellPainter} that is decorated. + * The base {@link LayerCellPainter} that is decorated. */ - private final ICellPainter baseCellPainter; + private final LayerCellPainter baseCellPainter; /** * The edge of the cell at which the decoration is applied. */ private final CellEdgeEnum cellEdge; /** - * The {@link ICellPainter} that is used to render the decoration. + * The {@link LayerCellPainter} that is used to render the decoration. */ - private final ICellPainter decoratorCellPainter; + private final LayerCellPainter decoratorCellPainter; /** * The spacing to use between base painter and decoration painter. * Note: If you want to add <b>padding</b> between the decoration and the cell border @@ -64,36 +64,36 @@ public class CellPainterDecorator implements ICellPainter { /** * Will create a {@link CellPainterDecorator} with the default spacing of 2 between base and * decoration painter, where the base painter is rendered dependent to the decoration. - * @param baseCellPainter The base {@link ICellPainter} that should be decorated + * @param baseCellPainter The base {@link LayerCellPainter} that should be decorated * @param cellEdge The edge of the cell at which the decoration should be applied - * @param decoratorCellPainter The {@link ICellPainter} that should be used to render the decoration. + * @param decoratorCellPainter The {@link LayerCellPainter} that should be used to render the decoration. */ - public CellPainterDecorator(final ICellPainter baseCellPainter, final CellEdgeEnum cellEdge, final ICellPainter decoratorCellPainter) { + public CellPainterDecorator(final LayerCellPainter baseCellPainter, final CellEdgeEnum cellEdge, final LayerCellPainter decoratorCellPainter) { this(baseCellPainter, cellEdge, 2, decoratorCellPainter); } /** * Will create a {@link CellPainterDecorator} with the default spacing of 2 between base and * decoration painter. If paintDecorationDependent is set to <code>false</code>, the spacing will be ignored. - * @param baseCellPainter The base {@link ICellPainter} that should be decorated + * @param baseCellPainter The base {@link LayerCellPainter} that should be decorated * @param cellEdge The edge of the cell at which the decoration should be applied - * @param decoratorCellPainter The {@link ICellPainter} that should be used to render the decoration. + * @param decoratorCellPainter The {@link LayerCellPainter} that should be used to render the decoration. * @param paintDecorationDependent Flag to specify whether the base painter should render dependent to the * decoration painter or not. */ - public CellPainterDecorator(final ICellPainter baseCellPainter, final CellEdgeEnum cellEdge, final ICellPainter decoratorCellPainter, final boolean paintDecorationDependent) { + public CellPainterDecorator(final LayerCellPainter baseCellPainter, final CellEdgeEnum cellEdge, final LayerCellPainter decoratorCellPainter, final boolean paintDecorationDependent) { this(baseCellPainter, cellEdge, 2, decoratorCellPainter, paintDecorationDependent); } /** * Will create a {@link CellPainterDecorator} with the given amount of pixels as spacing between base and * decoration painter, where the base painter is rendered dependent to the decoration. - * @param baseCellPainter The base {@link ICellPainter} that should be decorated + * @param baseCellPainter The base {@link LayerCellPainter} that should be decorated * @param cellEdge The edge of the cell at which the decoration should be applied * @param spacing The amount of pixels that should be used as spacing between decoration and base painter - * @param decoratorCellPainter The {@link ICellPainter} that should be used to render the decoration. + * @param decoratorCellPainter The {@link LayerCellPainter} that should be used to render the decoration. */ - public CellPainterDecorator(final ICellPainter baseCellPainter, final CellEdgeEnum cellEdge, final long spacing, final ICellPainter decoratorCellPainter) { + public CellPainterDecorator(final LayerCellPainter baseCellPainter, final CellEdgeEnum cellEdge, final long spacing, final LayerCellPainter decoratorCellPainter) { this(baseCellPainter, cellEdge, spacing, decoratorCellPainter, true); } @@ -101,13 +101,13 @@ public class CellPainterDecorator implements ICellPainter { * Will create a {@link CellPainterDecorator} with the given amount of pixels as spacing between base and * decoration painter. If paintDecorationDependent is set to <code>false</code>, the spacing will be ignored * while the decoration is mainly rendered over the base painter. - * @param baseCellPainter The base {@link ICellPainter} that should be decorated + * @param baseCellPainter The base {@link LayerCellPainter} that should be decorated * @param cellEdge The edge of the cell at which the decoration should be applied - * @param decoratorCellPainter The {@link ICellPainter} that should be used to render the decoration. + * @param decoratorCellPainter The {@link LayerCellPainter} that should be used to render the decoration. * @param paintDecorationDependent Flag to specify whether the base painter should render dependent to the * decoration painter or not. */ - public CellPainterDecorator(final ICellPainter baseCellPainter, final CellEdgeEnum cellEdge, final long spacing, final ICellPainter decoratorCellPainter, final boolean paintDecorationDependent) { + public CellPainterDecorator(final LayerCellPainter baseCellPainter, final CellEdgeEnum cellEdge, final long spacing, final LayerCellPainter decoratorCellPainter, final boolean paintDecorationDependent) { this.baseCellPainter= baseCellPainter; this.cellEdge= cellEdge; this.spacing= spacing; @@ -125,7 +125,7 @@ public class CellPainterDecorator implements ICellPainter { } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { switch (this.cellEdge) { case TOP_LEFT: case TOP_RIGHT: @@ -148,7 +148,7 @@ public class CellPainterDecorator implements ICellPainter { } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { switch (this.cellEdge) { case TOP_LEFT: case TOP_RIGHT: @@ -171,13 +171,13 @@ public class CellPainterDecorator implements ICellPainter { } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final LRectangle baseCellPainterBounds= this.paintDecorationDependent ? getBaseCellPainterBounds(cell, gc, adjustedCellBounds, configRegistry) : adjustedCellBounds; final LRectangle decoratorCellPainterBounds= getDecoratorCellPainterBounds(cell, gc, adjustedCellBounds, configRegistry); final Color originalBg= gc.getBackground(); - gc.setBackground(CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); + gc.setBackground(CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.BACKGROUND_COLOR)); gc.fillRectangle(safe(adjustedCellBounds)); @@ -191,7 +191,7 @@ public class CellPainterDecorator implements ICellPainter { * * @return The LRectangle which can be used by the base cell painter. */ - public LRectangle getBaseCellPainterBounds(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LRectangle getBaseCellPainterBounds(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final long preferredDecoratorWidth= this.decoratorCellPainter.getPreferredWidth(cell, gc, configRegistry); final long preferredDecoratorHeight= this.decoratorCellPainter.getPreferredHeight(cell, gc, configRegistry); @@ -266,7 +266,7 @@ public class CellPainterDecorator implements ICellPainter { /** * @return The LRectangle to paint the decoration. */ - public LRectangle getDecoratorCellPainterBounds(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LRectangle getDecoratorCellPainterBounds(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final long preferredDecoratorWidth= this.decoratorCellPainter.getPreferredWidth(cell, gc, configRegistry); final long preferredDecoratorHeight= this.decoratorCellPainter.getPreferredHeight(cell, gc, configRegistry); @@ -327,7 +327,7 @@ public class CellPainterDecorator implements ICellPainter { } @Override - public ICellPainter getCellPainterAt(final long x, final long y, final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LayerCellPainter getCellPainterAt(final long x, final long y, final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final LRectangle decoratorCellPainterBounds= getDecoratorCellPainterBounds(cell, gc, adjustedCellBounds, configRegistry); if (decoratorCellPainterBounds.contains(x, y)) { return this.decoratorCellPainter.getCellPainterAt(x, y, cell, gc, decoratorCellPainterBounds, configRegistry); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CustomLineBorderDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CustomLineBorderDecorator.java deleted file mode 100644 index d586f173..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/CustomLineBorderDecorator.java +++ /dev/null @@ -1,250 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Dirk Fauth and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.painter.cell.decorator; - -import java.util.List; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; - -import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; - - -/** - * {@link NatTable} decorator class which is used to draw borders for cells whose LabelStack - * contains border related labels. - * <p>Compared to the LineBorderDecorator which paints a border for every side of a cell, - * with this implementation you are free to choose for which side a border should be painted - * or not.</p> - */ -public class CustomLineBorderDecorator extends CellPainterWrapper { - - /** - * Label for adding a border at the top of a cell. - */ - public static final String TOP_LINE_BORDER_LABEL= "topLineBorderLabel"; //$NON-NLS-1$ - /** - * Label for adding a border at the bottom of a cell. - */ - public static final String BOTTOM_LINE_BORDER_LABEL= "bottomLineBorderLabel"; //$NON-NLS-1$ - /** - * Label for adding a border at the left of a cell. - */ - public static final String LEFT_LINE_BORDER_LABEL= "leftLineBorderLabel"; //$NON-NLS-1$ - /** - * Label for adding a border at the right of a cell. - */ - public static final String RIGHT_LINE_BORDER_LABEL= "rightLineBorderLabel"; //$NON-NLS-1$ - - /** - * The default border style which will be used if no border style is configured via - * cell style configuration. Can be <code>null</code> if there should be no border - * rendered by default. - */ - private final BorderStyle defaultBorderStyle; - - /** - * Creates a new LabelLineBorderDecorator wrapping the given interior painter and no - * default border style. - * @param interiorPainter The painter to be wrapped by this decorator. - */ - public CustomLineBorderDecorator(final ICellPainter interiorPainter) { - this(interiorPainter, null); - } - - /** - * Creates a new LabelLineBorderDecorator wrapping the given interior painter using - * the given BorderStyle as default. - * @param interiorPainter The painter to be wrapped by this decorator. - * @param defaultBorderStyle The BorderStyle to use as default if there is no BorderStyle - * configured via cell styles. Can be <code>null</code>. - */ - public CustomLineBorderDecorator(final ICellPainter interiorPainter, final BorderStyle defaultBorderStyle) { - super(interiorPainter); - this.defaultBorderStyle= defaultBorderStyle; - } - - @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { - final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); - final long borderThickness= borderStyle != null ? borderStyle.getThickness() : 0; - - long borderLineCount= 0; - //check how many border lines are configured for that cell - final List<String> labels= cell.getConfigLabels().getLabels(); - if (labels.contains(RIGHT_LINE_BORDER_LABEL)) { - borderLineCount++; - } - if (labels.contains(LEFT_LINE_BORDER_LABEL)) { - borderLineCount++; - } - - return super.getPreferredWidth(cell, gc, configRegistry) + (borderThickness * borderLineCount); - } - - @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { - final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); - final long borderThickness= borderStyle != null ? borderStyle.getThickness() : 0; - - long borderLineCount= 0; - //check how many border lines are configured for that cell - final List<String> labels= cell.getConfigLabels().getLabels(); - if (labels.contains(TOP_LINE_BORDER_LABEL)) { - borderLineCount++; - } - if (labels.contains(BOTTOM_LINE_BORDER_LABEL)) { - borderLineCount++; - } - - return super.getPreferredHeight(cell, gc, configRegistry) + (borderThickness * borderLineCount); - } - - private BorderStyle getBorderStyle(final ILayerCell cell, final IConfigRegistry configRegistry) { - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); - BorderStyle borderStyle= cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE); - if (borderStyle == null) { - borderStyle= this.defaultBorderStyle; - } - return borderStyle; - } - - @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { - final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); - final int borderThickness= borderStyle != null ? borderStyle.getThickness() : 0; - - //check how many border lines are configured for that cell - final List<String> labels= cell.getConfigLabels().getLabels(); - - long leftBorderThickness= 0; - long rightBorderThickness= 0; - long topBorderThickness= 0; - long bottomBorderThickness= 0; - - if (labels.contains(LEFT_LINE_BORDER_LABEL)) { - leftBorderThickness= borderThickness; - } - if (labels.contains(RIGHT_LINE_BORDER_LABEL)) { - rightBorderThickness= borderThickness; - } - if (labels.contains(TOP_LINE_BORDER_LABEL)) { - topBorderThickness= borderThickness; - } - if (labels.contains(BOTTOM_LINE_BORDER_LABEL)) { - bottomBorderThickness= borderThickness; - } - - final LRectangle interiorBounds = - new LRectangle( - lRectangle.x + leftBorderThickness, - lRectangle.y + topBorderThickness, - (lRectangle.width - leftBorderThickness - rightBorderThickness), - (lRectangle.height - topBorderThickness - bottomBorderThickness) - ); - super.paintCell(cell, gc, interiorBounds, configRegistry); - - if (borderStyle == null || borderThickness <= 0 || - (leftBorderThickness == 0 && rightBorderThickness == 0 - && topBorderThickness == 0 && bottomBorderThickness == 0)) { - return; - } - - // Save GC settings - final Color originalForeground= gc.getForeground(); - final int originalLineWidth= gc.getLineWidth(); - final int originalLineStyle= gc.getLineStyle(); - - gc.setLineWidth(borderThickness); - - final LRectangle borderArea= new LRectangle(lRectangle.x, lRectangle.y, lRectangle.width, lRectangle.height); - if (borderThickness >= 1) { - int shift= 0; - int correction= 0; - - if ((borderThickness % 2) == 0) { - shift= borderThickness / 2; - } else { - shift= borderThickness / 2; - correction= 1; - } - - if (leftBorderThickness >= 1) { - borderArea.x+= shift; - borderArea.width-= shift; - } - - if (rightBorderThickness >= 1) { - borderArea.width-= shift + correction; - } - - if (topBorderThickness >= 1) { - borderArea.y+= shift; - borderArea.height-= shift; - } - - if (bottomBorderThickness >= 1) { - borderArea.height-= shift + correction; - } - } - - gc.setLineStyle(SWTUtil.toSWT(borderStyle.getLineStyle())); - gc.setForeground(borderStyle.getColor()); - - final org.eclipse.swt.graphics.Rectangle rect= GraphicsUtils.safe(borderArea); - //if all borders are set draw a rectangle - if (leftBorderThickness > 0 && rightBorderThickness > 0 - && topBorderThickness > 0 && bottomBorderThickness > 0) { - gc.drawRectangle(rect); - } - //else draw a line for every set border - else { - final Point topLeftPos= new Point(rect.x, rect.y); - final Point topRightPos= new Point(rect.x + rect.width, rect.y); - final Point bottomLeftPos= new Point(rect.x, rect.y + rect.height); - final Point bottomRightPos= new Point(rect.x + rect.width, rect.y + rect.height); - - if (leftBorderThickness > 0) { - gc.drawLine(topLeftPos.x, topLeftPos.y, bottomLeftPos.x, bottomLeftPos.y); - } - if (rightBorderThickness > 0) { - gc.drawLine(topRightPos.x, topRightPos.y, bottomRightPos.x, bottomRightPos.y); - } - if (topBorderThickness > 0) { - gc.drawLine(topLeftPos.x, topLeftPos.y, topRightPos.x, topRightPos.y); - } - if (bottomBorderThickness > 0) { - gc.drawLine(bottomLeftPos.x, bottomLeftPos.y, bottomRightPos.x, bottomRightPos.y); - } - } - - // Restore GC settings - gc.setForeground(originalForeground); - gc.setLineWidth(originalLineWidth); - gc.setLineStyle(originalLineStyle); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/LineBorderDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/LineBorderDecorator.java index acdeb7cd..c76b620e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/LineBorderDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/LineBorderDecorator.java @@ -16,35 +16,35 @@ package org.eclipse.statet.ecommons.waltable.painter.cell.decorator; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; import org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; public class LineBorderDecorator extends CellPainterWrapper { private final BorderStyle defaultBorderStyle; - public LineBorderDecorator(final ICellPainter interiorPainter) { + public LineBorderDecorator(final LayerCellPainter interiorPainter) { this(interiorPainter, null); } - public LineBorderDecorator(final ICellPainter interiorPainter, final BorderStyle defaultBorderStyle) { + public LineBorderDecorator(final LayerCellPainter interiorPainter, final BorderStyle defaultBorderStyle) { super(interiorPainter); this.defaultBorderStyle= defaultBorderStyle; } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); final long padding= borderStyle != null ? Math.max(borderStyle.getOffset() + borderStyle.getThickness(), 0) : 0; @@ -52,16 +52,16 @@ public class LineBorderDecorator extends CellPainterWrapper { } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); final long padding= borderStyle != null ? Math.max(borderStyle.getOffset() + borderStyle.getThickness(), 0) : 0; return super.getPreferredHeight(cell, gc, configRegistry) + (padding * 2); } - private BorderStyle getBorderStyle(final ILayerCell cell, final IConfigRegistry configRegistry) { - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); - BorderStyle borderStyle= cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE); + private BorderStyle getBorderStyle(final LayerCell cell, final ConfigRegistry configRegistry) { + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + BorderStyle borderStyle= cellStyle.getAttributeValue(CellStyling.BORDER_STYLE); if (borderStyle == null) { borderStyle= this.defaultBorderStyle; } @@ -69,7 +69,7 @@ public class LineBorderDecorator extends CellPainterWrapper { } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { final BorderStyle borderStyle= getBorderStyle(cell, configRegistry); final long padding= borderStyle != null ? Math.max(borderStyle.getOffset() + borderStyle.getThickness(), 0) : 0; @@ -93,14 +93,8 @@ public class LineBorderDecorator extends CellPainterWrapper { final long borderOffset= borderStyle.getOffset(); final int borderThickness= borderStyle.getThickness(); - final LRectangle borderArea= new LRectangle( - lRectangle.x + borderOffset, - lRectangle.y + borderOffset, - lRectangle.width - (borderOffset * 2), - lRectangle.height - (borderOffset * 2) - ); - { - long shift= 0; + final LRectangle borderArea; + { long shift= 0; long areaShift= 0; if ((borderThickness % 2) == 0) { shift= borderThickness / 2; @@ -109,14 +103,15 @@ public class LineBorderDecorator extends CellPainterWrapper { shift= borderThickness / 2; areaShift= (shift * 2) + 1; } - borderArea.x+= shift; - borderArea.y+= shift; - borderArea.width-= areaShift; - borderArea.height-= areaShift; + borderArea= new LRectangle( + lRectangle.x + borderOffset + shift, + lRectangle.y + borderOffset + shift, + lRectangle.width - (borderOffset * 2) - areaShift, + lRectangle.height - (borderOffset * 2) - areaShift ); } - + gc.setLineWidth(borderThickness); - gc.setLineStyle(SWTUtil.toSWT(borderStyle.getLineStyle())); + gc.setLineStyle(SwtUtils.toSWT(borderStyle.getLineStyle())); gc.setForeground(borderStyle.getColor()); gc.drawRectangle(GraphicsUtils.safe(borderArea)); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PaddingDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PaddingDecorator.java index f931c99a..450a7472 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PaddingDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PaddingDecorator.java @@ -18,16 +18,16 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; public class PaddingDecorator extends CellPainterWrapper { @@ -39,15 +39,15 @@ public class PaddingDecorator extends CellPainterWrapper { private final long leftPadding; - public PaddingDecorator(final ICellPainter interiorPainter) { + public PaddingDecorator(final LayerCellPainter interiorPainter) { this(interiorPainter, 2); } - public PaddingDecorator(final ICellPainter interiorPainter, final long padding) { + public PaddingDecorator(final LayerCellPainter interiorPainter, final long padding) { this(interiorPainter, padding, padding, padding, padding); } - public PaddingDecorator(final ICellPainter interiorPainter, final long topPadding, final long rightPadding, final long bottomPadding, final long leftPadding) { + public PaddingDecorator(final LayerCellPainter interiorPainter, final long topPadding, final long rightPadding, final long bottomPadding, final long leftPadding) { super(interiorPainter); this.topPadding= topPadding; this.rightPadding= rightPadding; @@ -57,17 +57,17 @@ public class PaddingDecorator extends CellPainterWrapper { @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return this.leftPadding + super.getPreferredWidth(cell, gc, configRegistry) + this.rightPadding; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return this.topPadding + super.getPreferredHeight(cell, gc, configRegistry) + this.bottomPadding; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { final Color originalBg= gc.getBackground(); final Color cellStyleBackground= getBackgroundColor(cell, configRegistry); if (cellStyleBackground != null) { @@ -94,16 +94,16 @@ public class PaddingDecorator extends CellPainterWrapper { ); } - protected Color getBackgroundColor(final ILayerCell cell, final IConfigRegistry configRegistry) { - return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + protected Color getBackgroundColor(final LayerCell cell, final ConfigRegistry configRegistry) { + return CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyling.BACKGROUND_COLOR); } @Override - public ICellPainter getCellPainterAt(final long x, final long y, final ILayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final IConfigRegistry configRegistry) { + public LayerCellPainter getCellPainterAt(final long x, final long y, final LayerCell cell, final GC gc, final LRectangle adjustedCellBounds, final ConfigRegistry configRegistry) { //need to take the alignment into account - final IStyle cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); + final Style cellStyle= CellStyleUtil.getCellStyle(cell, configRegistry); - final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT); + final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT); long horizontalAlignmentPadding= 0; switch (horizontalAlignment) { case LEFT: horizontalAlignmentPadding= this.leftPadding; @@ -112,7 +112,7 @@ public class PaddingDecorator extends CellPainterWrapper { break; } - final VerticalAlignment verticalAlignment= cellStyle.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT); + final VerticalAlignment verticalAlignment= cellStyle.getAttributeValue(CellStyling.VERTICAL_ALIGNMENT); long verticalAlignmentPadding= 0; switch (verticalAlignment) { case TOP: verticalAlignmentPadding= this.topPadding; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PercentageBarDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PercentageBarDecorator.java index 0b0e6912..7240af49 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PercentageBarDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/PercentageBarDecorator.java @@ -19,17 +19,17 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Pattern; import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; /** @@ -41,22 +41,22 @@ public class PercentageBarDecorator extends CellPainterWrapper { public static final ConfigAttribute<Color> PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR= new ConfigAttribute<>(); public static final ConfigAttribute<Color> PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR= new ConfigAttribute<>(); - private static final Color DEFAULT_COMPLETE_REGION_START_COLOR= GUIHelper.getColor(new RGB(187, 216, 254)); - private static final Color DEFAULT_COMPLETE_REGION_END_COLOR= GUIHelper.getColor(new RGB(255, 255, 255)); + private static final Color DEFAULT_COMPLETE_REGION_START_COLOR= new Color(new RGB(187, 216, 254)); + private static final Color DEFAULT_COMPLETE_REGION_END_COLOR= new Color(new RGB(255, 255, 255)); - public PercentageBarDecorator(final ICellPainter interiorPainter) { + public PercentageBarDecorator(final LayerCellPainter interiorPainter) { super(interiorPainter); } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { final Pattern originalBackgroundPattern= gc.getBackgroundPattern(); double factor= Math.min(1.0, ((Double) cell.getDataValue(0, null)).doubleValue()); factor= Math.max(0.0, factor); final LRectangle bar= new LRectangle(lRectangle.x, lRectangle.y, (long) (lRectangle.width * factor), lRectangle.height); - final org.eclipse.swt.graphics.Rectangle rect= safe(bar); + final Rectangle rect= safe(bar); final LRectangle bounds= cell.getBounds(); Color color1= CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/XPBackgroundDecorator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/XPBackgroundDecorator.java index bea7648f..e0e8b5c3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/XPBackgroundDecorator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/painter/cell/decorator/XPBackgroundDecorator.java @@ -18,11 +18,11 @@ import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.sa import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.BackgroundPainter; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -38,32 +38,32 @@ public class XPBackgroundDecorator extends BackgroundPainter { public final Color highlightColor2; public final Color highlightColor3; - public XPBackgroundDecorator(final ICellPainter interiorPainter) { + public XPBackgroundDecorator(final LayerCellPainter interiorPainter) { super(interiorPainter); - this.separatorColor= GUIHelper.getColor(199, 197, 178); + this.separatorColor= new Color(199, 197, 178); - this.gradientColor1= GUIHelper.getColor(226, 222, 205); - this.gradientColor2= GUIHelper.getColor(214, 210, 194); - this.gradientColor3= GUIHelper.getColor(203, 199, 184); + this.gradientColor1= new Color(226, 222, 205); + this.gradientColor2= new Color(214, 210, 194); + this.gradientColor3= new Color(203, 199, 184); - this.highlightColor1= GUIHelper.getColor(250, 171, 0); - this.highlightColor2= GUIHelper.getColor(252, 194, 71); - this.highlightColor3= GUIHelper.getColor(250, 178, 24); + this.highlightColor1= new Color(250, 171, 0); + this.highlightColor2= new Color(252, 194, 71); + this.highlightColor3= new Color(250, 178, 24); } @Override - public long getPreferredWidth(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredWidth(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredWidth(cell, gc, configRegistry) + 4; } @Override - public long getPreferredHeight(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + public long getPreferredHeight(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { return super.getPreferredHeight(cell, gc, configRegistry) + 4; } @Override - public void paintCell(final ILayerCell cell, final GC gc, final LRectangle lRectangle, final IConfigRegistry configRegistry) { + public void paintCell(final LayerCell cell, final GC gc, final LRectangle lRectangle, final ConfigRegistry configRegistry) { // Draw background super.paintCell(cell, gc, lRectangle, configRegistry); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/ColorPersistor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/ColorPersistor.java index 43152b78..eb748ba6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/ColorPersistor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/ColorPersistor.java @@ -13,9 +13,9 @@ package org.eclipse.statet.ecommons.waltable.persistence; -import static org.eclipse.statet.ecommons.waltable.persistence.IPersistable.DOT; +import static org.eclipse.statet.ecommons.waltable.core.Persistable.DOT; -import java.util.Properties; +import java.util.Map; import org.eclipse.jface.resource.DataFormatException; import org.eclipse.jface.resource.StringConverter; @@ -23,28 +23,26 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; - public class ColorPersistor { public static final String STYLE_PERSISTENCE_PREFIX= "color"; //$NON-NLS-1$ public static final Color DEFAULT_COLOR= Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - public static void saveColor(String prefix, final Properties properties, final Color color) { + public static void saveColor(String prefix, final Map<String, String> properties, final Color color) { prefix= prefix + DOT + STYLE_PERSISTENCE_PREFIX; if (color == null) { return; } - properties.setProperty(prefix, asString(color)); + properties.put(prefix, asString(color)); } - public static Color loadColor(String prefix, final Properties properties) { + public static Color loadColor(String prefix, final Map<String, String> properties) { prefix= prefix + DOT + STYLE_PERSISTENCE_PREFIX; - final String colorAsString= properties.getProperty(prefix); + final String colorAsString= properties.get(prefix); if (colorAsString == null) { return null; } else { @@ -64,7 +62,7 @@ public class ColorPersistor { */ public static Color asColor(final String colorAsString) { try { - return GUIHelper.getColor(StringConverter.asRGB(colorAsString)); + return new Color(StringConverter.asRGB(colorAsString)); } catch (final DataFormatException e) { return DEFAULT_COLOR; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommand.java index d2b717e3..d2c3d0e2 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommand.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.persistence; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; public class DisplayPersistenceDialogCommand extends AbstractContextFreeCommand { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommandHandler.java index a60c8cd7..a650d264 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/DisplayPersistenceDialogCommandHandler.java @@ -15,10 +15,11 @@ package org.eclipse.statet.ecommons.waltable.persistence; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Properties; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; import org.eclipse.statet.ecommons.waltable.persistence.gui.PersistenceDialog; @@ -33,7 +34,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand /** * The Properties instance that should be used for saving and loading. */ - private Properties properties; + private Map<String, String> properties; /** * List of {@link IStateChangedListener}s that will be notified if states are changed @@ -52,7 +53,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand * It can be accessed via getProperties() for further usage. */ public DisplayPersistenceDialogCommandHandler() { - this(new Properties(), null); + this((Map)new Properties(), null); } /** @@ -66,7 +67,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand * in the opened dialog. */ public DisplayPersistenceDialogCommandHandler(final NatTable natTable) { - this(new Properties(), natTable); + this((Map)new Properties(), natTable); } /** @@ -74,7 +75,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand * instance. * @param properties The Properties instance that should be used for saving and loading. */ - public DisplayPersistenceDialogCommandHandler(final Properties properties) { + public DisplayPersistenceDialogCommandHandler(final Map<String, String> properties) { this(properties, null); } @@ -88,7 +89,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand * default configuration. This default configuration can't be modified anymore * in the opened dialog. */ - public DisplayPersistenceDialogCommandHandler(final Properties properties, final NatTable natTable) { + public DisplayPersistenceDialogCommandHandler(final Map<String, String> properties, final NatTable natTable) { if (properties == null) { throw new IllegalArgumentException("properties can not be null!"); //$NON-NLS-1$ } @@ -96,7 +97,7 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand if (natTable != null) { natTable.saveState("", this.properties); //$NON-NLS-1$ - this.properties.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, ""); //$NON-NLS-1$ + this.properties.put(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, ""); //$NON-NLS-1$ } } @@ -117,14 +118,14 @@ public class DisplayPersistenceDialogCommandHandler extends AbstractLayerCommand /** * @return The Properties instance that is used for saving and loading. */ - public Properties getProperties() { + public Map<String, String> getProperties() { return this.properties; } /** * @param properties The Properties instance that should be used for saving and loading. */ - public void setProperties(final Properties properties) { + public void setProperties(final Map<String, String> properties) { if (properties == null) { throw new IllegalArgumentException("properties can not be null!"); //$NON-NLS-1$ } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/PersistenceHelper.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/PersistenceHelper.java index 662018bc..acb94c05 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/PersistenceHelper.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/PersistenceHelper.java @@ -17,9 +17,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Properties; +import java.util.Map; import java.util.Set; +import org.eclipse.statet.ecommons.waltable.core.Persistable; import org.eclipse.statet.ecommons.waltable.persistence.gui.PersistenceDialog; @@ -36,13 +37,13 @@ public class PersistenceHelper { * Can be interpreted as state configuration name. * @param properties The properties containing the state configuration. */ - public static void deleteState(final String prefix, final Properties properties) { + public static void deleteState(final String prefix, final Map<String, String> properties) { if (properties != null) { //build the key prefix to search for //always add the dot as states without a prefix are stored with a leading dot //and for named states it might be possible that there are some starting with //the same prefix, so the dot clarifies the prefix - final String keyPrefix= prefix + IPersistable.DOT; + final String keyPrefix= prefix + Persistable.DOT; //collect the keys to remove final List<Object> keysToRemove= new ArrayList<>(); @@ -67,7 +68,7 @@ public class PersistenceHelper { * @param properties The Properties to retrieve the containing states of * @return Collection of all state prefixes that are contained in the given properties. */ - public static Collection<String> getAvailableStates(final Properties properties) { + public static Collection<String> getAvailableStates(final Map<String, String> properties) { final Set<String> stateNames= new HashSet<>(); if (properties != null && !properties.isEmpty()) { for (final Object key : properties.keySet()) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/StylePersistor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/StylePersistor.java index 85397841..55cbc876 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/StylePersistor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/StylePersistor.java @@ -13,25 +13,26 @@ package org.eclipse.statet.ecommons.waltable.persistence; -import static org.eclipse.statet.ecommons.waltable.persistence.IPersistable.DOT; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.BACKGROUND_COLOR; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.BORDER_STYLE; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.FONT; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.FOREGROUND_COLOR; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.HORIZONTAL_ALIGNMENT; -import static org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes.VERTICAL_ALIGNMENT; +import static org.eclipse.statet.ecommons.waltable.core.Persistable.DOT; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.BACKGROUND_COLOR; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.BORDER_STYLE; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.FONT; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.FOREGROUND_COLOR; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.HORIZONTAL_ALIGNMENT; +import static org.eclipse.statet.ecommons.waltable.core.style.CellStyling.VERTICAL_ALIGNMENT; -import java.util.Properties; +import java.util.Map; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -60,7 +61,7 @@ public class StylePersistor { // Save - public static void saveStyle(String prefix, final Properties properties, final Style style) { + public static void saveStyle(String prefix, final Map<String, String> properties, final Style style) { prefix= prefix + DOT + STYLE_PERSISTENCE_PREFIX; saveColor(prefix + DOT + BG_COLOR_PREFIX, properties, style.getAttributeValue(BACKGROUND_COLOR)); @@ -74,35 +75,35 @@ public class StylePersistor { saveBorder(prefix, properties, style.getAttributeValue(BORDER_STYLE)); } - protected static void saveVAlign(final String prefix, final Properties properties, final VerticalAlignment vAlign) { + protected static void saveVAlign(final String prefix, final Map<String, String> properties, final VerticalAlignment vAlign) { if (vAlign == null) { return; } - properties.setProperty(prefix + DOT + V_ALIGNMENT_PREFIX, vAlign.name()); + properties.put(prefix + DOT + V_ALIGNMENT_PREFIX, vAlign.name()); } - protected static void saveHAlign(final String prefix, final Properties properties, final HorizontalAlignment hAlign) { + protected static void saveHAlign(final String prefix, final Map<String, String> properties, final HorizontalAlignment hAlign) { if (hAlign == null) { return; } - properties.setProperty(prefix + DOT + H_ALIGNMENT_PREFIX, hAlign.name()); + properties.put(prefix + DOT + H_ALIGNMENT_PREFIX, hAlign.name()); } - protected static void saveBorder(final String prefix, final Properties properties, final BorderStyle borderStyle) { + protected static void saveBorder(final String prefix, final Map<String, String> properties, final BorderStyle borderStyle) { if (borderStyle == null) { return; } - properties.setProperty(prefix + DOT + BORDER_PREFIX, String.valueOf(borderStyle.toString())); + properties.put(prefix + DOT + BORDER_PREFIX, String.valueOf(borderStyle.toString())); } - protected static void saveFont(final String prefix, final Properties properties, final Font font) { + protected static void saveFont(final String prefix, final Map<String, String> properties, final Font font) { if (font == null) { return; } - properties.setProperty(prefix + DOT + FONT_PREFIX, String.valueOf(font.getFontData()[0].toString())); + properties.put(prefix + DOT + FONT_PREFIX, String.valueOf(font.getFontData()[0].toString())); } - protected static void saveColor(final String prefix, final Properties properties, final Color color) { + protected static void saveColor(final String prefix, final Map<String, String> properties, final Color color) { if (color == null) { return; } @@ -111,87 +112,87 @@ public class StylePersistor { // Load - public static Style loadStyle(String prefix, final Properties properties) { - final Style style= new Style(); + public static BasicStyle loadStyle(String prefix, final Map<String, String> properties) { + final var style= new BasicStyle(); prefix= prefix + DOT + STYLE_PERSISTENCE_PREFIX; // BG Color final String bgColorPrefix= prefix + DOT + BG_COLOR_PREFIX; final Color bgColor= loadColor(bgColorPrefix, properties); if (bgColor != null) { - style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, bgColor); + style.setAttributeValue(CellStyling.BACKGROUND_COLOR, bgColor); } // FG Color final String fgColorPrefix= prefix + DOT + FG_COLOR_PREFIX; final Color fgColor= loadColor(fgColorPrefix, properties); if (fgColor != null) { - style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, fgColor); + style.setAttributeValue(CellStyling.FOREGROUND_COLOR, fgColor); } // Alignment final String hAlignPrefix= prefix + DOT + H_ALIGNMENT_PREFIX; final HorizontalAlignment hAlign= loadHAlignment(hAlignPrefix, properties); if (hAlign != null) { - style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, hAlign); + style.setAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT, hAlign); } final String vAlignPrefix= prefix + DOT + V_ALIGNMENT_PREFIX; final VerticalAlignment vAlign= loadVAlignment(vAlignPrefix, properties); if (vAlign != null) { - style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, vAlign); + style.setAttributeValue(CellStyling.VERTICAL_ALIGNMENT, vAlign); } // Font final String fontPrefix= prefix + DOT + FONT_PREFIX; final Font font= loadFont(fontPrefix, properties); if (font != null) { - style.setAttributeValue(CellStyleAttributes.FONT, font); + style.setAttributeValue(CellStyling.FONT, font); } // Border Style final String borderPrefix= prefix + DOT + BORDER_PREFIX; final BorderStyle borderStyle= loadBorderStyle(borderPrefix, properties); if (borderStyle != null) { - style.setAttributeValue(CellStyleAttributes.BORDER_STYLE, borderStyle); + style.setAttributeValue(CellStyling.BORDER_STYLE, borderStyle); } return style; } - private static BorderStyle loadBorderStyle(final String borderPrefix, final Properties properties) { - final String borderStyle= properties.getProperty(borderPrefix); + private static BorderStyle loadBorderStyle(final String borderPrefix, final Map<String, String> properties) { + final String borderStyle= properties.get(borderPrefix); if (borderStyle != null) { return new BorderStyle(borderStyle); } return null; } - private static Font loadFont(final String fontPrefix, final Properties properties) { - final String fontdata= properties.getProperty(fontPrefix); + private static Font loadFont(final String fontPrefix, final Map<String, String> properties) { + final String fontdata= properties.get(fontPrefix); if (fontdata != null) { return GUIHelper.getFont(new FontData(fontdata)); } return null; } - private static HorizontalAlignment loadHAlignment(final String hAlignPrefix, final Properties properties) { - final String enumName= properties.getProperty(hAlignPrefix); + private static HorizontalAlignment loadHAlignment(final String hAlignPrefix, final Map<String, String> properties) { + final String enumName= properties.get(hAlignPrefix); if (enumName != null) { return HorizontalAlignment.valueOf(enumName); } return null; } - private static VerticalAlignment loadVAlignment(final String vAlignPrefix, final Properties properties) { - final String enumName= properties.getProperty(vAlignPrefix); + private static VerticalAlignment loadVAlignment(final String vAlignPrefix, final Map<String, String> properties) { + final String enumName= properties.get(vAlignPrefix); if (enumName != null) { return VerticalAlignment.valueOf(enumName); } return null; } - protected static Color loadColor(final String prefix, final Properties properties) { + protected static Color loadColor(final String prefix, final Map<String, String> properties) { return ColorPersistor.loadColor(prefix, properties); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/gui/PersistenceDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/gui/PersistenceDialog.java index e0084dd4..0770bbdf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/gui/PersistenceDialog.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/persistence/gui/PersistenceDialog.java @@ -15,7 +15,7 @@ package org.eclipse.statet.ecommons.waltable.persistence.gui; import java.util.ArrayList; import java.util.List; -import java.util.Properties; +import java.util.Map; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; @@ -109,7 +109,7 @@ public class PersistenceDialog extends Dialog { /** * The Properties instance that should be used for saving and loading. */ - private Properties properties; + private Map<String, String> properties; /** * Viewer containing the state configurations. @@ -142,7 +142,7 @@ public class PersistenceDialog extends Dialog { * @param natTable The NatTable instance to apply the save/load operations. * @param properties The Properties instance that should be used for saving and loading. */ - public PersistenceDialog(final Shell parentShell, final NatTable natTable, final Properties properties) { + public PersistenceDialog(final Shell parentShell, final NatTable natTable, final Map<String, String> properties) { super(parentShell); setShellStyle(SWT.RESIZE | SWT.APPLICATION_MODAL| SWT.DIALOG_TRIM); @@ -336,14 +336,14 @@ public class PersistenceDialog extends Dialog { /** * @return The Properties instance that is used for saving and loading. */ - public Properties getProperties() { + public Map<String, String> getProperties() { return this.properties; } /** * @param properties The Properties instance that should be used for saving and loading. */ - public void setProperties(final Properties properties) { + public void setProperties(final Map<String, String> properties) { this.properties= properties; } @@ -351,7 +351,7 @@ public class PersistenceDialog extends Dialog { * @return The name of the current active view configuration */ public String getActiveViewConfigurationName() { - return this.properties.getProperty(ACTIVE_VIEW_CONFIGURATION_KEY); + return this.properties.get(ACTIVE_VIEW_CONFIGURATION_KEY); } /** @@ -362,7 +362,7 @@ public class PersistenceDialog extends Dialog { * @param name The name of the current active view configuration */ public void setActiveViewConfigurationName(final String name) { - this.properties.setProperty(ACTIVE_VIEW_CONFIGURATION_KEY, name); + this.properties.put(ACTIVE_VIEW_CONFIGURATION_KEY, name); } /** @@ -417,7 +417,7 @@ public class PersistenceDialog extends Dialog { private final Styler italicStyler; ViewConfigurationNameLabelProvider() { - this.italicFont= GUIHelper.getFont(new FontData[]{new FontData("Arial", 8, SWT.ITALIC)}); //$NON-NLS-1$ + this.italicFont= GUIHelper.getFont(new FontData("Arial", 8, SWT.ITALIC)); //$NON-NLS-1$ this.italicStyler= new Styler() { @Override public void applyStyles(final TextStyle textStyle) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEvent.java deleted file mode 100644 index c106c686..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.resize; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.ColumnStructuralChangeEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff.DiffTypeEnum; - - -public class ColumnResizeEvent extends ColumnStructuralChangeEvent { - - public ColumnResizeEvent(final ILayer layer, final long columnPosition) { - super(layer, new LRange(columnPosition)); - } - - protected ColumnResizeEvent(final ColumnResizeEvent event) { - super(event); - } - - @Override - public ColumnResizeEvent cloneEvent() { - return new ColumnResizeEvent(this); - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - final Collection<StructuralDiff> rowDiffs= new ArrayList<>(); - - for (final LRange lRange : getColumnPositionRanges()) { - rowDiffs.add(new StructuralDiff(DiffTypeEnum.CHANGE, lRange, lRange)); - } - - return rowDiffs; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/RowResizeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/RowResizeEvent.java deleted file mode 100644 index 2c18884a..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/RowResizeEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.resize; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.RowStructuralChangeEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff.DiffTypeEnum; - - -public class RowResizeEvent extends RowStructuralChangeEvent { - - public RowResizeEvent(final ILayer layer, final long rowPosition) { - super(layer, new LRange(rowPosition)); - } - - public RowResizeEvent(final ILayer layer, final LRange rowPositionRange) { - super(layer, rowPositionRange); - } - - protected RowResizeEvent(final RowResizeEvent event) { - super(event); - } - - @Override - public RowResizeEvent cloneEvent() { - return new RowResizeEvent(this); - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - final Collection<StructuralDiff> rowDiffs= new ArrayList<>(); - - for (final LRange lRange : getRowPositionRanges()) { - new StructuralDiff(DiffTypeEnum.CHANGE, lRange, lRange); - } - - return rowDiffs; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ColumnSelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ColumnSelectionEvent.java deleted file mode 100644 index da6ecd51..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ColumnSelectionEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.selection.SelectionLayer.NO_SELECTION; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.ColumnVisualChangeEvent; - - -public class ColumnSelectionEvent extends ColumnVisualChangeEvent implements ISelectionEvent { - - - private final SelectionLayer selectionLayer; - - private long columnPositionToReveal; - - - public ColumnSelectionEvent(final SelectionLayer selectionLayer, - final long columnPosition, final boolean revealColumn) { - this(selectionLayer, new LRangeList(columnPosition), - (revealColumn) ? columnPosition : NO_SELECTION ); - } - - public ColumnSelectionEvent(final SelectionLayer selectionLayer, - final Collection<LRange> columnPositions, final long columnPositionToReveal) { - super(selectionLayer, columnPositions); - this.selectionLayer= selectionLayer; - this.columnPositionToReveal= columnPositionToReveal; - } - - protected ColumnSelectionEvent(final ColumnSelectionEvent event) { - super(event); - this.selectionLayer= event.selectionLayer; - this.columnPositionToReveal= event.columnPositionToReveal; - } - - @Override - public ColumnSelectionEvent cloneEvent() { - return new ColumnSelectionEvent(this); - } - - - @Override - public SelectionLayer getSelectionLayer() { - return this.selectionLayer; - } - - public long getColumnPositionToReveal() { - return this.columnPositionToReveal; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - if (this.columnPositionToReveal != NO_SELECTION) { - this.columnPositionToReveal= localLayer.getDim(HORIZONTAL).underlyingToLocalPosition( - getLayer().getDim(HORIZONTAL), this.columnPositionToReveal ); - } - - return super.convertToLocal(localLayer); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/IRowSelectionModel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/IRowSelectionModel.java deleted file mode 100644 index 63f08754..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/IRowSelectionModel.java +++ /dev/null @@ -1,35 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection; - -import java.util.List; - - -public interface IRowSelectionModel<R> extends ISelectionModel { - - /** - * Expose the underlying row objects - * - * @return - */ - public List<R> getSelectedRowObjects(); - - /** - * Removes the selected row object from the selection - * - * @param rowObject - */ - public void clearSelection(R rowObject); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/RowSelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/RowSelectionEvent.java deleted file mode 100644 index 3edee0ce..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/RowSelectionEvent.java +++ /dev/null @@ -1,79 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; -import static org.eclipse.statet.ecommons.waltable.selection.SelectionLayer.NO_SELECTION; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.RowVisualChangeEvent; - - -public class RowSelectionEvent extends RowVisualChangeEvent implements ISelectionEvent { - - - private final SelectionLayer selectionLayer; - - private long rowPositionToReveal; - - - public RowSelectionEvent(final SelectionLayer selectionLayer, - final long rowPosition, final boolean revealRow) { - this(selectionLayer, new LRangeList(rowPosition), - (revealRow) ? rowPosition : NO_SELECTION ); - } - - public RowSelectionEvent(final SelectionLayer selectionLayer, - final Collection<LRange> rowPositions, final long rowPositionToReveal) { - super(selectionLayer, rowPositions); - this.selectionLayer= selectionLayer; - this.rowPositionToReveal= rowPositionToReveal; - } - - protected RowSelectionEvent(final RowSelectionEvent event) { - super(event); - this.selectionLayer= event.selectionLayer; - this.rowPositionToReveal= event.rowPositionToReveal; - } - - @Override - public RowSelectionEvent cloneEvent() { - return new RowSelectionEvent(this); - } - - - @Override - public SelectionLayer getSelectionLayer() { - return this.selectionLayer; - } - - public long getRowPositionToReveal() { - return this.rowPositionToReveal; - } - - @Override - public boolean convertToLocal(final ILayer localLayer) { - if (this.rowPositionToReveal != NO_SELECTION) { - this.rowPositionToReveal= localLayer.getDim(VERTICAL).underlyingToLocalPosition( - getLayer().getDim(VERTICAL), this.rowPositionToReveal ); - } - - return super.convertToLocal(localLayer); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionFlags.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionFlags.java deleted file mode 100644 index f3beadea..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionFlags.java +++ /dev/null @@ -1,39 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection; - -import org.eclipse.swt.SWT; - - -public class SelectionFlags { - - - /** Extend current selection */ - public static final int RANGE_SELECTION= SWT.SHIFT; - /** Retain or toggle */ - public static final int RETAIN_SELECTION= SWT.CTRL; - - - public static final int swt2Flags(final int swtMask) { - int flags= 0; - if ((swtMask & SWT.MOD2) != 0) { - flags |= RANGE_SELECTION; - } - if ((swtMask & SWT.MOD1) != 0) { - flags |= RETAIN_SELECTION; - } - return flags; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayerStructuralChangeEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayerStructuralChangeEventHandler.java deleted file mode 100644 index bcd40600..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayerStructuralChangeEventHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; -import org.eclipse.statet.ecommons.waltable.layer.event.IStructuralChangeEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff.DiffTypeEnum; - - -public class SelectionLayerStructuralChangeEventHandler implements ILayerEventHandler<IStructuralChangeEvent> { - - private final ISelectionModel selectionModel; - private final SelectionLayer selectionLayer; - - public SelectionLayerStructuralChangeEventHandler(final SelectionLayer selectionLayer, final ISelectionModel selectionModel) { - this.selectionLayer= selectionLayer; - this.selectionModel= selectionModel; - } - - @Override - public Class<IStructuralChangeEvent> getLayerEventClass() { - return IStructuralChangeEvent.class; - } - - @Override - public void handleLayerEvent(final IStructuralChangeEvent event) { - if (event.isHorizontalStructureChanged()) { - // TODO handle column deletion - this.selectionLayer.clear(); - return; - } - - if (event.isVerticalStructureChanged()) { - //if there are no row diffs, it seems to be a complete refresh - if (event.getRowDiffs() == null) { - final Collection<LRectangle> lRectangles= event.getChangedPositionRectangles(); - for (final LRectangle lRectangle : lRectangles) { - final LRange changedRange= new LRange(lRectangle.y, lRectangle.y + lRectangle.height); - if (selectedRowModified(changedRange)) { - if (this.selectionLayer.getRowCount() > 0) { - long columnPosition= this.selectionLayer.getSelectionAnchor().columnPosition; - if (columnPosition == SelectionLayer.NO_SELECTION) { - columnPosition= 0; - } - this.selectionLayer.setSelectionToCell(columnPosition, 0, false); - } - else { - this.selectionLayer.clear(); - } - return; - } - } - } - else { - //there are row diffs so we try to determine the diffs to process - for (final StructuralDiff diff : event.getRowDiffs()) { - //DiffTypeEnum.CHANGE is used for resizing and shouldn't result in clearing the selection - if (diff.getDiffType() != DiffTypeEnum.CHANGE) { - if (selectedRowModified(diff.getBeforePositionRange())) { - this.selectionLayer.clear(); - return; - } - } - } - } - } - } - - private boolean selectedRowModified(final LRange changedRange){ - final List<LRange> selectedRows= this.selectionModel.getSelectedRowPositions(); - for (final LRange rowRange : selectedRows) { - if (rowRange.overlap(changedRange)){ - return true; - } - } - return false; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java deleted file mode 100644 index 370ce283..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java +++ /dev/null @@ -1,126 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.selection.config; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; - -import org.eclipse.statet.ecommons.waltable.config.AbstractRegistryConfiguration; -import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle.LineStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; - - -/** - * Sets up rendering style used for selected areas and the selection anchor. - */ -public class DefaultSelectionStyleConfiguration extends AbstractRegistryConfiguration { - - // Selection style - public Font selectionFont= GUIHelper.getFont(new FontData("Verdana", 8, SWT.BOLD | SWT.ITALIC)); //$NON-NLS-1$ - public Color selectionBgColor= GUIHelper.COLOR_TITLE_INACTIVE_BACKGROUND; - public Color selectionFgColor= GUIHelper.COLOR_BLACK; - - // Anchor style - public Color anchorBorderColor= GUIHelper.COLOR_DARK_GRAY; - public BorderStyle anchorBorderStyle= new BorderStyle(1, this.anchorBorderColor, LineStyle.SOLID); - public Color anchorBgColor= GUIHelper.COLOR_GRAY; - public Color anchorFgColor= GUIHelper.COLOR_WHITE; - - // Selected headers style - public Color selectedHeaderBgColor= GUIHelper.COLOR_GRAY; - public Color selectedHeaderFgColor= GUIHelper.COLOR_WHITE; - public Font selectedHeaderFont= GUIHelper.getFont(new FontData("Verdana", 10, SWT.BOLD)); //$NON-NLS-1$ - public BorderStyle selectedHeaderBorderStyle= new BorderStyle(-1, this.selectedHeaderFgColor, LineStyle.SOLID); - - // Anchor grid line style - public Color anchorGridBorderColor= GUIHelper.COLOR_BLACK; - public BorderStyle anchorGridBorderStyle= new BorderStyle(1, this.anchorGridBorderColor, LineStyle.DOTTED); - - - @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configureSelectionStyle(configRegistry); - configureSelectionAnchorStyle(configRegistry); - configureSelectionAnchorGridLineStyle(configRegistry); - configureHeaderHasSelectionStyle(configRegistry); - configureHeaderFullySelectedStyle(configRegistry); - } - - protected void configureSelectionStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.FONT, this.selectionFont); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.selectionBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.selectionFgColor); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT ); - } - - protected void configureSelectionAnchorStyle(final IConfigRegistry configRegistry) { - // Selection anchor style for normal display mode - Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.anchorBorderStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.NORMAL, SelectionStyleLabels.SELECTION_ANCHOR_STYLE ); - - // Selection anchor style for select display mode - cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.anchorBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.anchorFgColor); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.anchorBorderStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, SelectionStyleLabels.SELECTION_ANCHOR_STYLE ); - } - - protected void configureSelectionAnchorGridLineStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.anchorGridBorderStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE ); - } - - protected void configureHeaderHasSelectionStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, this.selectedHeaderFgColor); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.selectedHeaderBgColor); - cellStyle.setAttributeValue(CellStyleAttributes.FONT, this.selectedHeaderFont); - cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.selectedHeaderBorderStyle); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, GridRegion.COLUMN_HEADER ); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, GridRegion.CORNER ); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, GridRegion.ROW_HEADER ); - } - - protected void configureHeaderFullySelectedStyle(final IConfigRegistry configRegistry) { - // Header fully selected - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_WIDGET_NORMAL_SHADOW); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, - DisplayMode.SELECT, SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ClearSortCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ClearSortCommandHandler.java deleted file mode 100644 index f947e7a4..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ClearSortCommandHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.sort; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; - -import java.util.List; - -import org.eclipse.swt.custom.BusyIndicator; - -import org.eclipse.statet.ecommons.waltable.command.ILayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; - - -public class ClearSortCommandHandler implements ILayerCommandHandler<ClearSortCommand> { - - - private final ISortModel sortModel; - - - public ClearSortCommandHandler(final ISortModel sortModel) { - this.sortModel= sortModel; - } - - - @Override - public Class<ClearSortCommand> getCommandClass() { - return ClearSortCommand.class; - } - - - @Override - public boolean doCommand(final ILayer targetLayer, final ClearSortCommand command) { - // with busy indicator - final Runnable sortRunner= new Runnable() { - @Override - public void run() { - final ILayerDim dim= targetLayer.getDim(HORIZONTAL); - - final List<Long> sortedIds= ClearSortCommandHandler.this.sortModel.getSortedColumnIds(); - final LRangeList sortedPositions= new LRangeList(); - for (final Long id : sortedIds) { - final long position= dim.getPositionById(id); - if (position != ILayerDim.POSITION_NA) { - sortedPositions.values().add(position); - } - } - - ClearSortCommandHandler.this.sortModel.clear(); - - // Fire event - final SortColumnEvent sortEvent= new SortColumnEvent(dim, - sortedPositions ); - dim.getLayer().fireLayerEvent(sortEvent); - } - }; - BusyIndicator.showWhile(null, sortRunner); - - return true; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortColumnEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortColumnEvent.java deleted file mode 100644 index 391bbb0a..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortColumnEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.sort; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.event.ColumnVisualChangeEvent; - - -public class SortColumnEvent extends ColumnVisualChangeEvent { - - - public SortColumnEvent(final ILayerDim layer, final long columnPosition) { - super(layer.getLayer(), new LRange(columnPosition)); - } - - public SortColumnEvent(final ILayerDim layer, final Collection<LRange> columnPositions) { - super(layer.getLayer(), columnPositions); - } - - protected SortColumnEvent(final SortColumnEvent event) { - super(event); - } - - @Override - public SortColumnEvent cloneEvent() { - return new SortColumnEvent(this); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortConfigAttributes.java deleted file mode 100644 index 74b798b0..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortConfigAttributes.java +++ /dev/null @@ -1,25 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.sort; - -import java.util.Comparator; - -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; - - -public interface SortConfigAttributes { - - public static final ConfigAttribute<Comparator<?>> SORT_COMPARATOR= new ConfigAttribute<>(); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortPositionCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortPositionCommandHandler.java deleted file mode 100644 index 708c0292..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortPositionCommandHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.sort; - -import org.eclipse.swt.custom.BusyIndicator; - -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; - - -/** - * Handle sort commands - */ -public class SortPositionCommandHandler extends AbstractLayerCommandHandler<SortDimPositionCommand> { - - - private final ISortModel sortModel; - - - public SortPositionCommandHandler(final ISortModel sortModel) { - this.sortModel= sortModel; - } - - - @Override - public Class<SortDimPositionCommand> getCommandClass() { - return SortDimPositionCommand.class; - } - - @Override - protected boolean doCommand(final SortDimPositionCommand command) { - final long columnId= command.getDim() - .getPositionId(command.getPosition(), command.getPosition()); - - // with busy indicator - final Runnable sortRunner= new Runnable() { - @Override - public void run() { - final ILayerDim dim= command.getDim(); - - final SortDirection newSortDirection= (command.getDirection() != null) ? - command.getDirection() : - SortPositionCommandHandler.this.sortModel.getSortDirection(columnId).getNextSortDirection(); - SortPositionCommandHandler.this.sortModel.sort(columnId, - newSortDirection, command.isAccumulate() ); - - // Fire event - final SortColumnEvent sortEvent= new SortColumnEvent(dim, - command.getPosition() ); - dim.getLayer().fireLayerEvent(sortEvent); - } - }; - BusyIndicator.showWhile(null, sortRunner); - - return true; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleAttributes.java deleted file mode 100644 index 0ac872e3..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleAttributes.java +++ /dev/null @@ -1,87 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.style; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; - - -public interface CellStyleAttributes { - - /** - * Attribute for configuring the background color of a cell. - */ - public static final ConfigAttribute<Color> BACKGROUND_COLOR= new ConfigAttribute<>(); - - /** - * Attribute for configuring the foreground color of a cell. - */ - public static final ConfigAttribute<Color> FOREGROUND_COLOR= new ConfigAttribute<>(); - - /** - * Attribute for configuring the gradient sweeping background color. - * Is used by the GradientBackgroundPainter. - */ - public static final ConfigAttribute<Color> GRADIENT_BACKGROUND_COLOR= new ConfigAttribute<>(); - - /** - * Attribute for configuring the gradient sweeping foreground color. - * Is used by the GradientBackgroundPainter. - */ - public static final ConfigAttribute<Color> GRADIENT_FOREGROUND_COLOR= new ConfigAttribute<>(); - - /** - * Attribute for configuring the horizontal alignment of a cell. - */ - public static final ConfigAttribute<HorizontalAlignment> HORIZONTAL_ALIGNMENT= new ConfigAttribute<>(); - - /** - * Attribute for configuring the vertical alignment of a cell. - */ - public static final ConfigAttribute<VerticalAlignment> VERTICAL_ALIGNMENT= new ConfigAttribute<>(); - - /** - * Attribute for configuring the font to be used on rendering text. - * Is used by all specialisations of the AbstractTextPainter. - */ - public static final ConfigAttribute<Font> FONT= new ConfigAttribute<>(); - - /** - * Attribute for configuring the image to rendered. - * Is used by the ImagePainter to determine the image to render dynamically. - */ - public static final ConfigAttribute<Image> IMAGE= new ConfigAttribute<>(); - - /** - * Attribute for configuring the border style. - * Is used by the LineBorderDecorator. - */ - public static final ConfigAttribute<BorderStyle> BORDER_STYLE= new ConfigAttribute<>(); - - /** - * Attribute for configuring the echo character that should be used by PasswordTextPainter and - * PasswordCellEditor. - */ - public static final ConfigAttribute<Character> PASSWORD_ECHO_CHAR= new ConfigAttribute<>(); - - /** - * Attribute for configuring the text decoration (underline and/or strikethrough). - * Is used by all specialisations of the AbstractTextPainter - */ - public static final ConfigAttribute<TextDecorationEnum> TEXT_DECORATION= new ConfigAttribute<>(); - - public static final ConfigAttribute<Font> CONTROL_FONT= new ConfigAttribute<>(); - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleProxy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleProxy.java deleted file mode 100644 index dfc2b785..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleProxy.java +++ /dev/null @@ -1,36 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.style; - -import java.util.List; - -import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; - - -public class CellStyleProxy extends StyleProxy { - - - public CellStyleProxy(final IConfigRegistry configRegistry, - final DisplayMode targetDisplayMode, final List<String> configLabels) { - super(CellConfigAttributes.CELL_STYLE, configRegistry, targetDisplayMode, configLabels); - } - - - @Override - public <T> void setAttributeValue(final ConfigAttribute<T> styleAttribute, final T value) { - throw new UnsupportedOperationException("Not implemented yet"); //$NON-NLS-1$ - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleUtil.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleUtil.java index 2cdc5d67..a16f6952 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleUtil.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/CellStyleUtil.java @@ -19,25 +19,31 @@ import java.util.List; import org.eclipse.swt.graphics.Color; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.RegistryStyle; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; public class CellStyleUtil { - public static IStyle getCellStyle(final ILayerCell cell, final IConfigRegistry configRegistry) { - return new CellStyleProxy(configRegistry, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); + public static Style getCellStyle(final LayerCell cell, final ConfigRegistry configRegistry) { + return new RegistryStyle(configRegistry, CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getLabels().getLabels()); } - public static int getHorizontalAlignmentSWT(final IStyle cellStyle, final int swtDefault) { - final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT); - return (horizontalAlignment != null) ? SWTUtil.toSWT(horizontalAlignment) : swtDefault; + public static int getHorizontalAlignmentSWT(final Style cellStyle, final int swtDefault) { + final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT); + return (horizontalAlignment != null) ? SwtUtils.toSWT(horizontalAlignment) : swtDefault; } - public static long getHorizontalAlignmentPadding(final IStyle cellStyle, final LRectangle lRectangle, final long contentWidth) { - final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT); + public static long getHorizontalAlignmentPadding(final Style cellStyle, final LRectangle lRectangle, final long contentWidth) { + final HorizontalAlignment horizontalAlignment= cellStyle.getAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT); return getHorizontalAlignmentPadding(horizontalAlignment, lRectangle.width, contentWidth); } @@ -70,8 +76,8 @@ public class CellStyleUtil { return padding; } - public static long getVerticalAlignmentPadding(final IStyle cellStyle, final LRectangle lRectangle, final long contentHeight) { - final VerticalAlignment verticalAlignment= cellStyle.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT); + public static long getVerticalAlignmentPadding(final Style cellStyle, final LRectangle lRectangle, final long contentHeight) { + final VerticalAlignment verticalAlignment= cellStyle.getAttributeValue(CellStyling.VERTICAL_ALIGNMENT); return getVerticalAlignmentPadding(verticalAlignment, lRectangle.height, contentHeight); } @@ -101,20 +107,20 @@ public class CellStyleUtil { return padding; } - public static List<Color> getAllBackgroundColors(final ILayerCell cell, final IConfigRegistry configRegistry, + public static List<Color> getAllBackgroundColors(final LayerCell cell, final ConfigRegistry configRegistry, final DisplayMode displayMode) { final List<Color> colors= new ArrayList<>(); - for (final String configLabel : cell.getConfigLabels().getLabels()) { - final IStyle cellStyle= configRegistry.getSpecificConfigAttribute(CellConfigAttributes.CELL_STYLE, displayMode, configLabel); + for (final String configLabel : cell.getLabels().getLabels()) { + final Style cellStyle= configRegistry.getSpecificAttribute(CellConfigAttributes.CELL_STYLE, displayMode, configLabel); if (cellStyle != null) { - final Color color= cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + final Color color= cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); if (color != null) { colors.add(color); } - } + } } return colors; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/DefaultDisplayModeOrdering.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/DefaultDisplayModeOrdering.java deleted file mode 100644 index 542f943a..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/DefaultDisplayModeOrdering.java +++ /dev/null @@ -1,53 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.style; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - - -public class DefaultDisplayModeOrdering implements IDisplayModeLookupStrategy { - - private static final List<DisplayMode> NORMAL_ORDERING= Arrays.asList(DisplayMode.NORMAL); - - private static final List<DisplayMode> HOVER_ORDERING= Arrays.asList(DisplayMode.HOVER, DisplayMode.NORMAL); - - private static final List<DisplayMode> SELECT_ORDERING= Arrays.asList(DisplayMode.SELECT, DisplayMode.NORMAL); - - private static final List<DisplayMode> EDIT_ORDERING= Arrays.asList(DisplayMode.EDIT, DisplayMode.NORMAL); - - private static final List<DisplayMode> EMPTY_ORDERING= Collections.emptyList(); - - - /** - * See DefaultDisplayModeOrderingTest - */ - @Override - public List<DisplayMode> getDisplayModeOrdering(final DisplayMode targetDisplayMode) { - switch (targetDisplayMode) { - case NORMAL: - return NORMAL_ORDERING; - case HOVER: - return HOVER_ORDERING; - case SELECT: - return SELECT_ORDERING; - case EDIT: - return EDIT_ORDERING; - default: - return EMPTY_ORDERING; - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/SelectionStyleLabels.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/SelectionStyleLabels.java index 179d9a37..55e6b761 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/SelectionStyleLabels.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/SelectionStyleLabels.java @@ -13,17 +13,17 @@ package org.eclipse.statet.ecommons.waltable.style; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; public interface SelectionStyleLabels { - public static final String SELECTION_ANCHOR_STYLE= "selectionAnchor"; //$NON-NLS-1$ + public static final String SELECTION_ANCHOR_STYLE= "SELECTION_ANCHOR"; //$NON-NLS-1$ public static final String SELECTION_ANCHOR_GRID_LINE_STYLE= "selectionAnchorGridLine"; //$NON-NLS-1$ - public static final String COLUMN_FULLY_SELECTED_STYLE= GridRegion.COLUMN_HEADER + "_FULL"; //$NON-NLS-1$ + public static final String COLUMN_FULLY_SELECTED_STYLE= GridLabels.COLUMN_HEADER + "_FULL"; //$NON-NLS-1$ - public static final String ROW_FULLY_SELECTED_STYLE= GridRegion.ROW_HEADER + "_FULL"; //$NON-NLS-1$ + public static final String ROW_FULLY_SELECTED_STYLE= GridLabels.ROW_HEADER + "_FULL"; //$NON-NLS-1$ } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/StyleProxy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/StyleProxy.java deleted file mode 100644 index 3983242d..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/StyleProxy.java +++ /dev/null @@ -1,69 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.style; - -import java.util.List; - -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; - - -public abstract class StyleProxy implements IStyle { - - - private final ConfigAttribute<IStyle> styleConfigAttribute; - private final IConfigRegistry configRegistry; - private final DisplayMode targetDisplayMode; - private final List<String> configLabels; - - - public StyleProxy(final ConfigAttribute<IStyle> styleConfigAttribute, - final IConfigRegistry configRegistry, - final DisplayMode targetDisplayMode, final List<String> configLabels) { - this.styleConfigAttribute= styleConfigAttribute; - this.configRegistry= configRegistry; - this.targetDisplayMode= targetDisplayMode; - this.configLabels= configLabels; - } - - - @Override - public <T> T getAttributeValue(final ConfigAttribute<T> styleAttribute) { - T styleAttributeValue= null; - final IDisplayModeLookupStrategy displayModeLookupStrategy= this.configRegistry.getDisplayModeOrdering(); - - for (final DisplayMode displayMode : displayModeLookupStrategy.getDisplayModeOrdering(this.targetDisplayMode)) { - for (final String configLabel : this.configLabels) { - final IStyle cellStyle= this.configRegistry.getSpecificConfigAttribute(this.styleConfigAttribute, displayMode, configLabel); - if (cellStyle != null) { - styleAttributeValue= cellStyle.getAttributeValue(styleAttribute); - if (styleAttributeValue != null) { - return styleAttributeValue; - } - } - } - - // default - final IStyle cellStyle= this.configRegistry.getSpecificConfigAttribute(this.styleConfigAttribute, displayMode, null); - if (cellStyle != null) { - styleAttributeValue= cellStyle.getAttributeValue(styleAttribute); - if (styleAttributeValue != null) { - return styleAttributeValue; - } - } - } - - return null; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderStyleEditorPanel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderStyleEditorPanel.java index a6d1e1f5..58c158f3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderStyleEditorPanel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderStyleEditorPanel.java @@ -25,8 +25,8 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle.LineStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle.LineStyle; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderThicknessPicker.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderThicknessPicker.java index 2a11077f..ca1d1ab3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderThicknessPicker.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/BorderThicknessPicker.java @@ -34,11 +34,11 @@ public class BorderThicknessPicker extends Composite { super(parent, NONE); setLayout(new RowLayout()); - this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); - this.combo.setItems(new String[] { - Messages.getString("BorderThicknessPicker.thin"), //$NON-NLS-1$ - Messages.getString("BorderThicknessPicker.thick"), //$NON-NLS-1$ - Messages.getString("BorderThicknessPicker.veryThick")}); //$NON-NLS-1$ + this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + this.combo.setItems( + Messages.getString("BorderThicknessPicker.thin"), //$NON-NLS-1$ + Messages.getString("BorderThicknessPicker.thick"), //$NON-NLS-1$ + Messages.getString("BorderThicknessPicker.veryThick") ); //$NON-NLS-1$ this.combo.select(0); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/CellStyleEditorPanel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/CellStyleEditorPanel.java index a3e6d54b..ede28694 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/CellStyleEditorPanel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/CellStyleEditorPanel.java @@ -22,10 +22,11 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.Style; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -80,27 +81,27 @@ public class CellStyleEditorPanel extends AbstractEditorPanel<Style> { @Override public void edit(final Style style) throws Exception { - this.origBgColor= style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + this.origBgColor= style.getAttributeValue(CellStyling.BACKGROUND_COLOR); if (this.origBgColor == null) { this.origBgColor= GUIHelper.COLOR_WHITE; } this.backgroundColorPicker.setSelectedColor(this.origBgColor); - this.origFgColor= style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR); + this.origFgColor= style.getAttributeValue(CellStyling.FOREGROUND_COLOR); if (this.origFgColor == null) { this.origFgColor= GUIHelper.COLOR_BLACK; } this.foregroundColorPicker.setSelectedColor(this.origFgColor); - this.fontPicker.setOriginalFont(style.getAttributeValue(CellStyleAttributes.FONT)); + this.fontPicker.setOriginalFont(style.getAttributeValue(CellStyling.FONT)); - this.origHAlign= style.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT); + this.origHAlign= style.getAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT); if (this.origHAlign == null) { this.origHAlign= HorizontalAlignment.CENTER; } this.horizontalAlignmentPicker.setSelectedAlignment(this.origHAlign); - this.origVAlign= style.getAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT); + this.origVAlign= style.getAttributeValue(CellStyling.VERTICAL_ALIGNMENT); if (this.origVAlign == null) { this.origVAlign= VerticalAlignment.MIDDLE; } @@ -108,23 +109,23 @@ public class CellStyleEditorPanel extends AbstractEditorPanel<Style> { } @Override - public Style getNewValue() { - final Style newStyle= new Style(); + public BasicStyle getNewValue() { + final BasicStyle newStyle= new BasicStyle(); final Color bgColor= this.backgroundColorPicker.getSelectedColor(); - newStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, bgColor); + newStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, bgColor); final Color fgColor= this.foregroundColorPicker.getSelectedColor(); - newStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, fgColor); + newStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, fgColor); final Font font= this.fontPicker.getSelectedFont(); - newStyle.setAttributeValue(CellStyleAttributes.FONT, font); + newStyle.setAttributeValue(CellStyling.FONT, font); final HorizontalAlignment hAlign= this.horizontalAlignmentPicker.getSelectedAlignment(); - newStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, hAlign); + newStyle.setAttributeValue(CellStyling.HORIZONTAL_ALIGNMENT, hAlign); final VerticalAlignment vAlign= this.verticalAlignmentPicker.getSelectedAlignment(); - newStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, vAlign); + newStyle.setAttributeValue(CellStyling.VERTICAL_ALIGNMENT, vAlign); return newStyle; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColorPicker.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColorPicker.java index b5393f0c..17a5dca4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColorPicker.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColorPicker.java @@ -27,8 +27,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; - /** * A button that displays a solid block of color and allows the user to pick a color. The user can double click on the @@ -73,7 +71,7 @@ public class ColorPicker extends CLabel { } private void update(final RGB selected) { - this.selectedColor= GUIHelper.getColor(selected); + this.selectedColor= new Color(selected); setImage(getColorImage(this.selectedColor)); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColumnStyleEditorDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColumnStyleEditorDialog.java index 5f043f53..66e1ef93 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColumnStyleEditorDialog.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/ColumnStyleEditorDialog.java @@ -24,9 +24,9 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -37,18 +37,18 @@ public class ColumnStyleEditorDialog extends AbstractStyleEditorDialog { private BorderStyleEditorPanel borderStyleEditorPanel; // These are populated on OK button press - protected Style newColumnCellStyle; + protected BasicStyle newColumnCellStyle; protected BorderStyle newBorderStyle; - private final Style columnStyle; + private final BasicStyle columnStyle; - public ColumnStyleEditorDialog(final Shell parent, final Style columnCellStyle) { + public ColumnStyleEditorDialog(final Shell parent, final BasicStyle columnCellStyle) { super(parent); this.columnStyle= columnCellStyle; this.newColumnCellStyle= columnCellStyle; if (columnCellStyle != null) { - this.newBorderStyle= this.columnStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE); + this.newBorderStyle= this.columnStyle.getAttributeValue(CellStyling.BORDER_STYLE); } } @@ -86,7 +86,7 @@ public class ColumnStyleEditorDialog extends AbstractStyleEditorDialog { try { this.cellStyleEditorPanel.edit(this.columnStyle); - this.borderStyleEditorPanel.edit(this.columnStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE)); + this.borderStyleEditorPanel.edit(this.columnStyle.getAttributeValue(CellStyling.BORDER_STYLE)); } catch (final Exception e) { e.printStackTrace(System.err); } @@ -139,7 +139,7 @@ public class ColumnStyleEditorDialog extends AbstractStyleEditorDialog { // Getters for the modified style - public Style getNewColumnCellStyle() { + public BasicStyle getNewColumnCellStyle() { return this.newColumnCellStyle; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommand.java index a321f3e4..7459843d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommand.java @@ -13,30 +13,30 @@ package org.eclipse.statet.ecommons.waltable.style.editor; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public class DisplayColumnStyleEditorCommand extends AbstractContextFreeCommand { public final long columnPosition; public final long rowPosition; - private final ILayer layer; - private final IConfigRegistry configRegistry; + private final Layer layer; + private final ConfigRegistry configRegistry; - public DisplayColumnStyleEditorCommand(final ILayer natLayer, final IConfigRegistry configRegistry, final long columnPosition, final long rowPosition) { + public DisplayColumnStyleEditorCommand(final Layer natLayer, final ConfigRegistry configRegistry, final long columnPosition, final long rowPosition) { this.layer= natLayer; this.configRegistry= configRegistry; this.columnPosition= columnPosition; this.rowPosition= rowPosition; } - public ILayer getNattableLayer() { + public Layer getNattableLayer() { return this.layer; } - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommandHandler.java index c804adb8..67b67d2b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/DisplayColumnStyleEditorCommandHandler.java @@ -14,27 +14,26 @@ package org.eclipse.statet.ecommons.waltable.style.editor; import static org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes.CELL_STYLE; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.style.DisplayMode.NORMAL; +import static org.eclipse.statet.ecommons.waltable.core.config.DisplayMode.NORMAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.util.HashMap; import java.util.Map; -import java.util.Properties; -import java.util.Set; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.ILValueIterator; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.jcommons.collections.LongIterator; + +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; import org.eclipse.statet.ecommons.waltable.layer.cell.ColumnOverrideLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; import org.eclipse.statet.ecommons.waltable.persistence.StylePersistor; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.Style; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** @@ -44,18 +43,18 @@ import org.eclipse.statet.ecommons.waltable.style.Style; * 3. Applies the label from step 2 to all cells in the selected column * */ -public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommandHandler<DisplayColumnStyleEditorCommand> implements IPersistable { +public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommandHandler<DisplayColumnStyleEditorCommand> implements Persistable { protected static final String PERSISTENCE_PREFIX= "userDefinedColumnStyle"; //$NON-NLS-1$ protected static final String USER_EDITED_STYLE_LABEL= "USER_EDITED_STYLE_FOR_INDEX_"; //$NON-NLS-1$ protected final SelectionLayer selectionLayer; protected ColumnOverrideLabelAccumulator columnLabelAccumulator; - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; protected ColumnStyleEditorDialog dialog; - protected final Map<String, Style> stylesToPersist= new HashMap<>(); + protected final Map<String, BasicStyle> stylesToPersist= new HashMap<>(); - public DisplayColumnStyleEditorCommandHandler(final SelectionLayer selectionLayer, final ColumnOverrideLabelAccumulator labelAccumulator, final IConfigRegistry configRegistry) { + public DisplayColumnStyleEditorCommandHandler(final SelectionLayer selectionLayer, final ColumnOverrideLabelAccumulator labelAccumulator, final ConfigRegistry configRegistry) { this.selectionLayer= selectionLayer; this.columnLabelAccumulator= labelAccumulator; this.configRegistry= configRegistry; @@ -67,11 +66,11 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand .getPositionId(command.columnPosition, command.columnPosition); final LabelStack configLabels= new LabelStack(); - this.columnLabelAccumulator.accumulateConfigLabels(configLabels, columnIndexOfClick, 0); + this.columnLabelAccumulator.addLabels(configLabels, columnIndexOfClick, 0); configLabels.addLabel(getConfigLabel(columnIndexOfClick)); // Column style - final Style clickedCellStyle= (Style) this.configRegistry.getConfigAttribute(CELL_STYLE, NORMAL, configLabels.getLabels()); + final BasicStyle clickedCellStyle= (BasicStyle) this.configRegistry.getAttribute(CELL_STYLE, NORMAL, configLabels.getLabels()); this.dialog= new ColumnStyleEditorDialog(Display.getCurrent().getActiveShell(), clickedCellStyle); this.dialog.open(); @@ -91,20 +90,20 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand protected void applySelectedStyleToColumns(final DisplayColumnStyleEditorCommand command, final LRangeList columnPositions) { - for (final ILValueIterator columnIter= columnPositions.values().iterator(); columnIter.hasNext(); ) { + for (final LongIterator columnIter= columnPositions.values().iterator(); columnIter.hasNext(); ) { final long position= columnIter.nextValue(); final long columnIndex= this.selectionLayer.getDim(HORIZONTAL).getPositionId(position, position); // Read the edited styles - final Style newColumnCellStyle= this.dialog.getNewColumnCellStyle(); + final BasicStyle newColumnCellStyle= this.dialog.getNewColumnCellStyle(); final String configLabel= getConfigLabel(columnIndex); if (newColumnCellStyle == null) { this.stylesToPersist.remove(configLabel); } else { - newColumnCellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, this.dialog.getNewColumnBorderStyle()); + newColumnCellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.dialog.getNewColumnBorderStyle()); this.stylesToPersist.put(configLabel, newColumnCellStyle); } - this.configRegistry.registerConfigAttribute(CELL_STYLE, newColumnCellStyle, NORMAL, configLabel); + this.configRegistry.registerAttribute(CELL_STYLE, newColumnCellStyle, NORMAL, configLabel); this.columnLabelAccumulator.registerColumnOverridesOnTop(columnIndex, configLabel); } } @@ -114,22 +113,17 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand } @Override - public void loadState(String prefix, final Properties properties) { + public void loadState(String prefix, final Map<String, String> properties) { prefix= prefix + DOT + PERSISTENCE_PREFIX; - final Set<Object> keySet= properties.keySet(); - - for (final Object key : keySet) { - final String keyString= (String) key; - - // Relevant Key - if (keyString.contains(PERSISTENCE_PREFIX)) { - final long colIndex= parseColumnIndexFromKey(keyString); - + for (final var entry : properties.entrySet()) { + final String key= entry.getKey(); + if (key.contains(PERSISTENCE_PREFIX)) { + final long colIndex= parseColumnIndexFromKey(key); // Has the config label been processed if (!this.stylesToPersist.keySet().contains(getConfigLabel(colIndex))) { - final Style savedStyle= StylePersistor.loadStyle(prefix + DOT + getConfigLabel(colIndex), properties); - - this.configRegistry.registerConfigAttribute(CELL_STYLE, savedStyle, NORMAL, getConfigLabel(colIndex)); + final BasicStyle savedStyle= StylePersistor.loadStyle(prefix + DOT + getConfigLabel(colIndex), properties); + + this.configRegistry.registerAttribute(CELL_STYLE, savedStyle, NORMAL, getConfigLabel(colIndex)); this.stylesToPersist.put(getConfigLabel(colIndex), savedStyle); this.columnLabelAccumulator.registerColumnOverrides(colIndex, getConfigLabel(colIndex)); } @@ -146,11 +140,11 @@ public class DisplayColumnStyleEditorCommandHandler extends AbstractLayerCommand } @Override - public void saveState(String prefix, final Properties properties) { + public void saveState(String prefix, final Map<String, String> properties) { prefix= prefix + DOT + PERSISTENCE_PREFIX; - for (final Map.Entry<String, Style> labelToStyle : this.stylesToPersist.entrySet()) { - final Style style= labelToStyle.getValue(); + for (final Map.Entry<String, BasicStyle> labelToStyle : this.stylesToPersist.entrySet()) { + final BasicStyle style= labelToStyle.getValue(); final String label= labelToStyle.getKey(); StylePersistor.saveStyle(prefix + DOT + label, properties, style); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridColorsEditorPanel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridColorsEditorPanel.java index 96bbb8d1..7f8098d7 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridColorsEditorPanel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridColorsEditorPanel.java @@ -20,7 +20,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; public class GridColorsEditorPanel extends AbstractEditorPanel<GridStyleParameterObject> { @@ -28,7 +28,7 @@ public class GridColorsEditorPanel extends AbstractEditorPanel<GridStyleParamete private ColorPicker evenRowColorPicker; private ColorPicker oddRowColorPicker; private ColorPicker selectionColorPicker; - private IConfigRegistry configRegistry; + private ConfigRegistry configRegistry; public GridColorsEditorPanel(final Composite parent, final GridStyleParameterObject currentStyle) { super(parent, SWT.NONE); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridStyleParameterObject.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridStyleParameterObject.java index a1c82e8b..b55dc835 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridStyleParameterObject.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/GridStyleParameterObject.java @@ -17,11 +17,11 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.grid.cell.AlternatingRowConfigLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.grid.AlternatingRowLabelContributor; public class GridStyleParameterObject { @@ -31,39 +31,39 @@ public class GridStyleParameterObject { public Color oddRowColor; public Color selectionColor; - public IStyle evenRowStyle; - public IStyle oddRowStyle; - public IStyle selectionStyle; - public IStyle tableStyle; + public Style evenRowStyle; + public Style oddRowStyle; + public Style selectionStyle; + public Style tableStyle; - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; - public GridStyleParameterObject(final IConfigRegistry configRegistry) { + public GridStyleParameterObject(final ConfigRegistry configRegistry) { this.configRegistry= configRegistry; init(configRegistry); } - private void init(final IConfigRegistry configRegistry) { - this.evenRowStyle= configRegistry.getConfigAttribute( + private void init(final ConfigRegistry configRegistry) { + this.evenRowStyle= configRegistry.getAttribute( CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, - AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE); - this.evenRowColor= this.evenRowStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + AlternatingRowLabelContributor.EVEN_ROW_CONFIG_TYPE); + this.evenRowColor= this.evenRowStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); - this.oddRowStyle= configRegistry.getConfigAttribute( + this.oddRowStyle= configRegistry.getAttribute( CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, - AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE); - this.oddRowColor= this.oddRowStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + AlternatingRowLabelContributor.ODD_ROW_CONFIG_TYPE); + this.oddRowColor= this.oddRowStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); - this.selectionStyle= configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.SELECT); - this.selectionColor= this.selectionStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); + this.selectionStyle= configRegistry.getAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.SELECTED); + this.selectionColor= this.selectionStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); - this.tableStyle= configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL); - this.tableFont= this.tableStyle.getAttributeValue(CellStyleAttributes.FONT); + this.tableStyle= configRegistry.getAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL); + this.tableFont= this.tableStyle.getAttributeValue(CellStyling.FONT); } - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/HorizontalAlignmentPicker.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/HorizontalAlignmentPicker.java index ce1bd776..9f877d23 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/HorizontalAlignmentPicker.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/HorizontalAlignmentPicker.java @@ -19,7 +19,7 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; /** @@ -33,9 +33,12 @@ public class HorizontalAlignmentPicker extends Composite { super(parent, SWT.NONE); setLayout(new RowLayout()); - this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); - this.combo.setItems(new String[] { Messages.getString("HorizontalAlignmentPicker.center"), Messages.getString("HorizontalAlignmentPicker.left"), Messages.getString("HorizontalAlignmentPicker.right") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + this.combo.setItems( + Messages.getString("HorizontalAlignmentPicker.center"), //$NON-NLS-1$ + Messages.getString("HorizontalAlignmentPicker.left"), //$NON-NLS-1$ + Messages.getString("HorizontalAlignmentPicker.right") ); //$NON-NLS-1$ + update(alignment); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/LineStylePicker.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/LineStylePicker.java index 67eb0168..ef63788d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/LineStylePicker.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/LineStylePicker.java @@ -21,7 +21,7 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle.LineStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle.LineStyle; /** @@ -35,8 +35,13 @@ public class LineStylePicker extends Composite { super(parent, NONE); setLayout(new RowLayout()); - this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); - this.combo.setItems(new String[] { Messages.getString("LineStylePicker.solid"), Messages.getString("LineStylePicker.dashed"), Messages.getString("LineStylePicker.dotted"), Messages.getString("LineStylePicker.dashdot"), Messages.getString("LineStylePicker.dashdotdot") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + this.combo.setItems( + Messages.getString("LineStylePicker.solid"), //$NON-NLS-1$ + Messages.getString("LineStylePicker.dashed"), //$NON-NLS-1$ + Messages.getString("LineStylePicker.dotted"), //$NON-NLS-1$ + Messages.getString("LineStylePicker.dashdot"), //$NON-NLS-1$ + Messages.getString("LineStylePicker.dashdotdot") ); //$NON-NLS-1$ this.combo.select(0); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/VerticalAlignmentPicker.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/VerticalAlignmentPicker.java index ff52d0d2..88e74c0e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/VerticalAlignmentPicker.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/editor/VerticalAlignmentPicker.java @@ -19,7 +19,7 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; /** @@ -33,8 +33,11 @@ public class VerticalAlignmentPicker extends Composite { super(parent, SWT.NONE); setLayout(new RowLayout()); - this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); - this.combo.setItems(new String[] { Messages.getString("VerticalAlignmentPicker.top"), Messages.getString("VerticalAlignmentPicker.middle"), Messages.getString("VerticalAlignmentPicker.bottom") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + this.combo= new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN); + this.combo.setItems( + Messages.getString("VerticalAlignmentPicker.top"), //$NON-NLS-1$ + Messages.getString("VerticalAlignmentPicker.middle"), //$NON-NLS-1$ + Messages.getString("VerticalAlignmentPicker.bottom") ); //$NON-NLS-1$ update(alignment); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/swt/SWTUtil.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/swt/SWTUtil.java deleted file mode 100644 index 1d3e4373..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/swt/SWTUtil.java +++ /dev/null @@ -1,160 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2013, 2021 Stephan Wahlbrink and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 - # which is available at https://www.apache.org/licenses/LICENSE-2.0. - # - # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 - # - # Contributors: - # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.swt; - -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Scrollable; - -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle.LineStyle; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; - - -public class SWTUtil { - - - public static final int getMouseWheelEventType(/*@NonNull*/ final Orientation orientation) { - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - return (orientation == HORIZONTAL) ? - SWT.MouseHorizontalWheel : - SWT.MouseVerticalWheel; - } - - public static final ScrollBar getScrollBar(/*@NonNull*/ final Scrollable control, - /*@NonNull*/ final Orientation orientation) { - if (control == null) { - throw new NullPointerException("control"); //$NON-NLS-1$ - } - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - return (orientation == HORIZONTAL) ? - control.getHorizontalBar() : - control.getVerticalBar(); - } - - public static final LRange getRange(/*@NonNull*/ final LRectangle lRectangle, - /*@NonNull*/ final Orientation orientation) { - if (lRectangle == null) { - throw new NullPointerException("rectangle"); //$NON-NLS-1$ - } - if (orientation == null) { - throw new NullPointerException("orientation"); //$NON-NLS-1$ - } - return (orientation == HORIZONTAL) ? - new LRange(lRectangle.x, lRectangle.x + lRectangle.width) : - new LRange(lRectangle.y, lRectangle.y + lRectangle.height); - } - - - public static final int get(final org.eclipse.swt.graphics.Point point, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - point.x : - point.y; - } - - public static final int getStart(final org.eclipse.swt.graphics.Rectangle rect, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - rect.x : - rect.y; - } - - public static final int getEnd(final org.eclipse.swt.graphics.Rectangle rect, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - rect.x + rect.width : - rect.y + rect.height; - } - - public static final int getSize(final org.eclipse.swt.graphics.Rectangle rect, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - rect.width : - rect.height; - } - - public static final int get(final org.eclipse.swt.events.MouseEvent point, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - point.x : - point.y; - } - - - public static final Rectangle toSWT(final LRectangle rect) { - if (rect.x > Integer.MAX_VALUE || rect.y > Integer.MAX_VALUE - || rect.width > Integer.MAX_VALUE || rect.height > Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); - } - - public static final LRectangle toNatTable(final Rectangle rect) { - return new LRectangle(rect.x, rect.y, rect.width, rect.height); - } - - public static final Point toSWT(final LPoint lPoint) { - if (lPoint.x > Integer.MAX_VALUE || lPoint.y > Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - return new org.eclipse.swt.graphics.Point((int) lPoint.x, (int) lPoint.y); - } - - - public static final int getPixel(final MouseEvent event, final Orientation orientation) { - return (orientation == HORIZONTAL) ? - event.x : - event.y; - } - - public static final int toSWT(final HorizontalAlignment alignment) { - switch (alignment) { - case LEFT: - return SWT.LEFT; - case CENTER: - return SWT.CENTER; - case RIGHT: - return SWT.RIGHT; - default: - throw new IllegalStateException(); - } - } - - public static final int toSWT(final LineStyle lineStyle) { - switch (lineStyle) { - case SOLID: - return SWT.LINE_SOLID; - case DASHED: - return SWT.LINE_DASH; - case DOTTED: - return SWT.LINE_DOT; - case DASHDOT: - return SWT.LINE_DASHDOT; - case DASHDOTDOT: - return SWT.LINE_DASHDOTDOT; - default: - throw new IllegalStateException(); - } - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tooltip/TableContentTooltip.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tooltip/TableContentTooltip.java index 00e7db75..c049a720 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tooltip/TableContentTooltip.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tooltip/TableContentTooltip.java @@ -19,14 +19,14 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.layer.cell.CellDisplayConversionUtils; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.PasswordTextPainter; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; /** @@ -92,15 +92,15 @@ public class TableContentTooltip extends DefaultToolTip { final long col= this.natTable.getColumnPositionByX(event.x); final long row= this.natTable.getRowPositionByY(event.y); - final ILayerCell cell= this.natTable.getCellByPosition(col, row); + final LayerCell cell= this.natTable.getCellByPosition(col, row); if (cell != null) { //if the registered cell painter is the PasswordCellPainter, there will be no tooltip - final ICellPainter painter= this.natTable.getConfigRegistry().getConfigAttribute( - CellConfigAttributes.CELL_PAINTER, DisplayMode.NORMAL, cell.getConfigLabels().getLabels()); + final LayerCellPainter painter= this.natTable.getStyleRegistry().getAttribute( + CellConfigAttributes.CELL_PAINTER, DisplayMode.NORMAL, cell.getLabels().getLabels()); if (isVisibleContentPainter(painter)) { final String tooltipValue= CellDisplayConversionUtils.convertDataType( cell, - this.natTable.getConfigRegistry()); + this.natTable.getStyleRegistry()); if (tooltipValue.length() > 0) { return tooltipValue; @@ -111,12 +111,12 @@ public class TableContentTooltip extends DefaultToolTip { } /** - * Checks if the given {@link ICellPainter} is showing the content directly or if it is + * Checks if the given {@link LayerCellPainter} is showing the content directly or if it is * anonymized by using the {@link PasswordTextPainter} - * @param painter The {@link ICellPainter} to check. + * @param painter The {@link LayerCellPainter} to check. * @return <code>true</code> if the painter is not a {@link PasswordTextPainter} */ - protected boolean isVisibleContentPainter(final ICellPainter painter) { + protected boolean isVisibleContentPainter(final LayerCellPainter painter) { if (painter instanceof PasswordTextPainter) { return false; } else if (painter instanceof CellPainterWrapper) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/NatEventData.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/NatEventData.java index 226b854b..5eed5f39 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/NatEventData.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/NatEventData.java @@ -16,7 +16,7 @@ package org.eclipse.statet.ecommons.waltable.ui; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; public class NatEventData { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/AbstractNavigationAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/AbstractNavigationAction.java index 87ceb5ea..59fb0921 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/AbstractNavigationAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/AbstractNavigationAction.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.ui.action; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; public abstract class AbstractNavigationAction implements IKeyAction { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/CellDragMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/CellDragMode.java index b797c0a0..2c69c67b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/CellDragMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/action/CellDragMode.java @@ -20,12 +20,12 @@ import org.eclipse.swt.graphics.ImageData; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.IOverlayPainter; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.top.OverlayPainter; public class CellDragMode implements IDragMode { @@ -76,7 +76,7 @@ public class CellDragMode implements IDragMode { private void setCellImage(final NatTable natTable) { final long columnPosition= natTable.getColumnPositionByX(this.currentEvent.x); final long rowPosition= natTable.getRowPositionByY(this.currentEvent.y); - final ILayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); + final LayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); final LRectangle cellBounds= cell.getBounds(); final int width= (int) Math.min(cellBounds.width, 0x1fff); @@ -86,11 +86,11 @@ public class CellDragMode implements IDragMode { final Image image= new Image(natTable.getDisplay(), width, height); final GC gc= new GC(image); - final IConfigRegistry configRegistry= natTable.getConfigRegistry(); - final ICellPainter cellPainter= configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, - cell.getDisplayMode(), cell.getConfigLabels().getLabels() ); - if (cellPainter != null) { - cellPainter.paintCell(cell, gc, new LRectangle(0, 0, width, height), configRegistry); + final ConfigRegistry configRegistry= natTable.getStyleRegistry(); + final LayerCellPainter layerCellPainter= configRegistry.getAttribute(CellConfigAttributes.CELL_PAINTER, + cell.getDisplayMode(), cell.getLabels().getLabels() ); + if (layerCellPainter != null) { + layerCellPainter.paintCell(cell, gc, new LRectangle(0, 0, width, height), configRegistry); } gc.dispose(); @@ -101,10 +101,10 @@ public class CellDragMode implements IDragMode { this.cellImage= new Image(natTable.getDisplay(), imageData); } - private class CellImageOverlayPainter implements IOverlayPainter { + private class CellImageOverlayPainter implements OverlayPainter { @Override - public void paintOverlay(final GC gc, final ILayer layer) { + public void paintOverlay(final GC gc, final Layer layer) { if (CellDragMode.this.cellImage != null & !CellDragMode.this.cellImage.isDisposed()) { gc.drawImage(CellDragMode.this.cellImage, CellDragMode.this.currentEvent.x - CellDragMode.this.xOffset, CellDragMode.this.currentEvent.y - CellDragMode.this.yOffset); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/binding/UiBindingRegistry.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/binding/UiBindingRegistry.java index 41b789dc..60ddb589 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/binding/UiBindingRegistry.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/binding/UiBindingRegistry.java @@ -21,7 +21,7 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; import org.eclipse.statet.ecommons.waltable.ui.action.IDragMode; import org.eclipse.statet.ecommons.waltable.ui.action.IKeyAction; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellEditorMouseEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellEditorMouseEventMatcher.java index f226e1c9..4517876b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellEditorMouseEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellEditorMouseEventMatcher.java @@ -16,11 +16,11 @@ package org.eclipse.statet.ecommons.waltable.ui.matcher; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.editor.ICellEditor; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; /** @@ -96,15 +96,15 @@ public class CellEditorMouseEventMatcher implements IMouseEventMatcher { if ((this.regionLabel == null || (regionLabels != null && regionLabels.hasLabel(this.regionLabel))) && event.button == this.button) { - final ILayerCell cell= natTable.getCellByPosition( + final LayerCell cell= natTable.getCellByPosition( natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y)); //Bug 407598: only perform a check if the click in the body region was performed on a cell //cell == null can happen if the viewport is quite large and contains not enough cells to fill it. if (cell != null) { - final ICellEditor cellEditor= natTable.getConfigRegistry().getConfigAttribute( - EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cell.getConfigLabels().getLabels()); + final ICellEditor cellEditor= natTable.getStyleRegistry().getAttribute( + EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, cell.getLabels().getLabels()); if (cellEditor != null && cellEditor.activateAtAnyPosition()) { //if there is a cell editor configured for the cell that was clicked on, the match is found diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellLabelMouseEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellLabelMouseEventMatcher.java index d327a706..5d3ebcbc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellLabelMouseEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellLabelMouseEventMatcher.java @@ -16,8 +16,8 @@ package org.eclipse.statet.ecommons.waltable.ui.matcher; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.ui.NatEventData; @@ -44,10 +44,10 @@ public class CellLabelMouseEventMatcher extends MouseEventMatcher { @Override public boolean matches(final NatTable natTable, final MouseEvent event, final LabelStack regionLabels) { final NatEventData eventData= NatEventData.createInstanceFromEvent(event); - final ILayerCell cell= natTable.getCellByPosition(eventData.getColumnPosition(), eventData.getRowPosition()); + final LayerCell cell= natTable.getCellByPosition(eventData.getColumnPosition(), eventData.getRowPosition()); return (cell != null && super.matches(natTable, event, regionLabels) - && cell.getConfigLabels().getLabels().contains(this.labelToMatch) ); + && cell.getLabels().getLabels().contains(this.labelToMatch) ); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellPainterMouseEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellPainterMouseEventMatcher.java index 91e2cbb9..94508bf6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellPainterMouseEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/CellPainterMouseEventMatcher.java @@ -18,11 +18,11 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; /** @@ -31,16 +31,16 @@ import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; public class CellPainterMouseEventMatcher extends MouseEventMatcher { - private ICellPainter targetCellPainter; - private Class<? extends ICellPainter> targetCellPainterClass; + private LayerCellPainter targetCellPainter; + private Class<? extends LayerCellPainter> targetCellPainterClass; - public CellPainterMouseEventMatcher(final String regionName, final int button, final ICellPainter targetCellPainter) { + public CellPainterMouseEventMatcher(final String regionName, final int button, final LayerCellPainter targetCellPainter) { super(regionName, button); this.targetCellPainter= targetCellPainter; } - public CellPainterMouseEventMatcher(final String regionName, final int button, final Class<? extends ICellPainter> targetCellPainterClass) { + public CellPainterMouseEventMatcher(final String regionName, final int button, final Class<? extends LayerCellPainter> targetCellPainterClass) { super(regionName, button); this.targetCellPainterClass= targetCellPainterClass; } @@ -52,20 +52,20 @@ public class CellPainterMouseEventMatcher extends MouseEventMatcher { final long columnPosition= natTable.getColumnPositionByX(event.x); final long rowPosition= natTable.getRowPositionByY(event.y); - final ILayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); + final LayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); //Bug 407598: only perform a check if the click in the body region was performed on a cell //cell == null can happen if the viewport is quite large and contains not enough cells to fill it. if (cell != null) { - final IConfigRegistry configRegistry= natTable.getConfigRegistry(); - final ICellPainter cellPainter= configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, - cell.getDisplayMode(), cell.getConfigLabels().getLabels() ); + final ConfigRegistry configRegistry= natTable.getStyleRegistry(); + final LayerCellPainter layerCellPainter= configRegistry.getAttribute(CellConfigAttributes.CELL_PAINTER, + cell.getDisplayMode(), cell.getLabels().getLabels() ); final GC gc= new GC(natTable.getDisplay()); try { final LRectangle adjustedCellBounds= natTable.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, cell.getBounds()); - final ICellPainter clickedCellPainter= cellPainter.getCellPainterAt(event.x, event.y, cell, gc, adjustedCellBounds, configRegistry); + final LayerCellPainter clickedCellPainter= layerCellPainter.getCellPainterAt(event.x, event.y, cell, gc, adjustedCellBounds, configRegistry); if (clickedCellPainter != null) { if ( (this.targetCellPainter != null && this.targetCellPainter == clickedCellPainter) || (this.targetCellPainterClass != null && this.targetCellPainterClass.isInstance(clickedCellPainter))) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/IMouseEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/IMouseEventMatcher.java index 2698c4cf..c1127c7f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/IMouseEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/IMouseEventMatcher.java @@ -16,7 +16,7 @@ package org.eclipse.statet.ecommons.waltable.ui.matcher; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; public interface IMouseEventMatcher { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/LetterOrDigitKeyEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/LetterOrDigitKeyEventMatcher.java index 14667383..7409f225 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/LetterOrDigitKeyEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/LetterOrDigitKeyEventMatcher.java @@ -79,7 +79,7 @@ public class LetterOrDigitKeyEventMatcher implements IKeyEventMatcher { */ public static boolean isLetterOrDigit(final char character) { return Character.isLetterOrDigit(character) - || Character.valueOf(character).toString().matches( + || Character.toString(character).matches( "[\\.:,;\\-_#\'+*~!?§$%&/()\\[\\]\\{\\}=\\\\\"]"); //$NON-NLS-1$ } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/MouseEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/MouseEventMatcher.java index 2de09320..913a8a7e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/MouseEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/matcher/MouseEventMatcher.java @@ -16,8 +16,8 @@ package org.eclipse.statet.ecommons.waltable.ui.matcher; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; public class MouseEventMatcher implements IMouseEventMatcher { @@ -55,7 +55,7 @@ public class MouseEventMatcher implements IMouseEventMatcher { /** * Constructor * @param stateMask @see "org.eclipse.swt.events.MouseEvent.stateMask" - * @param eventRegion {@linkplain org.eclipse.statet.ecommons.waltable.grid.GridRegion} + * @param eventRegion {@linkplain org.eclipse.statet.ecommons.waltable.grid.core.GridLabels} * @param button @see org.eclipse.swt.events.MouseEvent#button * {@link IMouseEventMatcher#LEFT_BUTTON}, {@link IMouseEventMatcher#RIGHT_BUTTON} * can be used for convenience @@ -119,43 +119,28 @@ public class MouseEventMatcher implements IMouseEventMatcher { public static MouseEventMatcher columnHeaderLeftClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.COLUMN_HEADER, LEFT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.COLUMN_HEADER, LEFT_BUTTON); } public static MouseEventMatcher columnHeaderRightClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.COLUMN_HEADER, RIGHT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.COLUMN_HEADER, RIGHT_BUTTON); } public static MouseEventMatcher rowHeaderLeftClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.ROW_HEADER, LEFT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.ROW_HEADER, LEFT_BUTTON); } public static MouseEventMatcher rowHeaderRightClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.ROW_HEADER, RIGHT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.ROW_HEADER, RIGHT_BUTTON); } public static MouseEventMatcher bodyLeftClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.BODY, LEFT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.BODY, LEFT_BUTTON); } public static MouseEventMatcher bodyRightClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.BODY, RIGHT_BUTTON); - } - - public static MouseEventMatcher columnGroupHeaderLeftClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.COLUMN_GROUP_HEADER, LEFT_BUTTON); - } - - public static MouseEventMatcher columnGroupHeaderRightClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.COLUMN_GROUP_HEADER, RIGHT_BUTTON); + return new MouseEventMatcher(mask, GridLabels.BODY, RIGHT_BUTTON); } - public static MouseEventMatcher rowGroupHeaderLeftClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.ROW_GROUP_HEADER, LEFT_BUTTON); - } - - public static MouseEventMatcher rowGroupHeaderRightClick(final int mask) { - return new MouseEventMatcher(mask, GridRegion.ROW_GROUP_HEADER, RIGHT_BUTTON); - } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/AbstractHeaderMenuConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/AbstractHeaderMenuConfiguration.java index 41ef0841..15a975c3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/AbstractHeaderMenuConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/AbstractHeaderMenuConfiguration.java @@ -20,7 +20,7 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; @@ -116,19 +116,19 @@ public class AbstractHeaderMenuConfiguration extends AbstractUiBindingConfigurat public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) { if (this.colHeaderMenu != null) { uiBindingRegistry.registerMouseDownBinding( - new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, MouseEventMatcher.RIGHT_BUTTON), + new MouseEventMatcher(SWT.NONE, GridLabels.COLUMN_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.colHeaderMenu)); } if (this.rowHeaderMenu != null) { uiBindingRegistry.registerMouseDownBinding( - new MouseEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, MouseEventMatcher.RIGHT_BUTTON), + new MouseEventMatcher(SWT.NONE, GridLabels.ROW_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.rowHeaderMenu)); } if (this.cornerMenu != null) { uiBindingRegistry.registerMouseDownBinding( - new MouseEventMatcher(SWT.NONE, GridRegion.CORNER, MouseEventMatcher.RIGHT_BUTTON), + new MouseEventMatcher(SWT.NONE, GridLabels.CORNER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(this.cornerMenu)); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/BodyMenuConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/BodyMenuConfiguration.java index 9a6b9d94..1f05185f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/BodyMenuConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/BodyMenuConfiguration.java @@ -21,8 +21,8 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.statet.ecommons.waltable.Messages; import org.eclipse.statet.ecommons.waltable.NatTable; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; @@ -31,7 +31,7 @@ public class BodyMenuConfiguration extends AbstractUiBindingConfiguration { private final Menu colHeaderMenu; - public BodyMenuConfiguration(final NatTable natTable, final ILayer bodyLayer) { + public BodyMenuConfiguration(final NatTable natTable, final Layer bodyLayer) { this.colHeaderMenu= new PopupMenuBuilder(natTable) .withColumnStyleEditor(Messages.getString("ColumnStyleEditorDialog.shellTitle")) //$NON-NLS-1$ .build(); @@ -49,7 +49,7 @@ public class BodyMenuConfiguration extends AbstractUiBindingConfiguration { @Override public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) { uiBindingRegistry.registerMouseDownBinding( - new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_HEADER, 3), + new MouseEventMatcher(SWT.NONE, GridLabels.COLUMN_HEADER, 3), new PopupMenuAction(this.colHeaderMenu)); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/MenuItemProviders.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/MenuItemProviders.java index 37eaa319..d4cb89d2 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/MenuItemProviders.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/menu/MenuItemProviders.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.ui.menu; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -26,10 +26,9 @@ import org.eclipse.swt.widgets.Widget; import org.eclipse.statet.ecommons.waltable.Messages; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.persistence.DisplayPersistenceDialogCommand; -import org.eclipse.statet.ecommons.waltable.resize.InitializeAutoResizeCommand; +import org.eclipse.statet.ecommons.waltable.resize.core.InitializeAutoResizeCommand; import org.eclipse.statet.ecommons.waltable.style.editor.DisplayColumnStyleEditorCommand; import org.eclipse.statet.ecommons.waltable.ui.NatEventData; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -165,7 +164,7 @@ public class MenuItemProviders { public void widgetSelected(final SelectionEvent event) { final long rowPosition= getNatEventData(event).getRowPosition(); final long columnPosition= getNatEventData(event).getColumnPosition(); - natTable.doCommand(new DisplayColumnStyleEditorCommand(natTable, natTable.getConfigRegistry(), columnPosition, rowPosition)); + natTable.doCommand(new DisplayColumnStyleEditorCommand(natTable, natTable.getStyleRegistry(), columnPosition, rowPosition)); } }); } @@ -190,15 +189,15 @@ public class MenuItemProviders { final long columnPosition= natEventData.getColumnPosition(); final long rowPosition= natEventData.getRowPosition(); - final ILayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); + final LayerCell cell= natTable.getCellByPosition(columnPosition, rowPosition); final String msg= "Display mode: " + cell.getDisplayMode() + //$NON-NLS-1$ - "\nConfig labels: " + cell.getConfigLabels() + //$NON-NLS-1$ + "\nConfig labels: " + cell.getLabels() + //$NON-NLS-1$ "\nData value: " + cell.getDataValue(0, null) + //$NON-NLS-1$ "\n\nColumn position: " + columnPosition + //$NON-NLS-1$ - "\nColumn id: " + cell.getDim(Orientation.HORIZONTAL).getId() + //$NON-NLS-1$ + "\nColumn id: " + cell.getDim(HORIZONTAL).getId() + //$NON-NLS-1$ "\n\nRow position: " + rowPosition + //$NON-NLS-1$ - "\nRow id: " + cell.getDim(Orientation.VERTICAL).getId(); //$NON-NLS-1$ + "\nRow id: " + cell.getDim(VERTICAL).getId(); //$NON-NLS-1$ final MessageBox messageBox= new MessageBox(natTable.getShell(), SWT.ICON_INFORMATION | SWT.OK); messageBox.setText(Messages.getString("MenuItemProviders.debugInformation")); //$NON-NLS-1$ diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/widget/NatCombo.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/swt/widgets/NatCombo.java index 1ec70143..c3c2f8d7 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/widget/NatCombo.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/swt/widgets/NatCombo.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.widget; +package org.eclipse.statet.ecommons.waltable.ui.swt.widgets; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; @@ -54,11 +54,11 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.HorizontalAlignment; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.style.CellStyleUtil; -import org.eclipse.statet.ecommons.waltable.style.HorizontalAlignment; -import org.eclipse.statet.ecommons.waltable.style.IStyle; -import org.eclipse.statet.ecommons.waltable.style.VerticalAlignment; import org.eclipse.statet.ecommons.waltable.ui.matcher.LetterOrDigitKeyEventMatcher; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -105,7 +105,7 @@ public class NatCombo extends Composite { * The important configurations used are horizontal alignment, background and * foreground color and font. */ - protected final IStyle cellStyle; + protected final Style cellStyle; /** * The maximum number of visible items of the combo. @@ -215,7 +215,7 @@ public class NatCombo extends Composite { * @param style The style for the Text Control to construct. Uses this style * adding internal styles via ConfigRegistry. */ - public NatCombo(final Composite parent, final IStyle cellStyle, final int style) { + public NatCombo(final Composite parent, final Style cellStyle, final int style) { this(parent, cellStyle, DEFAULT_NUM_OF_VISIBLE_ITEMS, style, GUIHelper.getImage("down_2")); //$NON-NLS-1$ } @@ -231,7 +231,7 @@ public class NatCombo extends Composite { * @param style The style for the Text Control to construct. Uses this style * adding internal styles via ConfigRegistry. */ - public NatCombo(final Composite parent, final IStyle cellStyle, final int maxVisibleItems, final int style) { + public NatCombo(final Composite parent, final Style cellStyle, final int maxVisibleItems, final int style) { this(parent, cellStyle, maxVisibleItems, style, GUIHelper.getImage("down_2")); //$NON-NLS-1$ } @@ -249,7 +249,7 @@ public class NatCombo extends Composite { * is visible. Using this image will indicate that the control is an open combo * to the user. */ - public NatCombo(final Composite parent, final IStyle cellStyle, final int maxVisibleItems, final int style, final Image iconImage) { + public NatCombo(final Composite parent, final Style cellStyle, final int maxVisibleItems, final int style, final Image iconImage) { super(parent, SWT.NONE); this.cellStyle= cellStyle; @@ -304,9 +304,9 @@ public class NatCombo extends Composite { protected void createTextControl(final int style) { final int widgetStyle= style | CellStyleUtil.getHorizontalAlignmentSWT(this.cellStyle, SWT.NONE); this.text= new Text(this, widgetStyle); - this.text.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); - this.text.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); - this.text.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT)); + this.text.setBackground(this.cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); + this.text.setForeground(this.cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR)); + this.text.setFont(this.cellStyle.getAttributeValue(CellStyling.FONT)); GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true); this.text.setLayoutData(gridData); @@ -434,9 +434,9 @@ public class NatCombo extends Composite { | CellStyleUtil.getHorizontalAlignmentSWT(this.cellStyle, SWT.NONE); this.dropdownTable= new Table(this.dropdownShell, dropdownListStyle); - this.dropdownTable.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); - this.dropdownTable.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); - this.dropdownTable.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT)); + this.dropdownTable.setBackground(this.cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR)); + this.dropdownTable.setForeground(this.cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR)); + this.dropdownTable.setFont(this.cellStyle.getAttributeValue(CellStyling.FONT)); this.dropdownTable.addSelectionListener(new SelectionAdapter() { @Override diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/util/CellEdgeDetectUtil.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/util/CellEdgeDetectUtil.java index e4b877bb..df8e5a45 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/util/CellEdgeDetectUtil.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/ui/util/CellEdgeDetectUtil.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.ui.util; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import static org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum.BOTTOM; import static org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum.LEFT; import static org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum.NONE; @@ -22,11 +22,11 @@ import static org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum.RIGHT; import static org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum.TOP; import static org.eclipse.statet.ecommons.waltable.util.GUIHelper.DEFAULT_RESIZE_HANDLE_SIZE; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public class CellEdgeDetectUtil { @@ -37,9 +37,9 @@ public class CellEdgeDetectUtil { * on the left/right edges of the cell. * Does <i>not</i> take into account columns which are not allowed to be resized. */ - public static long getPositionToResize(final ILayer layer, final LPoint clickPoint, + public static long getPositionToResize(final Layer layer, final LPoint clickPoint, final Orientation orientation) { - final ILayerCell cell= layer.getCellByPosition( + final LayerCell cell= layer.getCellByPosition( layer.getDim(HORIZONTAL).getPositionByPixel(clickPoint.x), layer.getDim(VERTICAL).getPositionByPixel(clickPoint.y) ); if (cell != null) { @@ -65,13 +65,13 @@ public class CellEdgeDetectUtil { } - public static CellEdgeEnum getHorizontalCellEdge(final ILayer layer, final LPoint clickPt) { + public static CellEdgeEnum getHorizontalCellEdge(final Layer layer, final LPoint clickPt) { return getHorizontalCellEdge(layer, clickPt, -1); } - public static CellEdgeEnum getHorizontalCellEdge(final ILayer layer, final LPoint clickPt, + public static CellEdgeEnum getHorizontalCellEdge(final Layer layer, final LPoint clickPt, final long handleWidth) { - final ILayerCell cell= layer.getCellByPosition( + final LayerCell cell= layer.getCellByPosition( layer.getColumnPositionByX(clickPt.x), layer.getRowPositionByY(clickPt.y) ); @@ -108,13 +108,13 @@ public class CellEdgeDetectUtil { } - public static CellEdgeEnum getVerticalCellEdge(final ILayer layer, final LPoint clickPt) { + public static CellEdgeEnum getVerticalCellEdge(final Layer layer, final LPoint clickPt) { return getVerticalCellEdge(layer, clickPt, -1); } - public static CellEdgeEnum getVerticalCellEdge(final ILayer layer, final LPoint clickPt, + public static CellEdgeEnum getVerticalCellEdge(final Layer layer, final LPoint clickPt, final long handleHeight) { - final ILayerCell cell= layer.getCellByPosition( + final LayerCell cell= layer.getCellByPosition( layer.getColumnPositionByX(clickPt.x), layer.getRowPositionByY(clickPt.y) ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/ComparatorChain.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/ComparatorChain.java deleted file mode 100644 index 86dda67e..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/ComparatorChain.java +++ /dev/null @@ -1,39 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.util; - -import java.util.Comparator; -import java.util.List; - - -public class ComparatorChain<T> implements Comparator<T> { - - private final List<Comparator<T>> comparators; - - public ComparatorChain(final List<Comparator<T>> comparators) { - this.comparators= comparators; - } - - @Override - public int compare(final T arg0, final T arg1) { - for (int i= 0; i < this.comparators.size(); i++) { - final int compareResult= this.comparators.get(i).compare(arg0, arg1); - if (compareResult != 0) { - return compareResult; - } - } - return 0; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/GUIHelper.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/GUIHelper.java index 80cd72b4..5474e42c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/GUIHelper.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/util/GUIHelper.java @@ -56,28 +56,10 @@ public class GUIHelper { public static final Color COLOR_WIDGET_NORMAL_SHADOW= Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); public static final Color COLOR_WIDGET_HIGHLIGHT_SHADOW= Display.getDefault().getSystemColor( SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); - public static Color getColor(final RGB rgb) { - return getColor(rgb.red, rgb.green, rgb.blue); - } - - public static Color getColor(final int red, final int green, final int blue) { - final String key= getColorKey(red, green, blue); - if (JFaceResources.getColorRegistry().hasValueFor(key)) { - return JFaceResources.getColorRegistry().get(key); - } else { - JFaceResources.getColorRegistry().put(key, new RGB(red, green, blue)); - return getColor(key); - } - } - public static Color getColor(final String key) { return JFaceResources.getColorRegistry().get(key); } - private static String getColorKey(final int red, final int green, final int blue) { - return KEY_PREFIX + "_COLOR_" + red + "_" + green + "_" + blue; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - // Font public static final Font DEFAULT_FONT= Display.getDefault().getSystemFont(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollEvent.java deleted file mode 100644 index 44fb0dec..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.viewport; - -import java.util.Collection; - -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; - - -public class ScrollEvent extends StructuralRefreshEvent { - - public ScrollEvent(final ViewportLayer viewportLayer) { - super(viewportLayer); - } - - protected ScrollEvent(final ScrollEvent event) { - super(event); - } - - @Override - public ScrollEvent cloneEvent() { - return new ScrollEvent(this); - } - - @Override - public Collection<StructuralDiff> getColumnDiffs() { - // TODO this is bogus - should have a horiz/vert scroll event instead that are multi col/row structural changes - return null; - } - - @Override - public Collection<StructuralDiff> getRowDiffs() { - // TODO this is bogus - should have a horiz/vert scroll event instead that are multi col/row structural changes - return null; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/SelectRelativePageCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/SelectRelativePageCommandHandler.java deleted file mode 100644 index ef633774..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/SelectRelativePageCommandHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2010, 2021 Stephan Wahlbrink and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 - # which is available at https://www.apache.org/licenses/LICENSE-2.0. - # - # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 - # - # Contributors: - # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.viewport; - -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.selection.SelectRelativeCellCommand; - - -public class SelectRelativePageCommandHandler extends AbstractLayerCommandHandler<SelectRelativePageCommand> { - - - private final ILayer viewportLayer; - - - public SelectRelativePageCommandHandler(final ILayer viewportLayer) { - this.viewportLayer= viewportLayer; - } - - - @Override - public Class<SelectRelativePageCommand> getCommandClass() { - return SelectRelativePageCommand.class; - } - - @Override - protected boolean doCommand(final SelectRelativePageCommand command) { - if (command.convertToTargetLayer(this.viewportLayer)) { - long stepCount; - switch (command.getDirection()) { - case UP: - case DOWN: - stepCount= this.viewportLayer.getRowCount(); - break; - case LEFT: - case RIGHT: - stepCount= this.viewportLayer.getColumnCount(); - break; - default: - return false; - } - this.viewportLayer.doCommand(new SelectRelativeCellCommand( - command.getDirection(), stepCount, command.getSelectionFlags() )); - } - return true; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/widget/WaitDialog.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/widget/WaitDialog.java deleted file mode 100644 index 11900d2c..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/widget/WaitDialog.java +++ /dev/null @@ -1,90 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2012, 2021 Original NatTable authors and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # Original NatTable authors and others - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.ecommons.waltable.widget; - -import static org.eclipse.swt.layout.GridData.CENTER; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.statet.ecommons.waltable.util.GUIHelper; - - -public class WaitDialog extends Dialog { - - private String msg; - private final Image iconImage; - private Label textLabel; - - public WaitDialog(final Shell parent, final int shellStyle, final String msg, final Image iconImg) { - super(parent); - this.msg= msg; - this.iconImage= iconImg; - setShellStyle(shellStyle | SWT.APPLICATION_MODAL); - } - - private void centerDialogOnScreen(final Shell shell) { - shell.setSize(250, 75); - final org.eclipse.swt.graphics.Rectangle parentSize= getParentShell().getBounds(); - final org.eclipse.swt.graphics.Rectangle mySize= shell.getBounds(); - int locationX, locationY; - locationX= (parentSize.width - mySize.width)/2+parentSize.x; - locationY= (parentSize.height - mySize.height)/2+parentSize.y; - shell.setLocation(locationX, locationY); - } - - @Override - protected Control createContents(final Composite parent) { - centerDialogOnScreen(getShell()); - - final Composite composite= new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(CENTER, CENTER, true, true)); - composite.setRedraw(true); - - final Label imgLabel= new Label(composite, SWT.NONE); - imgLabel.setImage(this.iconImage); - - this.textLabel= new Label(composite, SWT.NONE); - this.textLabel.setLayoutData(new GridData(CENTER, CENTER, true, true)); - this.textLabel.setFont(GUIHelper.getFont(new FontData("Arial", 9, SWT.BOLD))); //$NON-NLS-1$ - this.textLabel.setRedraw(true); - this.textLabel.setText(this.msg); - - return composite; - } - - public void setMsg(final String msg) { - this.msg= msg; - this.textLabel.setText(msg); - getShell().layout(new Control[]{this.textLabel}); - } - - @Override - public boolean close() { - if (this.iconImage != null) { - this.iconImage.dispose(); - } - return super.close(); - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/internal/ecommons/waltable/LayerListenerList.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/internal/ecommons/waltable/LayerListenerList.java deleted file mode 100644 index bb7801f4..00000000 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/internal/ecommons/waltable/LayerListenerList.java +++ /dev/null @@ -1,173 +0,0 @@ -/*=============================================================================# - # Copyright (c) 2004, 2021 IBM Corporation and others. - # - # This program and the accompanying materials are made available under the - # terms of the Eclipse Public License 2.0 which is available at - # https://www.eclipse.org/legal/epl-2.0. - # - # SPDX-License-Identifier: EPL-2.0 - # - # Contributors: - # IBM Corporation - org.eclipse.platform: initial API and implementation - # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation - #=============================================================================*/ - -package org.eclipse.statet.internal.ecommons.waltable; - -import org.eclipse.statet.ecommons.waltable.layer.ILayerListener; - - -/** - * This class is a thread safe list that is designed for storing lists of listeners. - * The implementation is optimized for minimal memory footprint, frequent reads - * and infrequent writes. Modification of the list is synchronized and relatively - * expensive, while accessing the listeners is very fast. Readers are given access - * to the underlying array data structure for reading, with the trust that they will - * not modify the underlying array. - * <p> - * <a name="same">A listener list handles the <i>same</i> listener being added - * multiple times, and tolerates removal of listeners that are the same as other - * listeners in the list. For this purpose, listeners can be compared with each other - * using either equality or identity, as specified in the list constructor. - * </p> - * <p> - * Use the <code>getListeners</code> method when notifying listeners. The recommended - * code sequence for notifying all registered listeners of say, - * <code>FooListener.eventHappened</code>, is: - * - * <pre> - * Object[] listeners= myListenerList.getListeners(); - * for (int i= 0; i < listeners.length; ++i) { - * ((FooListener) listeners[i]).eventHappened(event); - * } - * </pre> - * - * </p><p> - * This class can be used without OSGi running. - * </p> - * @since org.eclipse.equinox.common 3.2 - */ -public class LayerListenerList { - - /** - * The empty array singleton instance. - */ - private static final ILayerListener[] EMPTY_ARRAY= new ILayerListener[0]; - - - /** - * The list of listeners. Initially empty but initialized - * to an array of size capacity the first time a listener is added. - * Maintains invariant: listeners != null - */ - private volatile ILayerListener[] listeners= EMPTY_ARRAY; - - /** - * Creates a listener list. - */ - public LayerListenerList() { - } - - - /** - * Adds a listener to this list. This method has no effect if the <a href="#same">same</a> - * listener is already registered. - * - * @param listener the non-<code>null</code> listener to add - */ - public synchronized void add(final ILayerListener listener) { - // This method is synchronized to protect against multiple threads adding - // or removing listeners concurrently. This does not block concurrent readers. - if (listener == null) { - throw new IllegalArgumentException(); - } - // check for duplicates - final int oldSize= this.listeners.length; - for (int i= 0; i < oldSize; ++i) { - final ILayerListener listener2= this.listeners[i]; - if (listener == listener2) { - return; - } - } - // Thread safety: create new array to avoid affecting concurrent readers - final ILayerListener[] newListeners= new ILayerListener[oldSize + 1]; - System.arraycopy(this.listeners, 0, newListeners, 0, oldSize); - newListeners[oldSize]= listener; - //atomic assignment - this.listeners= newListeners; - } - - /** - * Returns an array containing all the registered listeners. - * The resulting array is unaffected by subsequent adds or removes. - * If there are no listeners registered, the result is an empty array. - * Use this method when notifying listeners, so that any modifications - * to the listener list during the notification will have no effect on - * the notification itself. - * <p> - * Note: Callers of this method <b>must not</b> modify the returned array. - * - * @return the list of registered listeners - */ - public ILayerListener[] getListeners() { - return this.listeners; - } - - /** - * Returns whether this listener list is empty. - * - * @return <code>true</code> if there are no registered listeners, and - * <code>false</code> otherwise - */ - public boolean isEmpty() { - return this.listeners.length == 0; - } - - /** - * Removes a listener from this list. Has no effect if the <a href="#same">same</a> - * listener was not already registered. - * - * @param listener the non-<code>null</code> listener to remove - */ - public synchronized void remove(final Object listener) { - // This method is synchronized to protect against multiple threads adding - // or removing listeners concurrently. This does not block concurrent readers. - if (listener == null) { - throw new IllegalArgumentException(); - } - final int oldSize= this.listeners.length; - for (int i= 0; i < oldSize; ++i) { - final ILayerListener listener2= this.listeners[i]; - if (listener == listener2) { - if (oldSize == 1) { - this.listeners= EMPTY_ARRAY; - } else { - // Thread safety: create new array to avoid affecting concurrent readers - final ILayerListener[] newListeners= new ILayerListener[oldSize - 1]; - System.arraycopy(this.listeners, 0, newListeners, 0, i); - System.arraycopy(this.listeners, i + 1, newListeners, i, oldSize - i - 1); - //atomic assignment to field - this.listeners= newListeners; - } - return; - } - } - } - - /** - * Returns the number of registered listeners. - * - * @return the number of registered listeners - */ - public long size() { - return this.listeners.length; - } - - /** - * Removes all listeners from this list. - */ - public synchronized void clear() { - this.listeners= EMPTY_ARRAY; - } - -} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommand.java index f99f5b90..e855b459 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommand.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.copy; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; public class CopyToClipboardCommand extends AbstractContextFreeCommand { @@ -22,10 +22,10 @@ public class CopyToClipboardCommand extends AbstractContextFreeCommand { private final String cellDelimeter; private final String rowDelimeter; - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; - public CopyToClipboardCommand(final String cellDelimeter, final String rowDelimeter, final IConfigRegistry configRegistry) { + public CopyToClipboardCommand(final String cellDelimeter, final String rowDelimeter, final ConfigRegistry configRegistry) { this.cellDelimeter= cellDelimeter; this.rowDelimeter= rowDelimeter; this.configRegistry= configRegistry; @@ -40,7 +40,7 @@ public class CopyToClipboardCommand extends AbstractContextFreeCommand { return this.rowDelimeter; } - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommandHandler.java index 67cfb6e9..66a77a1d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/CopyToClipboardCommandHandler.java @@ -25,15 +25,16 @@ import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.ILValueIterator; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.data.ControlData; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.collections.LongIterator; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.data.ControlData; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.layer.cell.CellDisplayConversionUtils; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.ecommons.waltable.ui.ITableUIContext; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -57,12 +58,12 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C /** * The column header layer of the grid, needed to also copy the column header data. */ - private final ILayer columnHeaderDataLayer; + private final Layer columnHeaderDataLayer; /** * The row header layer of the grid, needed to also copy the row header data. */ - private final ILayer rowHeaderDataLayer; + private final Layer rowHeaderDataLayer; private final ITableUIContext uiContext; @@ -84,7 +85,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C * @param rowHeaderDataLayer The row header data layer within the NatTable grid. Can be <code>null</code>. */ public CopyToClipboardCommandHandler(final SelectionLayer selectionLayer, - final ILayer columnHeaderDataLayer, final ILayer rowHeaderDataLayer, + final Layer columnHeaderDataLayer, final Layer rowHeaderDataLayer, final ITableUIContext uiContext) { if (selectionLayer == null) { throw new NullPointerException("selectionLayer"); //$NON-NLS-1$ @@ -107,7 +108,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C } private void doCopy(final CopyToClipboardCommand command) { - final ILayerCell[][] copiedCells= assembleCopiedDataStructure(); + final LayerCell[][] copiedCells= assembleCopiedDataStructure(); if (copiedCells.length == 0) { return; } @@ -119,7 +120,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C if (rowCount <= 1000 && colCount <= 1000) { for (int rowIdx= 0; rowIdx < rowCount; rowIdx++) { for (int colIdx= 0; colIdx < colCount; colIdx++) { - final ILayerCell cell= copiedCells[rowIdx][colIdx]; + final LayerCell cell= copiedCells[rowIdx][colIdx]; if (cell != null) { final Object dataValue= cell.getDataValue(0, null); if (dataValue instanceof ControlData) { @@ -161,7 +162,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C final StringBuilder textBuilder= new StringBuilder(); for (int rowIdx= 0; rowIdx < rowCount; ) { for (int colIdx= 0; colIdx < colCount; ) { - final ILayerCell cell= copiedCells[rowIdx][colIdx]; + final LayerCell cell= copiedCells[rowIdx][colIdx]; if (cell != null) { textBuilder.append(getTextForCell(command, cell, values[rowIdx][colIdx])); } @@ -189,7 +190,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C } } - private void loadAsync(final ILayerCell[][] copiedCells, final Object[][] values, + private void loadAsync(final LayerCell[][] copiedCells, final Object[][] values, final int startRowIdx, final int startColIdx) throws CoreException { try { this.uiContext.run(true, true, new IRunnableWithProgress() { @@ -204,9 +205,9 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C for (int rowIdx= startRowIdx; rowIdx < rowCount; rowIdx++) { for (int colIdx= (rowIdx == startRowIdx) ? startColIdx : 0; colIdx < colCount; colIdx++) { - final ILayerCell cell= copiedCells[rowIdx][colIdx]; + final LayerCell cell= copiedCells[rowIdx][colIdx]; if (cell != null) { - final Object dataValue= cell.getDataValue(IDataProvider.FORCE_SYNC, + final Object dataValue= cell.getDataValue(DataProvider.FORCE_SYNC, monitor ); if (dataValue instanceof ControlData) { if ((((ControlData) dataValue).getCode() & ControlData.ERROR) != 0) { @@ -249,7 +250,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C } } - protected String getTextForCell(final CopyToClipboardCommand command, final ILayerCell cell, final Object value) { + protected String getTextForCell(final CopyToClipboardCommand command, final LayerCell cell, final Object value) { return CellDisplayConversionUtils.convertDataType(cell, value, command.getConfigRegistry()); } @@ -269,7 +270,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C * The first level of this array represent the row positions of the cells, while the * second level contains the cells itself based on the column position. */ - protected ILayerCell[][] assembleCopiedDataStructure() { + protected LayerCell[][] assembleCopiedDataStructure() { final LRangeList selectedRowPositions= this.selectionLayer.getSelectedRowPositions(); final LRangeList selectedColumnPositions= this.selectionLayer.getSelectedColumnPositions(); @@ -280,13 +281,13 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C throw new UnsupportedOperationException("Selected area too large."); } - final ILayerCell[][] cells= new ILayerCell[(int) (selectedRowPositions.values().size() + rowOffset)][]; + final LayerCell[][] cells= new LayerCell[(int) (selectedRowPositions.values().size() + rowOffset)][]; int cellsIdx= 0; while (cellsIdx < rowOffset) { cells[cellsIdx++]= assembleColumnHeader(selectedColumnPositions, (int) columnOffset, cellsIdx); } - for (final ILValueIterator rowIter= selectedRowPositions.values().iterator(); rowIter.hasNext(); ) { + for (final LongIterator rowIter= selectedRowPositions.values().iterator(); rowIter.hasNext(); ) { final long rowPosition= rowIter.nextValue(); cells[cellsIdx++]= assembleBody(selectedColumnPositions, (int) columnOffset, rowPosition); } @@ -304,13 +305,13 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C * @param headerRowPosition The row position in the column header of which the information should be collected * @return An array containing the column header information */ - protected ILayerCell[] assembleColumnHeader(final LRangeList selectedColumnPositions, final int columnOffset, + protected LayerCell[] assembleColumnHeader(final LRangeList selectedColumnPositions, final int columnOffset, final long headerRowPosition) { - final ILayerCell[] headerCells= new ILayerCell[(int) (selectedColumnPositions.values().size() + columnOffset)]; + final LayerCell[] headerCells= new LayerCell[(int) (selectedColumnPositions.values().size() + columnOffset)]; int headerIdx= columnOffset; if (this.columnHeaderDataLayer != null) { - for (final ILValueIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); headerIdx++) { + for (final LongIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); headerIdx++) { final long columnPosition= columnIter.nextValue(); headerCells[headerIdx]= this.columnHeaderDataLayer.getCellByPosition(columnPosition, headerRowPosition); } @@ -329,9 +330,9 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C * @param currentRowPosition The row position of which the selected cells should be collected * @return An array containing the specified cells */ - protected ILayerCell[] assembleBody(final LRangeList selectedColumnPositions, final int columnOffset, + protected LayerCell[] assembleBody(final LRangeList selectedColumnPositions, final int columnOffset, final long currentRowPosition) { - final ILayerCell[] bodyCells= new ILayerCell[(int) (selectedColumnPositions.values().size() + columnOffset)]; + final LayerCell[] bodyCells= new LayerCell[(int) (selectedColumnPositions.values().size() + columnOffset)]; int bodyIdx= 0; if (this.rowHeaderDataLayer != null) { @@ -339,7 +340,7 @@ public class CopyToClipboardCommandHandler extends AbstractLayerCommandHandler<C bodyCells[bodyIdx]= this.rowHeaderDataLayer.getCellByPosition(bodyIdx, currentRowPosition); } } - for (final ILValueIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); bodyIdx++) { + for (final LongIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); bodyIdx++) { final long columnPosition= columnIter.nextValue(); if (this.selectionLayer.isCellPositionSelected(columnPosition, currentRowPosition)) { bodyCells[bodyIdx]= this.selectionLayer.getCellByPosition(columnPosition, currentRowPosition); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/action/CopyDataAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/ui/action/CopyDataAction.java index 1be54aa8..183f2ab0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/copy/action/CopyDataAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/copy/ui/action/CopyDataAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.copy.action; +package org.eclipse.statet.ecommons.waltable.copy.ui.action; import org.eclipse.swt.events.KeyEvent; @@ -29,8 +29,8 @@ public class CopyDataAction implements IKeyAction { @Override public void run(final NatTable natTable, final KeyEvent event) { - natTable.doCommand(new CopyToClipboardCommand("\t", System.getProperty("line.separator"), //$NON-NLS-1$ //$NON-NLS-2$ - natTable.getConfigRegistry() )); + natTable.doCommand(new CopyToClipboardCommand("\t", System.lineSeparator(), //$NON-NLS-1$ + natTable.getStyleRegistry() )); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportCommand.java index d0fc412a..f43b616c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportCommand.java @@ -15,21 +15,21 @@ package org.eclipse.statet.ecommons.waltable.export; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; public class ExportCommand extends AbstractContextFreeCommand { - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; private final Shell shell; - public ExportCommand(final IConfigRegistry configRegistry, final Shell shell) { + public ExportCommand(final ConfigRegistry configRegistry, final Shell shell) { this.configRegistry= configRegistry; this.shell= shell; } - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportCommandHandler.java index 149c48e6..142bc753 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportCommandHandler.java @@ -15,32 +15,39 @@ package org.eclipse.statet.ecommons.waltable.export; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public class ExportCommandHandler extends AbstractLayerCommandHandler<ExportCommand> { - private final ILayer layer; - - public ExportCommandHandler(final ILayer layer) { +@NonNullByDefault +public class ExportCommandHandler implements LayerCommandHandler<ExportCommand> { + + + private final Layer layer; + + + public ExportCommandHandler(final Layer layer) { this.layer= layer; } - + + + @Override + public Class<ExportCommand> getCommandClass() { + return ExportCommand.class; + } + + @Override - public boolean doCommand(final ExportCommand command) { + public boolean executeCommand(final ExportCommand command) { final Shell shell= command.getShell(); - final IConfigRegistry configRegistry= command.getConfigRegistry(); + final ConfigRegistry configRegistry= command.getConfigRegistry(); new NatExporter(shell).exportSingleLayer(this.layer, configRegistry); return true; } - - @Override - public Class<ExportCommand> getCommandClass() { - return ExportCommand.class; - } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportConfigAttributes.java index e39bbdfb..14d6b1c1 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ExportConfigAttributes.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ExportConfigAttributes.java @@ -12,7 +12,7 @@ #=============================================================================*/ package org.eclipse.statet.ecommons.waltable.export; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/FileOutputStreamProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/FileOutputStreamProvider.java index f4f055ec..f4f055ec 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/FileOutputStreamProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/FileOutputStreamProvider.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/IExportFormatter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/IExportFormatter.java index dd071452..c3d7fc63 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/IExportFormatter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/IExportFormatter.java @@ -13,12 +13,12 @@ package org.eclipse.statet.ecommons.waltable.export; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; public interface IExportFormatter { - Object formatForExport(ILayerCell cell, IConfigRegistry configRegistry); + Object formatForExport(LayerCell cell, ConfigRegistry configRegistry); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ILayerExporter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ILayerExporter.java index e29539b9..ff3a7d7c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/ILayerExporter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ILayerExporter.java @@ -18,8 +18,8 @@ import java.io.OutputStream; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -137,6 +137,6 @@ public interface ILayerExporter { * of the cell that is currently exported. * @throws IOException If an error occurred during writing the export. */ - void exportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) throws IOException; + void exportCell(OutputStream outputStream, Object exportDisplayValue, LayerCell cell, ConfigRegistry configRegistry) throws IOException; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/IOutputStreamProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/IOutputStreamProvider.java index c558feaf..c558feaf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/IOutputStreamProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/IOutputStreamProvider.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/NatExporter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/NatExporter.java index 49855817..a8a5f51d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/NatExporter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/NatExporter.java @@ -25,15 +25,15 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.statet.ecommons.waltable.Messages; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.ClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.print.PrintEntireGridCommand; import org.eclipse.statet.ecommons.waltable.print.TurnViewportOffCommand; import org.eclipse.statet.ecommons.waltable.print.TurnViewportOnCommand; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; public class NatExporter { @@ -50,8 +50,8 @@ public class NatExporter { * @param configRegistry The ConfigRegistry of the NatTable instance to export, * that contains the necessary export configurations. */ - public void exportSingleLayer(final ILayer layer, final IConfigRegistry configRegistry) { - final ILayerExporter exporter= configRegistry.getConfigAttribute(ExportConfigAttributes.EXPORTER, DisplayMode.NORMAL); + public void exportSingleLayer(final Layer layer, final ConfigRegistry configRegistry) { + final ILayerExporter exporter= configRegistry.getAttribute(ExportConfigAttributes.EXPORTER, DisplayMode.NORMAL); final OutputStream outputStream= exporter.getOutputStream(this.shell); if (outputStream == null) { @@ -109,7 +109,7 @@ public class NatExporter { for (final String name : natTablesMap.keySet()) { final NatTable natTable= natTablesMap.get(name); - exportLayer(exporter, outputStream, name, natTable, natTable.getConfigRegistry()); + exportLayer(exporter, outputStream, name, natTable, natTable.getStyleRegistry()); } exporter.exportEnd(outputStream); @@ -146,8 +146,8 @@ public class NatExporter { * @param layer * @param configRegistry */ - protected void exportLayer(final ILayerExporter exporter, final OutputStream outputStream, final String layerName, final ILayer layer, final IConfigRegistry configRegistry) { - final IClientAreaProvider originalClientAreaProvider= layer.getClientAreaProvider(); + protected void exportLayer(final ILayerExporter exporter, final OutputStream outputStream, final String layerName, final Layer layer, final ConfigRegistry configRegistry) { + final ClientAreaProvider originalClientAreaProvider= layer.getClientAreaProvider(); // This needs to be done so that the layer can return all the cells // not just the ones visible in the viewport @@ -188,9 +188,9 @@ public class NatExporter { } for (long columnPosition= 0; columnPosition < layer.getColumnCount(); columnPosition++) { - final ILayerCell cell= layer.getCellByPosition(columnPosition, rowPosition); + final LayerCell cell= layer.getCellByPosition(columnPosition, rowPosition); - final IExportFormatter exportFormatter= configRegistry.getConfigAttribute(ExportConfigAttributes.EXPORT_FORMATTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); + final IExportFormatter exportFormatter= configRegistry.getAttribute(ExportConfigAttributes.EXPORT_FORMATTER, cell.getDisplayMode(), cell.getLabels().getLabels()); final Object exportDisplayValue= exportFormatter.formatForExport(cell, configRegistry); exporter.exportCell(outputStream, exportDisplayValue, cell, configRegistry); @@ -215,10 +215,10 @@ public class NatExporter { } } - private void setClientAreaToMaximum(final ILayer layer) { + private void setClientAreaToMaximum(final Layer layer) { final LRectangle maxClientArea= new LRectangle(0, 0, layer.getWidth(), layer.getHeight()); - layer.setClientAreaProvider(new IClientAreaProvider() { + layer.setClientAreaProvider(new ClientAreaProvider() { @Override public LRectangle getClientArea() { return maxClientArea; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/config/DefaultExportBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/config/DefaultExportBindings.java index d41e7b1d..4ed679f3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/config/DefaultExportBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/config/DefaultExportBindings.java @@ -15,13 +15,13 @@ package org.eclipse.statet.ecommons.waltable.export.config; import org.eclipse.swt.SWT; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IConfiguration; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; import org.eclipse.statet.ecommons.waltable.export.ExportConfigAttributes; -import org.eclipse.statet.ecommons.waltable.export.action.ExportAction; import org.eclipse.statet.ecommons.waltable.export.excel.DefaultExportFormatter; import org.eclipse.statet.ecommons.waltable.export.excel.ExcelExporter; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.export.ui.action.ExportAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; @@ -34,17 +34,17 @@ public class DefaultExportBindings implements IConfiguration { } @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute( + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute( ExportConfigAttributes.EXPORTER, new ExcelExporter()); - configRegistry.registerConfigAttribute( + configRegistry.registerAttribute( ExportConfigAttributes.EXPORT_FORMATTER, new DefaultExportFormatter()); - configRegistry.registerConfigAttribute( + configRegistry.registerAttribute( ExportConfigAttributes.DATE_FORMAT, "m/d/yy h:mm"); //$NON-NLS-1$ } @Override - public void configureLayer(final ILayer layer) { + public void configureLayer(final Layer layer) { } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/DefaultExportFormatter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/DefaultExportFormatter.java index 984cad9c..10835735 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/DefaultExportFormatter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/DefaultExportFormatter.java @@ -14,18 +14,18 @@ package org.eclipse.statet.ecommons.waltable.export.excel; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.convert.IDisplayConverter; import org.eclipse.statet.ecommons.waltable.export.IExportFormatter; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; public class DefaultExportFormatter implements IExportFormatter { @Override - public Object formatForExport(final ILayerCell cell, final IConfigRegistry configRegistry) { + public Object formatForExport(final LayerCell cell, final ConfigRegistry configRegistry) { final Object dataValue= cell.getDataValue(0, null); - final IDisplayConverter displayConverter= configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels()); + final IDisplayConverter displayConverter= configRegistry.getAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getLabels().getLabels()); return displayConverter.canonicalToDisplayValue(cell, configRegistry, dataValue); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/ExcelExporter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/ExcelExporter.java index 7fd57099..10a3220d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/ExcelExporter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/ExcelExporter.java @@ -24,14 +24,15 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.RegistryStyle; import org.eclipse.statet.ecommons.waltable.export.FileOutputStreamProvider; import org.eclipse.statet.ecommons.waltable.export.ILayerExporter; import org.eclipse.statet.ecommons.waltable.export.IOutputStreamProvider; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.CellStyleProxy; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -92,9 +93,7 @@ public class ExcelExporter implements ILayerExporter { * the header content file */ private void writeHeader(final OutputStream outputStream) throws IOException { - InputStream headerStream= null; - try { - headerStream= this.getClass().getResourceAsStream(EXCEL_HEADER_FILE); + try (InputStream headerStream= this.getClass().getResourceAsStream(EXCEL_HEADER_FILE)) { int c; while ((c= headerStream.read()) != -1) { outputStream.write(c); @@ -102,10 +101,6 @@ public class ExcelExporter implements ILayerExporter { } catch (final Exception e) { WaLTablePlugin.log(new Status(IStatus.ERROR, WaLTablePlugin.BUNDLE_ID, "Excel Exporter failed: " + e.getMessage(), e)); //$NON-NLS-1$ - } finally { - if (headerStream != null) { - headerStream.close(); - } } } @@ -125,11 +120,12 @@ public class ExcelExporter implements ILayerExporter { } @Override - public void exportCell(final OutputStream outputStream, final Object exportDisplayValue, final ILayerCell cell, final IConfigRegistry configRegistry) throws IOException { - final CellStyleProxy cellStyle= new CellStyleProxy(configRegistry, DisplayMode.NORMAL, cell.getConfigLabels().getLabels()); - final Color fg= cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR); - final Color bg= cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR); - final Font font= cellStyle.getAttributeValue(CellStyleAttributes.FONT); + public void exportCell(final OutputStream outputStream, final Object exportDisplayValue, final LayerCell cell, final ConfigRegistry configRegistry) throws IOException { + final var cellStyle= new RegistryStyle(configRegistry, CellConfigAttributes.CELL_STYLE, + DisplayMode.NORMAL, cell.getLabels().getLabels() ); + final Color fg= cellStyle.getAttributeValue(CellStyling.FOREGROUND_COLOR); + final Color bg= cellStyle.getAttributeValue(CellStyling.BACKGROUND_COLOR); + final Font font= cellStyle.getAttributeValue(CellStyling.FONT); String htmlAttributes= String.format("style='color: %s; background-color: %s; %s;'", //$NON-NLS-1$ getColorInCSSFormat(fg), diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/excelExportHeader.txt b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/excelExportHeader.txt index f92e23a2..f92e23a2 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/excel/excelExportHeader.txt +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/excel/excelExportHeader.txt diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/action/ExportAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ui/action/ExportAction.java index 6edd3ec6..6cae1c51 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/export/action/ExportAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/export/ui/action/ExportAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.export.action; +package org.eclipse.statet.ecommons.waltable.export.ui.action; import org.eclipse.swt.events.KeyEvent; @@ -24,7 +24,7 @@ public class ExportAction implements IKeyAction { @Override public void run(final NatTable natTable, final KeyEvent event) { - natTable.doCommand(new ExportCommand(natTable.getConfigRegistry(), natTable.getShell())); + natTable.doCommand(new ExportCommand(natTable.getStyleRegistry(), natTable.getShell())); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeCellPositionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeCellPositionCommand.java index d6827d49..367d8ffb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeCellPositionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeCellPositionCommand.java @@ -14,8 +14,8 @@ package org.eclipse.statet.ecommons.waltable.freeze; import org.eclipse.statet.ecommons.waltable.command.AbstractPositionCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** @@ -45,7 +45,7 @@ public class FreezeCellPositionCommand extends AbstractPositionCommand implement * @param rowPosition The row position that will be the bottom * row in the frozen part. */ - public FreezeCellPositionCommand(final ILayer layer, final long columnPosition, final long rowPosition) { + public FreezeCellPositionCommand(final Layer layer, final long columnPosition, final long rowPosition) { this(layer, columnPosition, rowPosition, false); } @@ -61,7 +61,7 @@ public class FreezeCellPositionCommand extends AbstractPositionCommand implement * @param toggle whether this command should toggle the frozen state between * frozen and unfrozen, or if it should always result in a frozen state. */ - public FreezeCellPositionCommand(final ILayer layer, final long columnPosition, final long rowPosition, final boolean toggle) { + public FreezeCellPositionCommand(final Layer layer, final long columnPosition, final long rowPosition, final boolean toggle) { this(layer, columnPosition, rowPosition, toggle, false); } @@ -78,7 +78,7 @@ public class FreezeCellPositionCommand extends AbstractPositionCommand implement * @param overrideFreeze whether this command should override a current frozen state * or if it should be skipped if a frozen state is already applied. */ - public FreezeCellPositionCommand(final ILayer layer, final long columnPosition, final long rowPosition, final boolean toggle, final boolean overrideFreeze) { + public FreezeCellPositionCommand(final Layer layer, final long columnPosition, final long rowPosition, final boolean toggle, final boolean overrideFreeze) { super(layer, columnPosition, rowPosition); this.toggle= toggle; this.overrideFreeze= overrideFreeze; @@ -106,7 +106,7 @@ public class FreezeCellPositionCommand extends AbstractPositionCommand implement } @Override - public ILayerCommand cloneCommand() { + public LayerCommand cloneCommand() { return new FreezeCellPositionCommand(this); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeColumnStrategy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeColumnStrategy.java index 53fa55b6..53fa55b6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeColumnStrategy.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeColumnStrategy.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeCommandHandler.java index 98d099aa..80cede81 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeCommandHandler.java @@ -13,12 +13,12 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportLayer; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayer; public class FreezeCommandHandler extends AbstractLayerCommandHandler<IFreezeCommand> { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeDimPositionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeDimPositionCommand.java index 29ddaf20..56e4cba6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeDimPositionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeDimPositionCommand.java @@ -13,9 +13,9 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; /** @@ -43,7 +43,7 @@ public class FreezeDimPositionCommand extends AbstractDimPositionCommand impleme * @param position The column/row position that will be the right most * column/row in the frozen part. */ - public FreezeDimPositionCommand(final ILayerDim layerDim, final long position) { + public FreezeDimPositionCommand(final LayerDim layerDim, final long position) { this(layerDim, position, false); } @@ -57,7 +57,7 @@ public class FreezeDimPositionCommand extends AbstractDimPositionCommand impleme * @param toggle whether this command should toggle the frozen state between * frozen and unfrozen, or if it should always result in a frozen state. */ - public FreezeDimPositionCommand(final ILayerDim layerDim, final long position, + public FreezeDimPositionCommand(final LayerDim layerDim, final long position, final boolean toggle) { this(layerDim, position, toggle, false); } @@ -73,7 +73,7 @@ public class FreezeDimPositionCommand extends AbstractDimPositionCommand impleme * @param overrideFreeze whether this command should override a current frozen state * or if it should be skipped if a frozen state is already applied. */ - public FreezeDimPositionCommand(final ILayerDim layerDim, final long position, + public FreezeDimPositionCommand(final LayerDim layerDim, final long position, final boolean toggle, final boolean overrideFreeze) { super(layerDim, position); @@ -104,7 +104,7 @@ public class FreezeDimPositionCommand extends AbstractDimPositionCommand impleme } @Override - public ILayerCommand cloneCommand() { + public LayerCommand cloneCommand() { return new FreezeDimPositionCommand(this); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java new file mode 100644 index 00000000..0389d3e6 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeEventHandler.java @@ -0,0 +1,134 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.freeze; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.Collection; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerListener; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff; + + +@NonNullByDefault +public class FreezeEventHandler implements LayerListener { + + + private final FreezeLayer freezeLayer; + + + public FreezeEventHandler(final FreezeLayer freezeLayer) { + this.freezeLayer= freezeLayer; + } + + + @Override + public void handleLayerEvent(final LayerEvent event) { + if (event instanceof StructuralChangeEvent) { + final var changeEvent= (StructuralChangeEvent)event; + final PositionCoordinate topLeftPosition= this.freezeLayer.getTopLeftPosition(); + final PositionCoordinate bottomRightPosition= this.freezeLayer.getBottomRightPosition(); + + // The handling of diffs have to be in sync with ViewportLayerDim#handleStructuralChanges + final Collection<StructuralDiff> columnDiffs= changeEvent.getDiffs(HORIZONTAL); + if (columnDiffs != null) { + int leftOffset= 0; + int rightOffset= 0; + int freezeMove= 0; // 0= unset, 1 == true, -1 == false + + for (final StructuralDiff diff : columnDiffs) { + final long start= diff.getBeforePositionRange().start; + switch (diff.getDiffType()) { + case ADD: + if (start < topLeftPosition.columnPosition) { + leftOffset+= diff.getAfterPositionRange().size(); + } + if (start <= bottomRightPosition.columnPosition + || (freezeMove == 1 && start == bottomRightPosition.columnPosition + 1) ) { + rightOffset+= diff.getAfterPositionRange().size(); + } + continue; + case DELETE: + if (start < topLeftPosition.columnPosition) { + leftOffset-= Math.min(diff.getBeforePositionRange().end, topLeftPosition.columnPosition + 1) - start; + } + if (start <= bottomRightPosition.columnPosition) { + rightOffset-= Math.min(diff.getBeforePositionRange().end, bottomRightPosition.columnPosition + 1) - start; + if (freezeMove == 0) { + freezeMove= 1; + } + } + else { + freezeMove= -1; + } + continue; + default: + continue; + } + } + + topLeftPosition.columnPosition+= leftOffset; + bottomRightPosition.columnPosition+= rightOffset; + } + + final Collection<StructuralDiff> rowDiffs= changeEvent.getDiffs(VERTICAL); + if (rowDiffs != null) { + int leftOffset= 0; + int rightOffset= 0; + int freezeMove= 0; // 0= unset, 1 == true, -1 == false + + for (final StructuralDiff diff : rowDiffs) { + final long start= diff.getBeforePositionRange().start; + switch (diff.getDiffType()) { + case ADD: + if (start < topLeftPosition.rowPosition) { + leftOffset+= diff.getAfterPositionRange().size(); + } + if (start <= bottomRightPosition.rowPosition + || (freezeMove == 1 && start == bottomRightPosition.rowPosition + 1) ) { + rightOffset+= diff.getAfterPositionRange().size(); + } + continue; + case DELETE: + if (start < topLeftPosition.rowPosition) { + leftOffset-= Math.min(diff.getBeforePositionRange().end, topLeftPosition.rowPosition + 1) - start; + } + if (start <= bottomRightPosition.rowPosition) { + rightOffset-= Math.min(diff.getBeforePositionRange().end, bottomRightPosition.rowPosition + 1) - start; + if (freezeMove == 0) { + freezeMove= 1; + } + } + else { + freezeMove= -1; + } + continue; + default: + continue; + } + } + + topLeftPosition.rowPosition+= leftOffset; + bottomRightPosition.rowPosition+= rightOffset; + } + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeHelper.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeHelper.java index 055b5f93..3dca1601 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeHelper.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeHelper.java @@ -13,13 +13,15 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; import org.eclipse.statet.ecommons.waltable.freeze.FreezeLayer.Dim; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportLayer; +import org.eclipse.statet.ecommons.waltable.freeze.core.FreezeEvent; +import org.eclipse.statet.ecommons.waltable.freeze.core.UnfreezeEvent; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayer; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeLayer.java index 1557b6c3..c603fda3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeLayer.java @@ -13,19 +13,22 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.TransformLayer; -import org.eclipse.statet.ecommons.waltable.layer.TransformLayerDim; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.TransformLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.TransformLayerDim; -public class FreezeLayer extends TransformLayer { +@NonNullByDefault +public class FreezeLayer extends TransformLayer<TransformLayerDim<FreezeLayer>> { public static final String PERSISTENCE_TOP_LEFT_POSITION= ".freezeTopLeftPosition"; //$NON-NLS-1$ @@ -39,7 +42,7 @@ public class FreezeLayer extends TransformLayer { private long endPosition; - public Dim(final FreezeLayer layer, final ILayerDim underlyingDim) { + public Dim(final FreezeLayer layer, final LayerDim underlyingDim) { super(layer, underlyingDim); } @@ -118,30 +121,28 @@ public class FreezeLayer extends TransformLayer { } - public FreezeLayer(final ILayer underlyingLayer) { + public FreezeLayer(final Layer underlyingLayer) { super(underlyingLayer); + init(); + registerEventHandler(new FreezeEventHandler(this)); } - @Override - protected void initDims() { - final ILayer underlying= getUnderlyingLayer(); - if (underlying == null) { - return; - } - setDim(new Dim(this, underlying.getDim(HORIZONTAL))); - setDim(new Dim(this, underlying.getDim(VERTICAL))); + protected Dim createDim(final Orientation orientation) { + final Layer underlyingLayer= getUnderlyingLayer(); + return new Dim(this, underlyingLayer.getDim(orientation)); } + final Dim get(final Orientation orientation) { - return (Dim) getDim(orientation); + return (Dim)getDim(orientation); } public boolean isFrozen() { - return getColumnCount() > 0 || getRowCount() > 0; + return (getColumnCount() > 0 || getRowCount() > 0); } public PositionCoordinate getTopLeftPosition() { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezePositionStrategy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezePositionStrategy.java index c8cbd6b5..c8cbd6b5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezePositionStrategy.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezePositionStrategy.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeRowStrategy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeRowStrategy.java index 51c03ec8..51c03ec8 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeRowStrategy.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeRowStrategy.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionCommand.java index 849c31d6..4c04fc9f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionCommand.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** @@ -79,7 +79,7 @@ public class FreezeSelectionCommand implements IFreezeCommand { } @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionStrategy.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionStrategy.java index 3e79d716..04fe2516 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionStrategy.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/FreezeSelectionStrategy.java @@ -13,14 +13,13 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.viewport.IViewportDim; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportLayer; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayer; public class FreezeSelectionStrategy implements IFreezeCoordinatesProvider { @@ -50,9 +49,9 @@ public class FreezeSelectionStrategy implements IFreezeCoordinatesProvider { } private long checkPosition(final Orientation orientation, final long maxPosition) { - final IViewportDim dim= this.viewportLayer.getDim(orientation); - if (dim.getSize() > 0) { - final long position= dim.getOriginPosition(); + final var viewportDim= this.viewportLayer.getDim(orientation); + if (viewportDim.getSize() > 0) { + final long position= viewportDim.getOriginPosition(); if (position < maxPosition) { return position; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCommand.java index 03888b4e..d080322e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCommand.java @@ -13,15 +13,15 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; /** * Interface to mark commands as freeze related commands that are handled by - * the {@link FreezeCommandHandler} or any command handler that handles {@link ILayerCommand}s + * the {@link FreezeCommandHandler} or any command handler that handles {@link LayerCommand}s * of this type. */ -public interface IFreezeCommand extends ILayerCommand { +public interface IFreezeCommand extends LayerCommand { /** * Indicates whether this command should toggle the frozen state between diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeConfigAttributes.java index debdc2c1..f8cf34da 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeConfigAttributes.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeConfigAttributes.java @@ -15,7 +15,7 @@ package org.eclipse.statet.ecommons.waltable.freeze; import org.eclipse.swt.graphics.Color; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; public interface IFreezeConfigAttributes { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCoordinatesProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCoordinatesProvider.java index 86d57f67..86d57f67 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCoordinatesProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/IFreezeCoordinatesProvider.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/UnFreezeGridCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/UnFreezeGridCommand.java index ec871ce2..5f832399 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/UnFreezeGridCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/UnFreezeGridCommand.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.freeze; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/CompositeFreezeLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/CompositeFreezeLayer.java new file mode 100644 index 00000000..c861ee6f --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/CompositeFreezeLayer.java @@ -0,0 +1,169 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.freeze.core; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.Map; +import java.util.StringTokenizer; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.freeze.FreezeCommandHandler; +import org.eclipse.statet.ecommons.waltable.freeze.FreezeHelper; +import org.eclipse.statet.ecommons.waltable.freeze.FreezeLayer; +import org.eclipse.statet.ecommons.waltable.freeze.swt.CompositeFreezeLayerPainter; +import org.eclipse.statet.ecommons.waltable.freeze.ui.action.DefaultFreezeGridBindings; +import org.eclipse.statet.ecommons.waltable.grid.core.ClientAreaResizeCommand; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.DimensionallyDependentLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayer; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportSelectDimPositionsCommandHandler; + + +@NonNullByDefault +public class CompositeFreezeLayer extends CompositeLayer { + + + protected final FreezeLayer freezeLayer; + + protected final ViewportLayer viewportLayer; + + protected final SelectionLayer selectionLayer; + + + public CompositeFreezeLayer(final FreezeLayer freezeLayer, final ViewportLayer viewportLayer, + final SelectionLayer selectionLayer) { + this(freezeLayer, viewportLayer, selectionLayer, true); + } + + public CompositeFreezeLayer(final FreezeLayer freezeLayer, final ViewportLayer viewportLayer, + final SelectionLayer selectionLayer, + final boolean useDefaultConfiguration) { + super(2, 2); + this.freezeLayer= freezeLayer; + this.viewportLayer= viewportLayer; + this.selectionLayer= selectionLayer; + + setChildLayer("FROZEN_REGION", freezeLayer, 0, 0); //$NON-NLS-1$ + setChildLayer("FROZEN_ROW_REGION", new DimensionallyDependentLayer( //$NON-NLS-1$ + viewportLayer.getScrollableLayer(), viewportLayer, freezeLayer), + 1, 0); + setChildLayer("FROZEN_COLUMN_REGION", new DimensionallyDependentLayer( //$NON-NLS-1$ + viewportLayer.getScrollableLayer(), freezeLayer, viewportLayer), + 0, 1); + setChildLayer("NONFROZEN_REGION", viewportLayer, 1, 1); //$NON-NLS-1$ + + registerCommandHandlers(); + + if (useDefaultConfiguration) { + addConfiguration(new DefaultFreezeGridBindings()); + } + } + + + @Override + protected LayerPainter createPainter() { + return new CompositeFreezeLayerPainter(this); + } + + + public boolean isFrozen() { + return this.freezeLayer.isFrozen(); + } + + @Override + protected void registerCommandHandlers() { + registerCommandHandler(new FreezeCommandHandler(this.freezeLayer, this.viewportLayer, this.selectionLayer)); + + final AbstractLayer frozenRowLayer= (AbstractLayer) getChildLayerByLayoutCoordinate(1, 0); + frozenRowLayer.registerCommandHandler(new ViewportSelectDimPositionsCommandHandler( + frozenRowLayer, VERTICAL )); + + final AbstractLayer frozenColumnLayer= (AbstractLayer) getChildLayerByLayoutCoordinate(0, 1); + frozenColumnLayer.registerCommandHandler(new ViewportSelectDimPositionsCommandHandler( + frozenRowLayer, HORIZONTAL )); + } + + + @Override + public boolean doCommand(final LayerCommand command) { + //if this layer should handle a ClientAreaResizeCommand we have to ensure that + //it is only called on the ViewportLayer, as otherwise an undefined behaviour + //could occur because the ViewportLayer isn't informed about potential refreshes + if (command instanceof ClientAreaResizeCommand) { + this.viewportLayer.doCommand(command); + } + return super.doCommand(command); + } + + + // Persistence + + @Override + public void saveState(final String prefix, final Map<String, String> properties) { + PositionCoordinate coord= this.freezeLayer.getTopLeftPosition(); + properties.put(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION, + coord.columnPosition + Persistable.VALUE_SEPARATOR + coord.rowPosition); + + coord= this.freezeLayer.getBottomRightPosition(); + properties.put(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION, + coord.columnPosition + Persistable.VALUE_SEPARATOR + coord.rowPosition); + + super.saveState(prefix, properties); + } + + @Override + public void loadState(final String prefix, final Map<String, String> properties) { + String property= properties.get(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION); + PositionCoordinate topLeftPosition= null; + if (property != null) { + final StringTokenizer tok= new StringTokenizer(property, Persistable.VALUE_SEPARATOR); + final String columnPosition= tok.nextToken(); + final String rowPosition= tok.nextToken(); + topLeftPosition= new PositionCoordinate(this.freezeLayer, + Long.parseLong(columnPosition), Long.parseLong(rowPosition)); + } + + property= properties.get(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION); + PositionCoordinate bottomRightPosition= null; + if (property != null) { + final StringTokenizer tok= new StringTokenizer(property, Persistable.VALUE_SEPARATOR); + final String columnPosition= tok.nextToken(); + final String rowPosition= tok.nextToken(); + bottomRightPosition= new PositionCoordinate(this.freezeLayer, + Long.parseLong(columnPosition), Long.parseLong(rowPosition)); + } + + //only restore a freeze state if there is one persisted + if (topLeftPosition != null && bottomRightPosition != null) { + if (topLeftPosition.columnPosition == -1 && topLeftPosition.rowPosition == -1 + && bottomRightPosition.columnPosition == -1 && bottomRightPosition.rowPosition == -1) { + FreezeHelper.unfreeze(this.freezeLayer, this.viewportLayer); + } else { + FreezeHelper.freeze(this.freezeLayer, this.viewportLayer, topLeftPosition, bottomRightPosition); + } + } + + super.loadState(prefix, properties); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/FreezeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/FreezeEvent.java new file mode 100644 index 00000000..ee8c3b03 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/FreezeEvent.java @@ -0,0 +1,41 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.freeze.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; + + +@NonNullByDefault +public class FreezeEvent extends GeneralStructuralChangeEvent { + + + public FreezeEvent(final Layer layer) { + super(layer); + } + + @Override + public @Nullable FreezeEvent toLayer(final Layer targetLayer) { + if (targetLayer == getLayer()) { + return this; + } + + return new FreezeEvent(targetLayer); + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/UnfreezeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/UnfreezeEvent.java new file mode 100644 index 00000000..3ba152f2 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/core/UnfreezeEvent.java @@ -0,0 +1,41 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.freeze.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; + + +@NonNullByDefault +public class UnfreezeEvent extends GeneralStructuralChangeEvent { + + + public UnfreezeEvent(final Layer layer) { + super(layer); + } + + @Override + public @Nullable UnfreezeEvent toLayer(final Layer targetLayer) { + if (targetLayer == getLayer()) { + return this; + } + + return new UnfreezeEvent(targetLayer); + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/swt/CompositeFreezeLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/swt/CompositeFreezeLayerPainter.java new file mode 100644 index 00000000..c2e3208a --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/swt/CompositeFreezeLayerPainter.java @@ -0,0 +1,74 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.freeze.swt; + +import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer.CompositeLayerPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.freeze.IFreezeConfigAttributes; +import org.eclipse.statet.ecommons.waltable.freeze.core.CompositeFreezeLayer; +import org.eclipse.statet.ecommons.waltable.util.GUIHelper; + + +@NonNullByDefault +public class CompositeFreezeLayerPainter extends CompositeLayerPainter { + + + public CompositeFreezeLayerPainter(final CompositeFreezeLayer layer) { + super(layer); + } + + + protected Layer getFreezeLayer() { + return this.layer.getChildLayerByLayoutCoordinate(0, 0); + } + + @Override + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, + final Rectangle rectangle, final ConfigRegistry configRegistry) { + super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); + final var freezeLayer= getFreezeLayer(); + + Color separatorColor= configRegistry.getAttribute(IFreezeConfigAttributes.SEPARATOR_COLOR, DisplayMode.NORMAL); + if (separatorColor == null) { + separatorColor= GUIHelper.COLOR_BLUE; + } + + gc.setClipping(rectangle); + final Color oldFg= gc.getForeground(); + gc.setForeground(separatorColor); + final long freezeWidth= freezeLayer.getWidth() - 1; + if (freezeWidth > 0) { + gc.drawLine(safe(xOffset + freezeWidth), yOffset, + safe(xOffset + freezeWidth), safe(yOffset + this.layer.getHeight() - 1)); + } + final long freezeHeight= freezeLayer.getHeight() - 1; + if (freezeHeight > 0) { + gc.drawLine(xOffset, safe(yOffset + freezeHeight), + safe(xOffset + this.layer.getWidth() - 1), safe(yOffset + freezeHeight)); + } + gc.setForeground(oldFg); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/config/DefaultFreezeGridBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/DefaultFreezeGridBindings.java index e92a1785..e54df16c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/config/DefaultFreezeGridBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/DefaultFreezeGridBindings.java @@ -11,24 +11,31 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.freeze.config; +package org.eclipse.statet.ecommons.waltable.freeze.ui.action; import org.eclipse.swt.SWT; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; -import org.eclipse.statet.ecommons.waltable.freeze.action.FreezeGridAction; -import org.eclipse.statet.ecommons.waltable.freeze.action.UnFreezeGridAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; +@NonNullByDefault public class DefaultFreezeGridBindings extends AbstractUiBindingConfiguration { + public DefaultFreezeGridBindings() { + } + + @Override public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) { - uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1 | SWT.MOD2, 'f'), new FreezeGridAction()); - uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1 | SWT.MOD2, 'u'), new UnFreezeGridAction()); + uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1 | SWT.MOD2, 'f'), + new FreezeGridAction() ); + uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.MOD1 | SWT.MOD2, 'u'), + new UnFreezeGridAction() ); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/action/FreezeGridAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/FreezeGridAction.java index 829b64cd..fdaccc3d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/action/FreezeGridAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/FreezeGridAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.freeze.action; +package org.eclipse.statet.ecommons.waltable.freeze.ui.action; import org.eclipse.swt.events.KeyEvent; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/action/UnFreezeGridAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/UnFreezeGridAction.java index 92abca65..670f22ae 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/freeze/action/UnFreezeGridAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/freeze/ui/action/UnFreezeGridAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.freeze.action; +package org.eclipse.statet.ecommons.waltable.freeze.ui.action; import org.eclipse.swt.events.KeyEvent; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/LayerPrinter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/LayerPrinter.java index f08f9e7f..2253e55a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/LayerPrinter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/LayerPrinter.java @@ -19,6 +19,7 @@ import java.util.Date; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.printing.PrintDialog; import org.eclipse.swt.printing.Printer; @@ -27,11 +28,11 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.statet.ecommons.waltable.Messages; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; -import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.ClientAreaProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; /** @@ -41,9 +42,9 @@ import org.eclipse.statet.ecommons.waltable.ui.IClientAreaProvider; */ public class LayerPrinter { - private final IConfigRegistry configRegistry; - private final ILayer layer; - private final IClientAreaProvider originalClientAreaProvider; + private final ConfigRegistry configRegistry; + private final Layer layer; + private final ClientAreaProvider originalClientAreaProvider; public static final int FOOTER_HEIGHT_IN_PRINTER_DPI= 300; final SimpleDateFormat dateFormat= new SimpleDateFormat("EEE, d MMM yyyy HH:mm a"); //$NON-NLS-1$ @@ -56,7 +57,7 @@ public class LayerPrinter { * the CompositeLayer, otherwise the ViewportLayer is a good choice. * @param configRegistry The ConfigRegistry needed for rendering to the print GC. */ - public LayerPrinter(final ILayer layer, final IConfigRegistry configRegistry) { + public LayerPrinter(final Layer layer, final ConfigRegistry configRegistry) { this.layer= layer; this.configRegistry= configRegistry; this.originalClientAreaProvider= layer.getClientAreaProvider(); @@ -176,10 +177,10 @@ public class LayerPrinter { */ private LRectangle computePrintArea(final Printer printer) { // Get the printable area - final org.eclipse.swt.graphics.Rectangle rect= printer.getClientArea(); + final Rectangle rect= printer.getClientArea(); // Compute the trim - final org.eclipse.swt.graphics.Rectangle trim= printer.computeTrim(0, 0, 0, 0); + final Rectangle trim= printer.computeTrim(0, 0, 0, 0); // Get the printer's DPI final Point dpi= printer.getDPI(); @@ -251,7 +252,7 @@ public class LayerPrinter { for (int horizontalPageNumber= 0; horizontalPageNumber < pageCount.x; horizontalPageNumber++) { // Calculate bounds for the next page - final org.eclipse.swt.graphics.Rectangle printBounds= SWTUtil.toSWT(new LRectangle( + final Rectangle printBounds= SwtUtils.toSWT(new LRectangle( (printerClientArea.width / scaleFactor.x) * horizontalPageNumber, ((printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y) * verticalPageNumber, printerClientArea.width / scaleFactor.x, @@ -306,7 +307,7 @@ public class LayerPrinter { else { final LRectangle fullLayerSize= getTotalArea(); - LayerPrinter.this.layer.setClientAreaProvider(new IClientAreaProvider(){ + LayerPrinter.this.layer.setClientAreaProvider(new ClientAreaProvider(){ @Override public LRectangle getClientArea() { return fullLayerSize; @@ -324,8 +325,9 @@ public class LayerPrinter { * @param gc The print GC to render the layer to. * @param printBounds The bounds of the print page. */ - private void printLayer(final GC gc, final org.eclipse.swt.graphics.Rectangle printBounds) { - LayerPrinter.this.layer.getLayerPainter().paintLayer(LayerPrinter.this.layer, gc, 0, 0, printBounds, LayerPrinter.this.configRegistry); + private void printLayer(final GC gc, final Rectangle printBounds) { + final var layerPainter= LayerPrinter.this.layer.getLayerPainter(); + layerPainter.paintLayer(LayerPrinter.this.layer, gc, 0, 0, printBounds, LayerPrinter.this.configRegistry); } /** @@ -334,7 +336,7 @@ public class LayerPrinter { * @param totalPageCount The total number of pages that are printed. * @param printBounds The bounds of the print page. */ - private void printFooter(final GC gc, final int totalPageCount, final org.eclipse.swt.graphics.Rectangle printBounds) { + private void printFooter(final GC gc, final int totalPageCount, final Rectangle printBounds) { gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintCommand.java index 8073158c..4bfb2df1 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintCommand.java @@ -15,21 +15,21 @@ package org.eclipse.statet.ecommons.waltable.print; import org.eclipse.swt.widgets.Shell; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; public class PrintCommand extends AbstractContextFreeCommand { - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; private final Shell shell; - public PrintCommand(final IConfigRegistry configRegistry, final Shell shell) { + public PrintCommand(final ConfigRegistry configRegistry, final Shell shell) { this.configRegistry= configRegistry; this.shell= shell; } - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintCommandHandler.java index 18c78afd..6c17c27a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintCommandHandler.java @@ -13,35 +13,42 @@ package org.eclipse.statet.ecommons.waltable.print; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** * ILayerCommandHandler for handling the PrintCommand. * Simply delegates to the */ -public class PrintCommandHandler extends AbstractLayerCommandHandler<PrintCommand> { - - private final ILayer layer; - +@NonNullByDefault +public class PrintCommandHandler implements LayerCommandHandler<PrintCommand> { + + + private final Layer layer; + + /** * @param layer The layer that should be printed. * Usually the top most layer to print, e.g. the GridLayer. */ - public PrintCommandHandler(final ILayer layer) { + public PrintCommandHandler(final Layer layer) { this.layer= layer; } - - @Override - public boolean doCommand(final PrintCommand command) { - new LayerPrinter(this.layer, command.getConfigRegistry()).print(command.getShell()); - return true; - } - + + @Override public Class<PrintCommand> getCommandClass() { return PrintCommand.class; } - + + @Override + public boolean executeCommand(final PrintCommand command) { + new LayerPrinter(this.layer, command.getConfigRegistry()) + .print(command.getShell()); + return true; + } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintEntireGridCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintEntireGridCommand.java index 3be82350..8ffe399b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/PrintEntireGridCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/PrintEntireGridCommand.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.print; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/TurnViewportOffCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/TurnViewportOffCommand.java index 1f6358f7..413ff349 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/TurnViewportOffCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/TurnViewportOffCommand.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.print; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/TurnViewportOnCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/TurnViewportOnCommand.java index 1453a686..fd7d51cd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/TurnViewportOnCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/TurnViewportOnCommand.java @@ -13,7 +13,7 @@ package org.eclipse.statet.ecommons.waltable.print; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/config/DefaultPrintBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/config/DefaultPrintBindings.java index c302f787..15623ea2 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/config/DefaultPrintBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/config/DefaultPrintBindings.java @@ -16,7 +16,7 @@ package org.eclipse.statet.ecommons.waltable.print.config; import org.eclipse.swt.SWT; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; -import org.eclipse.statet.ecommons.waltable.print.action.PrintAction; +import org.eclipse.statet.ecommons.waltable.print.ui.action.PrintAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/action/PrintAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/ui/action/PrintAction.java index d14e8a83..3de0ab6a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/print/action/PrintAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/print/ui/action/PrintAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.print.action; +package org.eclipse.statet.ecommons.waltable.print.ui.action; import org.eclipse.swt.events.KeyEvent; @@ -27,7 +27,7 @@ public class PrintAction implements IKeyAction { @Override public void run(final NatTable natTable, final KeyEvent event) { - natTable.doCommand(new PrintCommand(natTable.getConfigRegistry(), natTable.getShell())); + natTable.doCommand(new PrintCommand(natTable.getStyleRegistry(), natTable.getShell())); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/ITickUpdateHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/ITickUpdateHandler.java index c25e9d12..c25e9d12 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/ITickUpdateHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/ITickUpdateHandler.java diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommand.java index c9f7ec37..bd7ee867 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommand.java @@ -13,9 +13,9 @@ package org.eclipse.statet.ecommons.waltable.tickupdate; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** @@ -24,17 +24,17 @@ import org.eclipse.statet.ecommons.waltable.layer.ILayer; * SelectionLayer and the corresponding {@link TickUpdateCommandHandler} * is registered. */ -public class TickUpdateCommand implements ILayerCommand { +public class TickUpdateCommand implements LayerCommand { /** - * The {@link IConfigRegistry} of the current NatTable instance this + * The {@link ConfigRegistry} of the current NatTable instance this * command is executed in. Needed to determine several configurations * on handling this command by its handler. * As the command handler is not aware of the NatTable instance it - * is running in, and there is no kind of context, the {@link IConfigRegistry} + * is running in, and there is no kind of context, the {@link ConfigRegistry} * needs to be transported. */ - private final IConfigRegistry configRegistry; + private final ConfigRegistry configRegistry; /** * Flag to determine whether the current value in the data model * should be incremented or decremented. @@ -42,16 +42,16 @@ public class TickUpdateCommand implements ILayerCommand { private final boolean increment; /** - * @param configRegistry The {@link IConfigRegistry} of the current NatTable instance this + * @param configRegistry The {@link ConfigRegistry} of the current NatTable instance this * command is executed in. Needed to determine several configurations * on handling this command by its handler. * As the command handler is not aware of the NatTable instance it - * is running in, and there is no kind of context, the {@link IConfigRegistry} + * is running in, and there is no kind of context, the {@link ConfigRegistry} * needs to be transported. * @param increment Flag to determine whether the current value in the data model * should be incremented or decremented. */ - public TickUpdateCommand(final IConfigRegistry configRegistry, final boolean increment) { + public TickUpdateCommand(final ConfigRegistry configRegistry, final boolean increment) { this.configRegistry= configRegistry; this.increment= increment; } @@ -71,20 +71,20 @@ public class TickUpdateCommand implements ILayerCommand { } @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { // No op. return true; } /** - * @return The {@link IConfigRegistry} of the current NatTable instance this + * @return The {@link ConfigRegistry} of the current NatTable instance this * command is executed in. Needed to determine several configurations * on handling this command by its handler. * As the command handler is not aware of the NatTable instance it - * is running in, and there is no kind of context, the {@link IConfigRegistry} + * is running in, and there is no kind of context, the {@link ConfigRegistry} * needs to be transported. */ - public IConfigRegistry getConfigRegistry() { + public ConfigRegistry getConfigRegistry() { return this.configRegistry; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommandHandler.java index 90fc070f..f75d76cc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateCommandHandler.java @@ -18,17 +18,17 @@ import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IEditableRule; import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; import org.eclipse.statet.ecommons.waltable.data.validate.IDataValidator; import org.eclipse.statet.ecommons.waltable.edit.EditConfigAttributes; import org.eclipse.statet.ecommons.waltable.edit.EditUtils; import org.eclipse.statet.ecommons.waltable.edit.UpdateDataCommand; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; @@ -55,7 +55,7 @@ public class TickUpdateCommandHandler extends AbstractLayerCommandHandler<TickUp @Override public boolean doCommand(final TickUpdateCommand command) { final List<PositionCoordinate> selectedPositions= this.selectionLayer.getSelectedCellPositions(); - final IConfigRegistry configRegistry= command.getConfigRegistry(); + final ConfigRegistry configRegistry= command.getConfigRegistry(); // Tick update for multiple cells in selection if (selectedPositions.size() > 1) { @@ -84,20 +84,20 @@ public class TickUpdateCommandHandler extends AbstractLayerCommandHandler<TickUp * should be executed */ private void updateSingleCell(final TickUpdateCommand command, final PositionCoordinate selectedPosition) { - final ILayerCell cell= this.selectionLayer.getCellByPosition( + final LayerCell cell= this.selectionLayer.getCellByPosition( selectedPosition.columnPosition, selectedPosition.rowPosition); - final IConfigRegistry configRegistry= command.getConfigRegistry(); + final ConfigRegistry configRegistry= command.getConfigRegistry(); - final IEditableRule editableRule= configRegistry.getConfigAttribute( + final IEditableRule editableRule= configRegistry.getAttribute( EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); - final IDataValidator validator= configRegistry.getConfigAttribute( + final IDataValidator validator= configRegistry.getAttribute( EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); if (editableRule.isEditable(cell, configRegistry)) { //process the tick update @@ -131,11 +131,11 @@ public class TickUpdateCommandHandler extends AbstractLayerCommandHandler<TickUp * @param cell The cell on which the command should be processed * @return The processed value after the command was executed on the current cell value */ - private Object getNewCellValue(final TickUpdateCommand command, final ILayerCell cell) { - final ITickUpdateHandler tickUpdateHandler= command.getConfigRegistry().getConfigAttribute( + private Object getNewCellValue(final TickUpdateCommand command, final LayerCell cell) { + final ITickUpdateHandler tickUpdateHandler= command.getConfigRegistry().getAttribute( TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, - cell.getConfigLabels().getLabels()); + cell.getLabels().getLabels()); final Object dataValue= cell.getDataValue(0, null); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateConfigAttributes.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateConfigAttributes.java index b85d35cb..e894e34d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateConfigAttributes.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/TickUpdateConfigAttributes.java @@ -13,8 +13,8 @@ package org.eclipse.statet.ecommons.waltable.tickupdate; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigAttribute; import org.eclipse.statet.ecommons.waltable.edit.gui.TickUpdateCellEditDialog; -import org.eclipse.statet.ecommons.waltable.style.ConfigAttribute; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/config/DefaultTickUpdateConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/config/DefaultTickUpdateConfiguration.java index e5547ee6..04083dbd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/config/DefaultTickUpdateConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/config/DefaultTickUpdateConfiguration.java @@ -16,12 +16,12 @@ package org.eclipse.statet.ecommons.waltable.tickupdate.config; import org.eclipse.swt.SWT; import org.eclipse.statet.ecommons.waltable.config.AbstractLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.ecommons.waltable.tickupdate.ITickUpdateHandler; import org.eclipse.statet.ecommons.waltable.tickupdate.TickUpdateCommandHandler; import org.eclipse.statet.ecommons.waltable.tickupdate.TickUpdateConfigAttributes; -import org.eclipse.statet.ecommons.waltable.tickupdate.action.TickUpdateAction; +import org.eclipse.statet.ecommons.waltable.tickupdate.ui.action.TickUpdateAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; @@ -35,8 +35,8 @@ import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; public class DefaultTickUpdateConfiguration extends AbstractLayerConfiguration<SelectionLayer> { @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute( + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute( TickUpdateConfigAttributes.UPDATE_HANDLER, ITickUpdateHandler.DEFAULT_TICK_UPDATE_HANDLER); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/action/TickUpdateAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/ui/action/TickUpdateAction.java index c225753d..87d4f6f8 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/tickupdate/action/TickUpdateAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcAdditional/org/eclipse/statet/ecommons/waltable/tickupdate/ui/action/TickUpdateAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.tickupdate.action; +package org.eclipse.statet.ecommons.waltable.tickupdate.ui.action; import org.eclipse.swt.events.KeyEvent; @@ -43,7 +43,7 @@ public class TickUpdateAction implements IKeyAction { @Override public void run(final NatTable natTable, final KeyEvent event) { - natTable.doCommand(new TickUpdateCommand(natTable.getConfigRegistry(), this.increment)); + natTable.doCommand(new TickUpdateCommand(natTable.getStyleRegistry(), this.increment)); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/DataLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/DataLayer.java index 19471346..c5917c92 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/DataLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/DataLayer.java @@ -11,51 +11,60 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.data.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import java.util.Properties; +import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.command.StructuralRefreshCommandHandler; -import org.eclipse.statet.ecommons.waltable.command.VisualRefreshCommandHandler; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; import org.eclipse.statet.ecommons.waltable.edit.UpdateDataCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; -import org.eclipse.statet.ecommons.waltable.resize.ColumnResizeEvent; -import org.eclipse.statet.ecommons.waltable.resize.MultiColumnResizeCommandHandler; -import org.eclipse.statet.ecommons.waltable.resize.MultiRowResizeCommandHandler; -import org.eclipse.statet.ecommons.waltable.resize.PositionResizeCommandHandler; -import org.eclipse.statet.ecommons.waltable.resize.RowResizeEvent; +import org.eclipse.statet.ecommons.waltable.refresh.core.StructuralRefreshCommandHandler; +import org.eclipse.statet.ecommons.waltable.refresh.core.VisualRefreshCommandHandler; +import org.eclipse.statet.ecommons.waltable.resize.core.DimResizeEvent; +import org.eclipse.statet.ecommons.waltable.resize.core.MultiColumnResizeCommandHandler; +import org.eclipse.statet.ecommons.waltable.resize.core.MultiRowResizeCommandHandler; +import org.eclipse.statet.ecommons.waltable.resize.core.PositionResizeCommandHandler; /** - * Wraps the {@link IDataProvider}, and serves as the data source for all + * Wraps the {@link DataProvider}, and serves as the data source for all * other layers. Also, tracks the size of the columns and the rows using * {@link SizeConfig} objects. Since this layer sits directly on top of the * data source, at this layer index == position. */ -public class DataLayer extends AbstractLayer implements ILayer { +@NonNullByDefault +public class DataLayer extends AbstractLayer<DataLayerDim<? extends DataLayer>> implements Layer { - protected class DataLayerCell extends LayerCell { + protected class DataLayerCell extends BasicLayerCell { - public DataLayerCell(final ILayerCellDim horizontalDim, final ILayerCellDim verticalDim) { + public DataLayerCell(final LayerCellDim horizontalDim, final LayerCellDim verticalDim) { super(DataLayer.this, horizontalDim, verticalDim); } @Override - public Object getDataValue(final int flags, final IProgressMonitor monitor) { + public @Nullable Object getDataValue(final int flags, + final @Nullable IProgressMonitor monitor) { return DataLayer.this.dataProvider.getDataValue(getColumnPosition(), getRowPosition(), flags, monitor ); } @@ -70,7 +79,7 @@ public class DataLayer extends AbstractLayer implements ILayer { public static final int DEFAULT_ROW_HEIGHT= 20; - protected IDataProvider dataProvider; + protected DataProvider dataProvider; private final long columnIdCat; private final SizeConfig columnWidthConfig; @@ -79,13 +88,13 @@ public class DataLayer extends AbstractLayer implements ILayer { private final SizeConfig rowHeightConfig; - public DataLayer(final IDataProvider dataProvider, final long idCat) { + public DataLayer(final DataProvider dataProvider, final long idCat) { this(dataProvider, idCat, DEFAULT_COLUMN_WIDTH, idCat, DEFAULT_ROW_HEIGHT ); } - public DataLayer(final IDataProvider dataProvider, + public DataLayer(final DataProvider dataProvider, final long columnIdCat, final int defaultColumnWidth, final long rowIdCat, final int defaultRowHeight) { this(dataProvider, @@ -93,57 +102,59 @@ public class DataLayer extends AbstractLayer implements ILayer { rowIdCat, new SizeConfig(defaultRowHeight) ); } - public DataLayer(final IDataProvider dataProvider, + public DataLayer(final DataProvider dataProvider, final long columnIdCat, final SizeConfig columnWidthConfig, final long rowIdCat, final SizeConfig rowHeightConfig) { this.columnIdCat= columnIdCat; this.columnWidthConfig= columnWidthConfig; this.rowIdCat= rowIdCat; this.rowHeightConfig= rowHeightConfig; - initDims(); + + init(); registerCommandHandlers(); setDataProvider(dataProvider); } - @Override - protected void initDims() { - if (this.columnIdCat == 0 || this.rowIdCat == 0) { - return; + protected DataLayerDim<? extends DataLayer> createDim(final Orientation orientation) { + switch (orientation) { + case HORIZONTAL: + return new SizeConfigDim<>(this, HORIZONTAL, this.columnIdCat, this.columnWidthConfig) { + @Override + public long getPositionCount() { + return DataLayer.this.dataProvider.getColumnCount(); + } + }; + case VERTICAL: + return new SizeConfigDim<>(this, VERTICAL, this.rowIdCat, this.rowHeightConfig) { + @Override + public long getPositionCount() { + return DataLayer.this.dataProvider.getRowCount(); + } + }; + default: + throw new IllegalStateException(); } - - setDim(new SizeConfigDim<ILayer>(this, HORIZONTAL, this.columnIdCat, this.columnWidthConfig) { - @Override - public long getPositionCount() { - return DataLayer.this.dataProvider.getColumnCount(); - } - }); - setDim(new SizeConfigDim<ILayer>(this, VERTICAL, this.rowIdCat, this.rowHeightConfig) { - @Override - public long getPositionCount() { - return DataLayer.this.dataProvider.getRowCount(); - } - }); } // Persistence @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { super.saveState(prefix, properties); this.columnWidthConfig.saveState(prefix + PERSISTENCE_KEY_COLUMN_WIDTH, properties); this.rowHeightConfig.saveState(prefix + PERSISTENCE_KEY_ROW_HEIGHT, properties); } @Override - public void loadState(final String prefix, final Properties properties) { + public void loadState(final String prefix, final Map<String, String> properties) { super.loadState(prefix, properties); this.columnWidthConfig.loadState(prefix + PERSISTENCE_KEY_COLUMN_WIDTH, properties); this.rowHeightConfig.loadState(prefix + PERSISTENCE_KEY_ROW_HEIGHT, properties); - fireLayerEvent(new StructuralRefreshEvent(this)); + fireLayerEvent(new GeneralStructuralChangeEvent(this)); } // Configuration @@ -154,23 +165,23 @@ public class DataLayer extends AbstractLayer implements ILayer { registerCommandHandler(new MultiColumnResizeCommandHandler(this)); registerCommandHandler(new MultiRowResizeCommandHandler(this)); registerCommandHandler(new UpdateDataCommandHandler(this)); - registerCommandHandler(new StructuralRefreshCommandHandler()); - registerCommandHandler(new VisualRefreshCommandHandler()); + registerCommandHandler(new StructuralRefreshCommandHandler(this)); + registerCommandHandler(new VisualRefreshCommandHandler(this)); } - public IDataProvider getDataProvider() { + public DataProvider getDataProvider() { return this.dataProvider; } - protected void setDataProvider(final IDataProvider dataProvider) { - if (this.dataProvider instanceof IPersistable) { - unregisterPersistable((IPersistable) this.dataProvider); + protected void setDataProvider(final DataProvider dataProvider) { + if (this.dataProvider instanceof Persistable) { + unregisterPersistable((Persistable) this.dataProvider); } this.dataProvider= dataProvider; - if (dataProvider instanceof IPersistable) { - registerPersistable((IPersistable) dataProvider); + if (dataProvider instanceof Persistable) { + registerPersistable((Persistable) dataProvider); } } @@ -179,7 +190,7 @@ public class DataLayer extends AbstractLayer implements ILayer { public void setColumnWidthByPosition(final long columnPosition, final int width) { this.columnWidthConfig.setSize(columnPosition, width); - fireLayerEvent(new ColumnResizeEvent(this, columnPosition)); + fireLayerEvent(new DimResizeEvent(getDim(HORIZONTAL), new LRange(columnPosition))); } public void setDefaultColumnWidth(final int width) { @@ -206,7 +217,7 @@ public class DataLayer extends AbstractLayer implements ILayer { public void setRowHeightByPosition(final long rowPosition, final int height) { this.rowHeightConfig.setSize(rowPosition, height); - fireLayerEvent(new RowResizeEvent(this, rowPosition)); + fireLayerEvent(new DimResizeEvent(getDim(VERTICAL), new LRange(rowPosition))); } public void setDefaultRowHeight(final int height) { @@ -231,19 +242,19 @@ public class DataLayer extends AbstractLayer implements ILayer { // Cell features @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerDim hDim= getDim(HORIZONTAL); - final ILayerDim vDim= getDim(VERTICAL); + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerDim hDim= getDim(HORIZONTAL); + final LayerDim vDim= getDim(VERTICAL); final long columnId= hDim.getPositionId(columnPosition, columnPosition); final long rowId= vDim.getPositionId(rowPosition, rowPosition); return new DataLayerCell( - new LayerCellDim(HORIZONTAL, columnId, columnPosition), - new LayerCellDim(VERTICAL, rowId, rowPosition) ); + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition), + new BasicLayerCellDim(VERTICAL, rowId, rowPosition) ); } @Override - public ILayer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { + public @Nullable Layer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { return null; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/DataDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/DataLayerDim.java index 1d26c6ac..9965d2e1 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/DataDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/DataLayerDim.java @@ -11,25 +11,33 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.data.core; import java.util.Collection; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PixelOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionId; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PixelOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionId; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; -public abstract class DataDim<TLayer extends ILayer> extends AbstractLayerDim<TLayer> { + +@NonNullByDefault +public abstract class DataLayerDim<TLayer extends Layer> extends AbstractLayerDim<TLayer> { private final long idCat; - public DataDim(final TLayer layer, final Orientation orientation, + public DataLayerDim(final TLayer layer, final Orientation orientation, final long idCat) { super(layer, orientation); @@ -40,7 +48,7 @@ public abstract class DataDim<TLayer extends ILayer> extends AbstractLayerDim<TL @Override public long getPositionId(final long refPosition, final long position) { if (position < 0 || position >= getPositionCount()) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } return (this.idCat | position); } @@ -63,18 +71,18 @@ public abstract class DataDim<TLayer extends ILayer> extends AbstractLayerDim<TL } @Override - public long underlyingToLocalPosition(final ILayerDim sourceUnderlyingDim, final long underlyingPosition) { - return underlyingPosition; + public long underlyingToLocalPosition(final LayerDim sourceUnderlyingDim, final long underlyingPosition) { + throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ } @Override - public List<LRange> underlyingToLocalPositions(final ILayerDim sourceUnderlyingDim, + public List<LRange> underlyingToLocalPositions(final LayerDim sourceUnderlyingDim, final Collection<LRange> underlyingPositions) { - return null; + throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ } @Override - public List<ILayerDim> getUnderlyingDimsByPosition(final long position) { + public @Nullable ImList<LayerDim> getUnderlyingDimsByPosition(final long position) { return null; } @@ -90,7 +98,7 @@ public abstract class DataDim<TLayer extends ILayer> extends AbstractLayerDim<TL long endPixel= getSize(); if (pixel < startPixel || pixel >= endPixel) { - throw PixelOutOfBoundsException.pixel(pixel, getOrientation()); + throw new PixelOutOfBoundsException(pixel, getOrientation()); } long startPosition= 0; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SizeConfig.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SizeConfig.java index c70c772c..20273928 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SizeConfig.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SizeConfig.java @@ -11,15 +11,16 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.data.core; import java.util.Map; -import java.util.Properties; import java.util.StringTokenizer; import java.util.TreeMap; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; /** @@ -29,7 +30,8 @@ import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; * The mixed mode is only working if percentage sizing is enabled globally, and * the fixed sized positions are marked separately. */ -public class SizeConfig implements IPersistable { +@NonNullByDefault +public class SizeConfig implements Persistable { public static final String PERSISTENCE_KEY_DEFAULT_SIZE= ".defaultSize"; //$NON-NLS-1$ @@ -76,7 +78,7 @@ public class SizeConfig implements IPersistable { // Persistence @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { properties.put(prefix + PERSISTENCE_KEY_DEFAULT_SIZE, String.valueOf(this.defaultSize)); saveMap(this.defaultSizeMap, prefix + PERSISTENCE_KEY_DEFAULT_SIZES, properties); saveMap(this.sizeMap, prefix + PERSISTENCE_KEY_SIZES, properties); @@ -84,7 +86,7 @@ public class SizeConfig implements IPersistable { saveMap(this.resizablesMap, prefix + PERSISTENCE_KEY_RESIZABLE_INDEXES, properties); } - private void saveMap(final Map<Long, ?> map, final String key, final Properties properties) { + private void saveMap(final Map<Long, ?> map, final String key, final Map<String, String> properties) { if (map.size() > 0) { final StringBuilder strBuilder= new StringBuilder(); for (final Long index : map.keySet()) { @@ -93,25 +95,25 @@ public class SizeConfig implements IPersistable { strBuilder.append(map.get(index)); strBuilder.append(','); } - properties.setProperty(key, strBuilder.toString()); + properties.put(key, strBuilder.toString()); } } @Override - public void loadState(final String prefix, final Properties properties) { + public void loadState(final String prefix, final Map<String, String> properties) { //ensure to cleanup the current states prior loading new ones this.defaultSizeMap.clear(); this.sizeMap.clear(); this.resizablesMap.clear(); - final String persistedDefaultSize= properties.getProperty(prefix + PERSISTENCE_KEY_DEFAULT_SIZE); + final String persistedDefaultSize= properties.get(prefix + PERSISTENCE_KEY_DEFAULT_SIZE); if (persistedDefaultSize != null && !persistedDefaultSize.isEmpty()) { - this.defaultSize= Integer.valueOf(persistedDefaultSize).intValue(); + this.defaultSize= Integer.parseInt(persistedDefaultSize); } - final String persistedResizableDefault= properties.getProperty(prefix + PERSISTENCE_KEY_RESIZABLE_BY_DEFAULT); + final String persistedResizableDefault= properties.get(prefix + PERSISTENCE_KEY_RESIZABLE_BY_DEFAULT); if (persistedResizableDefault != null && !persistedResizableDefault.isEmpty()) { - this.resizableByDefault= Boolean.valueOf(persistedResizableDefault).booleanValue(); + this.resizableByDefault= Boolean.parseBoolean(persistedResizableDefault); } loadBooleanMap(prefix + PERSISTENCE_KEY_RESIZABLE_INDEXES, properties, this.resizablesMap); @@ -119,8 +121,8 @@ public class SizeConfig implements IPersistable { loadIntegerMap(prefix + PERSISTENCE_KEY_SIZES, properties, this.sizeMap); } - private void loadIntegerMap(final String key, final Properties properties, final Map<Long, Integer> map) { - final String property= properties.getProperty(key); + private void loadIntegerMap(final String key, final Map<String, String> properties, final Map<Long, Integer> map) { + final String property= properties.get(key); if (property != null) { map.clear(); @@ -133,8 +135,8 @@ public class SizeConfig implements IPersistable { } } - private void loadBooleanMap(final String key, final Properties properties, final Map<Long, Boolean> map) { - final String property= properties.getProperty(key); + private void loadBooleanMap(final String key, final Map<String, String> properties, final Map<Long, Boolean> map) { + final String property= properties.get(key); if (property != null) { final StringTokenizer tok= new StringTokenizer(property, ","); //$NON-NLS-1$ while (tok.hasMoreTokens()) { @@ -174,7 +176,7 @@ public class SizeConfig implements IPersistable { public long getAggregateSize(final long position) { if (position < 0) { - throw PositionOutOfBoundsException.position(position); + throw new PositionOutOfBoundsException(position); } else if (position == 0) { return 0; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SizeConfigDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SizeConfigDim.java index ea72305e..db98952f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SizeConfigDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SizeConfigDim.java @@ -11,18 +11,22 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.data.core; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; -public abstract class SizeConfigDim<TLayer extends ILayer> extends DataDim<ILayer> { + +@NonNullByDefault +public abstract class SizeConfigDim<TLayer extends Layer> extends DataLayerDim<TLayer> { private final SizeConfig sizeConfig; - public SizeConfigDim(final ILayer layer, final Orientation orientation, + public SizeConfigDim(final TLayer layer, final Orientation orientation, final long idCat, final SizeConfig sizeConfig) { super(layer, orientation, idCat); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SpanningDataLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SpanningDataLayer.java index b621ce66..c0df8d23 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/layer/SpanningDataLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/data/core/SpanningDataLayer.java @@ -11,21 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.layer; +package org.eclipse.statet.ecommons.waltable.data.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.data.ISpanningDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.cell.DataCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.data.DataCell; +import org.eclipse.statet.ecommons.waltable.core.data.SpanningDataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + +@NonNullByDefault public class SpanningDataLayer extends DataLayer { - public SpanningDataLayer(final ISpanningDataProvider dataProvider, + public SpanningDataLayer(final SpanningDataProvider dataProvider, final long columnIdCat, final int defaultColumnWidth, final long rowIdCat, final int defaultRowHeight) { super(dataProvider, @@ -35,23 +39,23 @@ public class SpanningDataLayer extends DataLayer { @Override - public ISpanningDataProvider getDataProvider() { - return (ISpanningDataProvider) super.getDataProvider(); + public SpanningDataProvider getDataProvider() { + return (SpanningDataProvider)super.getDataProvider(); } @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerDim hDim= getDim(HORIZONTAL); - final ILayerDim vDim= getDim(VERTICAL); + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerDim hDim= getDim(HORIZONTAL); + final LayerDim vDim= getDim(VERTICAL); final long columnId= hDim.getPositionId(columnPosition, columnPosition); final long rowId= vDim.getPositionId(rowPosition, rowPosition); final DataCell dataCell= getDataProvider().getCellByPosition(columnPosition, rowPosition); return new DataLayerCell( - new LayerCellDim(HORIZONTAL, columnId, columnPosition, + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition, dataCell.getColumnPosition(), dataCell.getColumnSpan() ), - new LayerCellDim(VERTICAL, rowId, rowPosition, + new BasicLayerCellDim(VERTICAL, rowId, rowPosition, dataCell.getRowPosition(), dataCell.getRowSpan() )); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/cell/AlternatingRowConfigLabelAccumulator.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/AlternatingRowLabelContributor.java index 1fc51ec0..c0691b3e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/cell/AlternatingRowConfigLabelAccumulator.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/AlternatingRowLabelContributor.java @@ -11,12 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.cell; +package org.eclipse.statet.ecommons.waltable.grid; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.config.DefaultRowStyleConfiguration; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.IConfigLabelAccumulator; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.grid.config.DefaultRowStyleConfiguration; +import org.eclipse.statet.ecommons.waltable.layer.cell.CellLabelContributor; /** @@ -25,14 +26,22 @@ import org.eclipse.statet.ecommons.waltable.layer.cell.IConfigLabelAccumulator; * * @see DefaultRowStyleConfiguration */ -public class AlternatingRowConfigLabelAccumulator implements IConfigLabelAccumulator { - - public static final String ODD_ROW_CONFIG_TYPE= "ODD_" + GridRegion.BODY; //$NON-NLS-1$ - - public static final String EVEN_ROW_CONFIG_TYPE= "EVEN_" + GridRegion.BODY; //$NON-NLS-1$ - +@NonNullByDefault +public class AlternatingRowLabelContributor implements CellLabelContributor { + + public static final String ODD_ROW_CONFIG_TYPE= "BODY_ODD_ROW"; //$NON-NLS-1$ + + public static final String EVEN_ROW_CONFIG_TYPE= "BODY_EVEN_ROW"; //$NON-NLS-1$ + + + + public AlternatingRowLabelContributor() { + } + + @Override - public void accumulateConfigLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { + public void addLabels(final LabelStack configLabels, final long columnPosition, final long rowPosition) { configLabels.addLabel((rowPosition % 2 == 0 ? EVEN_ROW_CONFIG_TYPE : ODD_ROW_CONFIG_TYPE)); } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/config/DefaultGridLayerConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/config/DefaultGridLayerConfiguration.java index 670edf54..5153f016 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/config/DefaultGridLayerConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/config/DefaultGridLayerConfiguration.java @@ -11,16 +11,16 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer.config; +package org.eclipse.statet.ecommons.waltable.grid.config; import org.eclipse.statet.ecommons.waltable.config.AggregateConfiguration; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer; import org.eclipse.statet.ecommons.waltable.edit.config.DefaultEditBindings; import org.eclipse.statet.ecommons.waltable.edit.config.DefaultEditConfiguration; import org.eclipse.statet.ecommons.waltable.export.config.DefaultExportBindings; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.cell.AlternatingRowConfigLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.grid.layer.GridLayer; -import org.eclipse.statet.ecommons.waltable.layer.CompositeLayer; +import org.eclipse.statet.ecommons.waltable.grid.AlternatingRowLabelContributor; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLayer; import org.eclipse.statet.ecommons.waltable.print.config.DefaultPrintBindings; @@ -55,7 +55,7 @@ public class DefaultGridLayerConfiguration extends AggregateConfiguration { protected void addAlternateRowColoringConfig(final CompositeLayer gridLayer) { addConfiguration(new DefaultRowStyleConfiguration()); - gridLayer.addConfigLabelAccumulatorForRegion(GridRegion.BODY, new AlternatingRowConfigLabelAccumulator()); + gridLayer.addCellLabelContributor(GridLabels.BODY, new AlternatingRowLabelContributor()); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/config/DefaultRowStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/config/DefaultRowStyleConfiguration.java index 88350ce5..ae2e721c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/config/DefaultRowStyleConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/config/DefaultRowStyleConfiguration.java @@ -11,17 +11,17 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer.config; +package org.eclipse.statet.ecommons.waltable.grid.config; import org.eclipse.swt.graphics.Color; import org.eclipse.statet.ecommons.waltable.config.AbstractRegistryConfiguration; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.grid.cell.AlternatingRowConfigLabelAccumulator; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.Style; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.grid.AlternatingRowLabelContributor; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -34,20 +34,20 @@ public class DefaultRowStyleConfiguration extends AbstractRegistryConfiguration public Color oddRowBgColor= GUIHelper.COLOR_WHITE; @Override - public void configureRegistry(final IConfigRegistry configRegistry) { + public void configureRegistry(final ConfigRegistry configRegistry) { configureOddRowStyle(configRegistry); configureEvenRowStyle(configRegistry); } - protected void configureOddRowStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.oddRowBgColor); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE); + protected void configureOddRowStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.oddRowBgColor); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, AlternatingRowLabelContributor.EVEN_ROW_CONFIG_TYPE); } - protected void configureEvenRowStyle(final IConfigRegistry configRegistry) { - final Style cellStyle= new Style(); - cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.evenRowBgColor); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE); + protected void configureEvenRowStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.evenRowBgColor); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, AlternatingRowLabelContributor.ODD_ROW_CONFIG_TYPE); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/ClientAreaResizeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/ClientAreaResizeCommand.java index 07db388f..edc21952 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/ClientAreaResizeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/ClientAreaResizeCommand.java @@ -11,20 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid; +package org.eclipse.statet.ecommons.waltable.grid.core; import org.eclipse.swt.widgets.Scrollable; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; /** * Command that gives the layers access to ClientArea and the Scrollable */ +@NonNullByDefault public class ClientAreaResizeCommand extends AbstractContextFreeCommand { + /** * The {@link Scrollable}, normally the NatTable itself. */ @@ -35,22 +40,25 @@ public class ClientAreaResizeCommand extends AbstractContextFreeCommand { * Without using a GridLayer, this will be the client area of the scrollable. * On using a GridLayer this value will be overriden with the body region area. */ - private LRectangle calcArea; - + private @Nullable LRectangle calcArea; + + public ClientAreaResizeCommand(final Scrollable scrollable) { super(); this.scrollable= scrollable; } - + + public Scrollable getScrollable() { return this.scrollable; } public LRectangle getCalcArea() { - if (this.calcArea == null) { - return SWTUtil.toNatTable(this.scrollable.getClientArea()); + final LRectangle calcArea= this.calcArea; + if (calcArea == null) { + return SwtUtils.toNatTable(this.scrollable.getClientArea()); } - return this.calcArea; + return calcArea; } public void setCalcArea(final LRectangle calcArea) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridLabels.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridLabels.java new file mode 100644 index 00000000..5a378d8b --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridLabels.java @@ -0,0 +1,47 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.grid.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + + +/** + * A region is simply an area on the Grid. + * Diving the table/grid into regions makes it easier to manage areas with similar behavior. + * + * For example all the cells in the column header are painted differently + * and can respond to sorting actions. + */ +@NonNullByDefault +public interface GridLabels { + + + static final String CORNER= "CORNER"; //$NON-NLS-1$ + static final String COLUMN_HEADER= "COLUMN_HEADER"; //$NON-NLS-1$ + static final String ROW_HEADER= "ROW_HEADER"; //$NON-NLS-1$ + + /* labeled header */ + static final String COLUMN_HEADER_LABEL= COLUMN_HEADER + "_LABEL"; //$NON-NLS-1$ + static final String ROW_HEADER_LABEL= ROW_HEADER + "_LABEL"; //$NON-NLS-1$ + static final String HEADER_PLACEHOLDER= "HEADER_PLACEHOLDER"; //$NON-NLS-1$ + + /* grouped column/row */ + static final String COLUMN_GROUP_HEADER= "COLUMN_GROUP_HEADER"; //$NON-NLS-1$ + static final String ROW_GROUP_HEADER= "ROW_GROUP_HEADER"; //$NON-NLS-1$ + + static final String BODY= "BODY"; //$NON-NLS-1$ + + static final String FILTER_ROW= "FILTER_ROW"; //$NON-NLS-1$ + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/GridLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridLayer.java index 2aa5e616..9725e276 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/GridLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridLayer.java @@ -11,19 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; import org.eclipse.statet.ecommons.waltable.export.ExportCommandHandler; -import org.eclipse.statet.ecommons.waltable.grid.ClientAreaResizeCommand; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.config.DefaultGridLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.layer.CompositeLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.grid.config.DefaultGridLayerConfiguration; import org.eclipse.statet.ecommons.waltable.print.PrintCommandHandler; -import org.eclipse.statet.ecommons.waltable.selection.SelectCellCommand; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectCellCommand; /** @@ -32,13 +32,14 @@ import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; * unlike the other layers. It simply delegates most functions to its child * layers. */ +@NonNullByDefault public class GridLayer extends CompositeLayer { - - public GridLayer(final ILayer bodyLayer, final ILayer columnHeaderLayer, final ILayer rowHeaderLayer, final ILayer cornerLayer) { + + public GridLayer(final Layer bodyLayer, final Layer columnHeaderLayer, final Layer rowHeaderLayer, final Layer cornerLayer) { this(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, true); } - public GridLayer(final ILayer bodyLayer, final ILayer columnHeaderLayer, final ILayer rowHeaderLayer, final ILayer cornerLayer, final boolean useDefaultConfiguration) { + public GridLayer(final Layer bodyLayer, final Layer columnHeaderLayer, final Layer rowHeaderLayer, final Layer cornerLayer, final boolean useDefaultConfiguration) { super(2, 2); setBodyLayer(bodyLayer); @@ -93,7 +94,7 @@ public class GridLayer extends CompositeLayer { * in the body. **/ @Override - protected boolean doCommandOnChildLayers(final ILayerCommand command) { + protected boolean doCommandOnChildLayers(final LayerCommand command) { if (getBodyLayer().doCommand(command)) { return true; } @@ -110,36 +111,36 @@ public class GridLayer extends CompositeLayer { // Sub-layer accessors - public ILayer getCornerLayer() { + public Layer getCornerLayer() { return getChildLayerByLayoutCoordinate(0, 0); } - public void setCornerLayer(final ILayer cornerLayer) { - setChildLayer(GridRegion.CORNER, cornerLayer, 0, 0); + public void setCornerLayer(final Layer cornerLayer) { + setChildLayer(GridLabels.CORNER, cornerLayer, 0, 0); } - - public ILayer getColumnHeaderLayer() { + + public Layer getColumnHeaderLayer() { return getChildLayerByLayoutCoordinate(1, 0); } - public void setColumnHeaderLayer(final ILayer columnHeaderLayer) { - setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 1, 0); + public void setColumnHeaderLayer(final Layer columnHeaderLayer) { + setChildLayer(GridLabels.COLUMN_HEADER, columnHeaderLayer, 1, 0); } - public ILayer getRowHeaderLayer() { + public Layer getRowHeaderLayer() { return getChildLayerByLayoutCoordinate(0, 1); } - public void setRowHeaderLayer(final ILayer rowHeaderLayer) { - setChildLayer(GridRegion.ROW_HEADER, rowHeaderLayer, 0, 1); + public void setRowHeaderLayer(final Layer rowHeaderLayer) { + setChildLayer(GridLabels.ROW_HEADER, rowHeaderLayer, 0, 1); } - public ILayer getBodyLayer() { + public Layer getBodyLayer() { return getChildLayerByLayoutCoordinate(1, 1); } - public void setBodyLayer(final ILayer bodyLayer) { - setChildLayer(GridRegion.BODY, bodyLayer, 1, 1); + public void setBodyLayer(final Layer bodyLayer) { + setChildLayer(GridLabels.BODY, bodyLayer, 1, 1); //update the command handlers for auto resize because of the connection to the body layer stack // unregisterCommandHandler(AutoResizePositionsCommand.class); @@ -160,21 +161,23 @@ public class GridLayer extends CompositeLayer { @Override - public boolean doCommand(final ILayerCommand command) { - if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) { - final ClientAreaResizeCommand clientAreaResizeCommand= (ClientAreaResizeCommand) command; - final LRectangle possibleArea= SWTUtil.toNatTable(clientAreaResizeCommand.getScrollable().getClientArea()); + public boolean doCommand(final LayerCommand command) { + if (command instanceof ClientAreaResizeCommand) { + final ClientAreaResizeCommand resizeCommand= (ClientAreaResizeCommand)command; + final LRectangle possibleArea= SwtUtils.toNatTable(resizeCommand.getScrollable().getClientArea()); //remove the column header height and the row header width from the client area to //ensure that only the body region is used for percentage calculation final LRectangle rowLayerArea= getRowHeaderLayer().getClientAreaProvider().getClientArea(); final LRectangle columnLayerArea= getColumnHeaderLayer().getClientAreaProvider().getClientArea(); - possibleArea.width= possibleArea.width - rowLayerArea.width; - possibleArea.height= possibleArea.height - columnLayerArea.height; - clientAreaResizeCommand.setCalcArea(possibleArea); + resizeCommand.setCalcArea(new LRectangle( + possibleArea.x, + possibleArea.y, + possibleArea.width - rowLayerArea.width, + possibleArea.height - columnLayerArea.height )); } return super.doCommand(command); } - -}
\ No newline at end of file + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/GridRegion.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridRegion.java index badb668a..62c33263 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/GridRegion.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/GridRegion.java @@ -11,7 +11,9 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid; +package org.eclipse.statet.ecommons.waltable.grid.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** @@ -21,19 +23,21 @@ package org.eclipse.statet.ecommons.waltable.grid; * For example all the cells in the column header are painted differently * and can respond to sorting actions. */ +@NonNullByDefault public interface GridRegion { - public static final String CORNER= "CORNER"; //$NON-NLS-1$ - public static final String COLUMN_HEADER= "COLUMN_HEADER"; //$NON-NLS-1$ - public static final String COLUMN_GROUP_HEADER= "COLUMN_GROUP_HEADER"; //$NON-NLS-1$ - public static final String ROW_HEADER= "ROW_HEADER"; //$NON-NLS-1$ - public static final String ROW_GROUP_HEADER= "ROW_GROUP_HEADER"; //$NON-NLS-1$ - public static final String COLUMN_HEADER_LABEL= COLUMN_HEADER + "_LABEL"; //$NON-NLS-1$ - public static final String ROW_HEADER_LABEL= ROW_HEADER + "_LABEL"; //$NON-NLS-1$ - public static final String HEADER_PLACEHOLDER= "HEADER_PLACEHOLDER"; //$NON-NLS-1$ - public static final String BODY= "BODY"; //$NON-NLS-1$ + static final String CORNER= "CORNER"; //$NON-NLS-1$ + static final String COLUMN_HEADER= "COLUMN_HEADER"; //$NON-NLS-1$ + static final String COLUMN_GROUP_HEADER= "COLUMN_GROUP_HEADER"; //$NON-NLS-1$ + static final String ROW_HEADER= "ROW_HEADER"; //$NON-NLS-1$ + static final String ROW_GROUP_HEADER= "ROW_GROUP_HEADER"; //$NON-NLS-1$ + static final String COLUMN_HEADER_LABEL= COLUMN_HEADER + "_LABEL"; //$NON-NLS-1$ + static final String ROW_HEADER_LABEL= ROW_HEADER + "_LABEL"; //$NON-NLS-1$ + static final String HEADER_PLACEHOLDER= "HEADER_PLACEHOLDER"; //$NON-NLS-1$ + + static final String BODY= "BODY"; //$NON-NLS-1$ - public static final String FILTER_ROW= "FILTER_ROW"; //$NON-NLS-1$ + static final String FILTER_ROW= "FILTER_ROW"; //$NON-NLS-1$ } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultColumnHeaderDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultColumnHeaderDataProvider.java new file mode 100644 index 00000000..e2b2cca7 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultColumnHeaderDataProvider.java @@ -0,0 +1,64 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.grid.core.data; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; + + +@NonNullByDefault +public class DefaultColumnHeaderDataProvider implements DataProvider { + + + private final ImList<String> columnLabels; + + + public DefaultColumnHeaderDataProvider(final ImList<String> columnLabels) { + this.columnLabels= columnLabels; + } + + + @Override + public long getColumnCount() { + return this.columnLabels.size(); + } + + @Override + public long getRowCount() { + return 1; + } + + /** + * This class does not support multiple rows in the column header layer. + */ + @Override + public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, + final @Nullable IProgressMonitor monitor) { + if (columnIndex < 0 || columnIndex >= this.columnLabels.size()) { + throw new IndexOutOfBoundsException(); + } + return this.columnLabels.get((int)columnIndex); + } + + @Override + public void setDataValue(final long columnIndex, final long rowIndex, final @Nullable Object newValue) { + throw new UnsupportedOperationException(); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultCornerDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultCornerDataProvider.java index a6bc893a..adedd809 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultCornerDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultCornerDataProvider.java @@ -11,25 +11,29 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.grid.core.data; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; -public class DefaultCornerDataProvider implements IDataProvider { + +@NonNullByDefault +public class DefaultCornerDataProvider implements DataProvider { - private final IDataProvider columnHeaderDataProvider; - private final IDataProvider rowHeaderDataProvider; + private final DataProvider columnHeaderDataProvider; + private final DataProvider rowHeaderDataProvider; - public DefaultCornerDataProvider(final IDataProvider columnHeaderDataProvider, final IDataProvider rowHeaderDataProvider) { + public DefaultCornerDataProvider(final DataProvider columnHeaderDataProvider, final DataProvider rowHeaderDataProvider) { this.columnHeaderDataProvider= columnHeaderDataProvider; this.rowHeaderDataProvider= rowHeaderDataProvider; } + @Override public long getColumnCount() { return this.rowHeaderDataProvider.getColumnCount(); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultRowHeaderDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultRowHeaderDataProvider.java index dac2ff8e..cba07dfb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultRowHeaderDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/data/DefaultRowHeaderDataProvider.java @@ -11,20 +11,23 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.grid.core.data; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; -public class DefaultRowHeaderDataProvider implements IDataProvider { + +@NonNullByDefault +public class DefaultRowHeaderDataProvider implements DataProvider { - protected final IDataProvider bodyDataProvider; + private final DataProvider bodyDataProvider; - public DefaultRowHeaderDataProvider(final IDataProvider bodyDataProvider) { + public DefaultRowHeaderDataProvider(final DataProvider bodyDataProvider) { this.bodyDataProvider= bodyDataProvider; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtColumnHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtColumnHeaderLayer.java index b52a7c2a..c47cb1ff 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtColumnHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtColumnHeaderLayer.java @@ -12,25 +12,28 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.labeled; +package org.eclipse.statet.ecommons.waltable.grid.core.labeled; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.PlaceholderLayer; -import org.eclipse.statet.ecommons.waltable.layer.CompositeLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.PlaceholderLayer; + +@NonNullByDefault public class ExtColumnHeaderLayer extends CompositeLayer { - public ExtColumnHeaderLayer(final ILayer columnHeaderLayer) { + public ExtColumnHeaderLayer(final Layer columnHeaderLayer) { super(1, 2); - setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0); - setChildLayer(GridRegion.HEADER_PLACEHOLDER, new PlaceholderLayer(columnHeaderLayer, null, + setChildLayer(GridLabels.COLUMN_HEADER, columnHeaderLayer, 0, 0); + setChildLayer(GridLabels.HEADER_PLACEHOLDER, new PlaceholderLayer(columnHeaderLayer, null, false, columnHeaderLayer.getLayerPainter() ), 0, 1); } @@ -42,8 +45,7 @@ public class ExtColumnHeaderLayer extends CompositeLayer { public void setSpaceSize(final int pixel) { - ((PlaceholderLayer) getChildByLabel(GridRegion.HEADER_PLACEHOLDER).layer) - .setSize(pixel); + ((PlaceholderLayer)getChildByLabel(GridLabels.HEADER_PLACEHOLDER).layer).setSize(pixel); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtGridLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtGridLayer.java index ba7dd6d0..2ae44679 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtGridLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtGridLayer.java @@ -12,32 +12,37 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.labeled; +package org.eclipse.statet.ecommons.waltable.grid.core.labeled; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.GridLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLayer; + +@NonNullByDefault public class ExtGridLayer extends GridLayer { - public static final String EXT_COLUMN_HEADER= "EXT_" + GridRegion.COLUMN_HEADER; //$NON-NLS-1$ - public static final String EXT_ROW_HEADER= "EXT_" + GridRegion.ROW_HEADER; //$NON-NLS-1$ + public static final String EXT_COLUMN_HEADER= "EXT_" + GridLabels.COLUMN_HEADER; //$NON-NLS-1$ + public static final String EXT_ROW_HEADER= "EXT_" + GridLabels.ROW_HEADER; //$NON-NLS-1$ - public ExtGridLayer(final ILayer bodyLayer, final ILayer columnHeaderLayer, final ILayer rowHeaderLayer, final ILayer cornerLayer, final boolean useDefaultConfiguration) { + public ExtGridLayer(final Layer bodyLayer, + final Layer columnHeaderLayer, final Layer rowHeaderLayer, final Layer cornerLayer, + final boolean useDefaultConfiguration) { super(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, useDefaultConfiguration); } @Override - public void setColumnHeaderLayer(final ILayer columnHeaderLayer) { + public void setColumnHeaderLayer(final Layer columnHeaderLayer) { setChildLayer(EXT_COLUMN_HEADER, columnHeaderLayer, 1, 0); } @Override - public void setRowHeaderLayer(final ILayer rowHeaderLayer) { + public void setRowHeaderLayer(final Layer rowHeaderLayer) { setChildLayer(EXT_ROW_HEADER, rowHeaderLayer, 0, 1); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtRowHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtRowHeaderLayer.java index 5b575dc0..00624a97 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/labeled/ExtRowHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/ExtRowHeaderLayer.java @@ -12,25 +12,28 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.labeled; +package org.eclipse.statet.ecommons.waltable.grid.core.labeled; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.grid.layer.PlaceholderLayer; -import org.eclipse.statet.ecommons.waltable.layer.CompositeLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.CompositeLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.PlaceholderLayer; + +@NonNullByDefault public class ExtRowHeaderLayer extends CompositeLayer { - public ExtRowHeaderLayer(final ILayer rowHeaderLayer) { + public ExtRowHeaderLayer(final Layer rowHeaderLayer) { super(2, 1); - setChildLayer(GridRegion.ROW_HEADER, rowHeaderLayer, 0, 0); - setChildLayer(GridRegion.HEADER_PLACEHOLDER, new PlaceholderLayer(null, rowHeaderLayer, + setChildLayer(GridLabels.ROW_HEADER, rowHeaderLayer, 0, 0); + setChildLayer(GridLabels.HEADER_PLACEHOLDER, new PlaceholderLayer(null, rowHeaderLayer, false, rowHeaderLayer.getLayerPainter() ), 1, 0); } @@ -42,8 +45,7 @@ public class ExtRowHeaderLayer extends CompositeLayer { public void setSpaceSize(final int pixel) { - ((PlaceholderLayer) getChildByLabel(GridRegion.HEADER_PLACEHOLDER).layer) - .setSize(pixel); + ((PlaceholderLayer)getChildByLabel(GridLabels.HEADER_PLACEHOLDER).layer).setSize(pixel); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/LabelCornerLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/LabelCornerLayer.java new file mode 100644 index 00000000..b9598154 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/labeled/LabelCornerLayer.java @@ -0,0 +1,126 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.grid.core.labeled; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.core.runtime.IProgressMonitor; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.grid.core.layers.CornerLayer; + + +@NonNullByDefault +public class LabelCornerLayer extends CornerLayer { + + + private final @Nullable DataProvider columnHeaderLabelProvider; + private final @Nullable DataProvider rowHeaderLabelProvider; + + + /** + * @param baseLayer + * The data provider for this layer + * @param horizontalLayerDependency + * The layer to link the horizontal dimension to, typically the row header layer + * @param verticalLayerDependency + * The layer to link the vertical dimension to, typically the column header layer + * @param useDefaultConfiguration + * If default configuration should be applied to this layer (at moment none) + * @param layerPainter + * The painter for this layer or <code>null</code> to use the painter of the base layer + */ + public LabelCornerLayer(final Layer baseLayer, + final Layer horizontalLayerDependency, final Layer verticalLayerDependency, + final @Nullable DataProvider columnHeaderLabelProvider, + final @Nullable DataProvider rowHeaderLabelProvider, + final boolean useDefaultConfiguration, + final LayerPainter layerPainter) { + super(baseLayer, horizontalLayerDependency, verticalLayerDependency, + useDefaultConfiguration, layerPainter ); + + this.columnHeaderLabelProvider= columnHeaderLabelProvider; + this.rowHeaderLabelProvider= rowHeaderLabelProvider; + } + + + @Override + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerDim hDim= getDim(HORIZONTAL); + final LayerDim vDim= getDim(VERTICAL); + final long columnId= hDim.getPositionId(columnPosition, columnPosition); + final long rowId= vDim.getPositionId(rowPosition, rowPosition); + + final long columnCount= getColumnCount(); + final long rowCount= getRowCount(); + if (rowPosition < rowCount - 1) { + return new BasicLayerCell(this, + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition, 0, columnCount), + new BasicLayerCellDim(VERTICAL, rowId, rowPosition) ) { + @Override + public LabelStack getLabels() { + return new LabelStack(GridLabels.COLUMN_HEADER_LABEL); + } + @Override + public @Nullable Object getDataValue(final int flags, final @Nullable IProgressMonitor monitor) { + final var labelProvider= LabelCornerLayer.this.columnHeaderLabelProvider; + return (labelProvider != null) ? + labelProvider.getDataValue(0, getRowPosition(), flags, monitor) : + ""; //$NON-NLS-1$ + } + }; + } + else if (columnPosition < columnCount - 1) { + return new BasicLayerCell(this, + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition), + new BasicLayerCellDim(VERTICAL, rowId, rowPosition) ) { + @Override + public LabelStack getLabels() { + return new LabelStack(GridLabels.ROW_HEADER_LABEL); + } + @Override + public @Nullable Object getDataValue(final int flags, final @Nullable IProgressMonitor monitor) { + final var labelProvider= LabelCornerLayer.this.rowHeaderLabelProvider; + return (labelProvider != null) ? + labelProvider.getDataValue(getColumnPosition(), 0, flags, monitor) : + ""; //$NON-NLS-1$ + } + }; + } + else { + return new BasicLayerCell(this, + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition), + new BasicLayerCellDim(VERTICAL, rowId, rowPosition) ) { + @Override + public LabelStack getLabels() { + return new LabelStack(GridLabels.HEADER_PLACEHOLDER); + } + }; + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/AbstractPositionHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/AbstractPositionHeaderLayer.java index c7183752..849426f0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/AbstractPositionHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/AbstractPositionHeaderLayer.java @@ -11,27 +11,32 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; -import org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** * Responsible for rendering, event handling etc on the column/row headers. */ +@NonNullByDefault public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { @@ -51,40 +56,35 @@ public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { * @param layerPainter * The painter for this layer or <code>null</code> to use the painter of the base layer */ - public AbstractPositionHeaderLayer(final ILayer baseLayer, final Orientation orientation, - final ILayer contentLayerDependency, + public AbstractPositionHeaderLayer(final Layer baseLayer, final Orientation orientation, + final Layer contentLayerDependency, final SelectionLayer selectionLayer, final String fullySelectedLabel, - final ILayerPainter layerPainter) { + final LayerPainter layerPainter) { super(baseLayer, (orientation == HORIZONTAL) ? contentLayerDependency : baseLayer, - (orientation == VERTICAL) ? contentLayerDependency : baseLayer ); - if (selectionLayer == null) { - throw new NullPointerException("selectionLayer"); //$NON-NLS-1$ - } - - this.headerOrientation= orientation; - this.selectionLayer= selectionLayer; - this.fullySelectedLabel= fullySelectedLabel; - - this.layerPainter= layerPainter; + (orientation == VERTICAL) ? contentLayerDependency : baseLayer, + layerPainter ); + this.headerOrientation= nonNullAssert(orientation); + this.selectionLayer= nonNullAssert(selectionLayer); + this.fullySelectedLabel= nonNullAssert(fullySelectedLabel); } @Override - protected ILayerCell createCell(final ILayerCellDim hDim, final ILayerCellDim vDim, final ILayerCell underlyingCell) { + protected LayerCell createCell(final LayerCellDim hDim, final LayerCellDim vDim, final LayerCell underlyingCell) { return new ForwardLayerCell(this, hDim, vDim, underlyingCell) { @Override public DisplayMode getDisplayMode() { if (isSelected(getDim(AbstractPositionHeaderLayer.this.headerOrientation))) { - return DisplayMode.SELECT; + return DisplayMode.SELECTED; } return super.getDisplayMode(); } @Override - public LabelStack getConfigLabels() { - final LabelStack configLabels= super.getConfigLabels(); + public LabelStack getLabels() { + final LabelStack configLabels= super.getLabels(); if (isFullySelected(getDim(AbstractPositionHeaderLayer.this.headerOrientation))) { configLabels.addLabel(AbstractPositionHeaderLayer.this.fullySelectedLabel); @@ -96,11 +96,11 @@ public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { }; } - protected boolean isSelected(final ILayerCellDim dim) { - final ILayerDim layerDim= getDim(this.headerOrientation); + protected boolean isSelected(final LayerCellDim dim) { + final LayerDim layerDim= getDim(this.headerOrientation); final long position= dim.getPosition(); if (this.selectionLayer.isPositionSelected(this.headerOrientation, - LayerUtil.convertPosition(layerDim, position, position, + LayerUtils.convertPosition(layerDim, position, position, this.selectionLayer.getDim(this.headerOrientation) ) )) { return true; } @@ -110,7 +110,7 @@ public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { for (; iPosition < endPosition; iPosition++) { if (iPosition != position && this.selectionLayer.isPositionSelected(this.headerOrientation, - LayerUtil.convertPosition(layerDim, position, iPosition, + LayerUtils.convertPosition(layerDim, position, iPosition, this.selectionLayer.getDim(this.headerOrientation) ))) { return true; } @@ -119,11 +119,11 @@ public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { return false; } - protected boolean isFullySelected(final ILayerCellDim dim) { - final ILayerDim layerDim= getDim(this.headerOrientation); + protected boolean isFullySelected(final LayerCellDim dim) { + final LayerDim layerDim= getDim(this.headerOrientation); final long position= dim.getPosition(); if (!this.selectionLayer.isPositionFullySelected(this.headerOrientation, - LayerUtil.convertPosition(layerDim, position, position, + LayerUtils.convertPosition(layerDim, position, position, this.selectionLayer.getDim(this.headerOrientation)) )) { return false; } @@ -133,7 +133,7 @@ public class AbstractPositionHeaderLayer extends DimensionallyDependentLayer { for (; iPosition < endPosition; iPosition++) { if (iPosition != position && !this.selectionLayer.isPositionFullySelected(this.headerOrientation, - LayerUtil.convertPosition(layerDim, position, iPosition, + LayerUtils.convertPosition(layerDim, position, iPosition, this.selectionLayer.getDim(this.headerOrientation) ))) { return false; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/ColumnHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/ColumnHeaderLayer.java index 8f226adc..209d6d96 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/ColumnHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/ColumnHeaderLayer.java @@ -11,21 +11,24 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.CellLayerPainter; import org.eclipse.statet.ecommons.waltable.layer.config.DefaultColumnHeaderLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.painter.layer.CellLayerPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; /** * Responsible for rendering, event handling etc on the column headers. */ +@NonNullByDefault public class ColumnHeaderLayer extends AbstractPositionHeaderLayer { @@ -39,11 +42,11 @@ public class ColumnHeaderLayer extends AbstractPositionHeaderLayer { * @param selectionLayer * The selection layer required to respond to selection events */ - public ColumnHeaderLayer(final ILayer baseLayer, final ILayer horizontalLayerDependency, final SelectionLayer selectionLayer) { + public ColumnHeaderLayer(final Layer baseLayer, final Layer horizontalLayerDependency, final SelectionLayer selectionLayer) { this(baseLayer, horizontalLayerDependency, selectionLayer, true); } - public ColumnHeaderLayer(final ILayer baseLayer, final ILayer horizontalLayerDependency, final SelectionLayer selectionLayer, final boolean useDefaultConfiguration) { + public ColumnHeaderLayer(final Layer baseLayer, final Layer horizontalLayerDependency, final SelectionLayer selectionLayer, final boolean useDefaultConfiguration) { this(baseLayer, horizontalLayerDependency, selectionLayer, useDefaultConfiguration, new CellLayerPainter()); } @@ -59,8 +62,9 @@ public class ColumnHeaderLayer extends AbstractPositionHeaderLayer { * @param layerPainter * The painter for this layer or <code>null</code> to use the painter of the base layer */ - public ColumnHeaderLayer(final ILayer baseLayer, final ILayer horizontalLayerDependency, - final SelectionLayer selectionLayer, final boolean useDefaultConfiguration, final ILayerPainter layerPainter) { + public ColumnHeaderLayer(final Layer baseLayer, final Layer horizontalLayerDependency, + final SelectionLayer selectionLayer, final boolean useDefaultConfiguration, + final LayerPainter layerPainter) { super(baseLayer, HORIZONTAL, horizontalLayerDependency, selectionLayer, SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE, layerPainter ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/CornerLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/CornerLayer.java new file mode 100644 index 00000000..09c50f36 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/CornerLayer.java @@ -0,0 +1,70 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.grid.core.layers; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; + + +/** + * Layer for the top left header corner of the grid layer + */ +@NonNullByDefault +public class CornerLayer extends DimensionallyDependentLayer { + + + /** + * @param baseLayer + * The data provider for this layer + * @param horizontalLayerDependency + * The layer to link the horizontal dimension to, typically the row header layer + * @param verticalLayerDependency + * The layer to link the vertical dimension to, typically the column header layer + * @param useDefaultConfiguration + * If default configuration should be applied to this layer (at moment none) + * @param layerPainter + * The painter for this layer or <code>null</code> to use the painter of the base layer + */ + public CornerLayer(final Layer baseLayer, + final Layer horizontalLayerDependency, final Layer verticalLayerDependency, + final boolean useDefaultConfiguration, + final LayerPainter layerPainter) { + super(baseLayer, horizontalLayerDependency, verticalLayerDependency, layerPainter); + } + + + @Override + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerDim hDim= getDim(HORIZONTAL); + final LayerDim vDim= getDim(VERTICAL); + final long columnId= hDim.getPositionId(columnPosition, columnPosition); + final long rowId= vDim.getPositionId(rowPosition, rowPosition); + + return new BasicLayerCell(this, + new BasicLayerCellDim(HORIZONTAL, columnId, + columnPosition, 0, hDim.getPositionCount() ), + new BasicLayerCellDim(VERTICAL, rowId, + rowPosition, 0, getVerticalLayerDependency().getRowCount()) ); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DefaultColumnHeaderDataLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DefaultColumnHeaderDataLayer.java index 9b91c1fe..7062a6a6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DefaultColumnHeaderDataLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DefaultColumnHeaderDataLayer.java @@ -11,17 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionId; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionId; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; + +@NonNullByDefault public class DefaultColumnHeaderDataLayer extends DataLayer { - public DefaultColumnHeaderDataLayer(final IDataProvider columnHeaderDataProvider) { + public DefaultColumnHeaderDataLayer(final DataProvider columnHeaderDataProvider) { super(columnHeaderDataProvider, PositionId.BODY_CAT, 100, PositionId.HEADER_CAT, 20); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DefaultRowHeaderDataLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DefaultRowHeaderDataLayer.java index df5cc511..208824ff 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DefaultRowHeaderDataLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DefaultRowHeaderDataLayer.java @@ -11,17 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionId; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionId; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; + +@NonNullByDefault public class DefaultRowHeaderDataLayer extends DataLayer { - public DefaultRowHeaderDataLayer(final IDataProvider rowHeaderDataProvider) { + public DefaultRowHeaderDataLayer(final DataProvider rowHeaderDataProvider) { super(rowHeaderDataProvider, PositionId.HEADER_CAT, 40, PositionId.BODY_CAT, 40); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DimensionallyDependentLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DimensionallyDependentLayer.java index 68ee02aa..8b93f5d0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/DimensionallyDependentLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/DimensionallyDependentLayer.java @@ -12,23 +12,30 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullLateInit; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.ForwardLayerDim; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.TransformLayer; +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.TransformLayer; /** @@ -50,18 +57,19 @@ import org.eclipse.statet.ecommons.waltable.layer.TransformLayer; * ILayer rowHeaderLayer= new DimensionallyDependentLayer(rowHeaderColumnDataLayer, bodyLayer, rowHeaderColumnDataLayer); * </pre> */ -public class DimensionallyDependentLayer extends TransformLayer { +@NonNullByDefault +public class DimensionallyDependentLayer extends TransformLayer<ForwardLayerDim<? extends DimensionallyDependentLayer>> { protected static class Dim extends ForwardLayerDim<DimensionallyDependentLayer> { - public Dim(final DimensionallyDependentLayer layer, final ILayerDim underlyingDim) { + public Dim(final DimensionallyDependentLayer layer, final LayerDim underlyingDim) { super(layer, underlyingDim); } - protected ILayerDim getBaseDim() { + protected LayerDim getBaseDim() { return this.layer.getBaseLayer().getDim(this.orientation); } @@ -72,14 +80,14 @@ public class DimensionallyDependentLayer extends TransformLayer { final long underlyingPosition= getBaseDim().getPositionById(id); if (underlyingPosition == POSITION_NA) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } return underlyingPosition; } @Override - public long underlyingToLocalPosition(final ILayerDim sourceUnderlyingDim, + public long underlyingToLocalPosition(final LayerDim sourceUnderlyingDim, final long underlyingPosition) { if (sourceUnderlyingDim != getBaseDim()) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -89,7 +97,7 @@ public class DimensionallyDependentLayer extends TransformLayer { } @Override - public List<LRange> underlyingToLocalPositions(final ILayerDim sourceUnderlyingDim, + public List<LRange> underlyingToLocalPositions(final LayerDim sourceUnderlyingDim, final Collection<LRange> underlyingPositions) { if (sourceUnderlyingDim != getBaseDim()) { throw new IllegalArgumentException("underlyingLayer"); //$NON-NLS-1$ @@ -119,22 +127,23 @@ public class DimensionallyDependentLayer extends TransformLayer { final long position= this.underlyingDim.getPositionById(id); if (underlyingPosition == POSITION_NA) { - throw PositionOutOfBoundsException.underlyingPosition(underlyingPosition); + throw new PositionOutOfBoundsException("underlyingPosition", + underlyingPosition, getOrientation() ); } return position; } @Override - public List<ILayerDim> getUnderlyingDimsByPosition(final long position) { - return Collections.<ILayerDim>singletonList(getBaseDim()); + public ImList<LayerDim> getUnderlyingDimsByPosition(final long position) { + return ImCollections.newList(getBaseDim()); } } - private ILayer horizontalLayerDependency; - private ILayer verticalLayerDependency; + private Layer horizontalLayerDependency= nonNullLateInit(); + private Layer verticalLayerDependency= nonNullLateInit(); /** @@ -144,48 +153,63 @@ public class DimensionallyDependentLayer extends TransformLayer { * @param horizontalLayerDependency the layer, the horizontal dimension is linked to * @param verticalLayerDependency the layer, the vertical dimension is linked to */ - public DimensionallyDependentLayer(final ILayer baseLayer, - final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency) { - super(baseLayer); + public DimensionallyDependentLayer(final Layer baseLayer, + final Layer horizontalLayerDependency, final Layer verticalLayerDependency, + final @Nullable LayerPainter layerPainter) { + super(baseLayer, layerPainter); + + this.horizontalLayerDependency= horizontalLayerDependency; + this.verticalLayerDependency= verticalLayerDependency; - setHorizontalLayerDependency(horizontalLayerDependency); - setVerticalLayerDependency(verticalLayerDependency); + init(); } /** - * Creates a new DimensionallyDependentLayer. The horizontal and vertical layer dependency must be set - * by calling {@link #init(ILayer, ILayer)} before the layer is used. + * Creates a new DimensionallyDependentLayer. * * @param baseLayer the underlying base layer + * @param horizontalLayerDependency the layer, the horizontal dimension is linked to + * @param verticalLayerDependency the layer, the vertical dimension is linked to */ - protected DimensionallyDependentLayer(final ILayer baseLayer) { - super(baseLayer); + public DimensionallyDependentLayer(final Layer baseLayer, + final Layer horizontalLayerDependency, final Layer verticalLayerDependency) { + this(baseLayer, horizontalLayerDependency, verticalLayerDependency, null); } + /** + * Creates a new DimensionallyDependentLayer. The horizontal and vertical layer dependency must be set + * by calling {@link #init(Layer, Layer)} before the layer is used. + * + * @param baseLayer the underlying base layer + */ + protected DimensionallyDependentLayer(final Layer baseLayer, + final @Nullable LayerPainter layerPainter) { + super(baseLayer, layerPainter); + } @Override - protected void initDims() { + protected void init() { if (this.horizontalLayerDependency == null || this.verticalLayerDependency == null) { return; } - - for (final Orientation orientation : Orientation.values()) { - final ILayer dependency= getLayerDependency(orientation); - final ILayerDim dim; - if (dependency == getBaseLayer()) { - dim= new ForwardLayerDim<>(this, dependency.getDim(orientation)); - } - else { - dim= new Dim(this, dependency.getDim(orientation)); - } - setDim(dim); + super.init(); + } + + @Override + protected ForwardLayerDim<? extends DimensionallyDependentLayer> createDim(final Orientation orientation) { + final Layer dependency= getLayerDependency(orientation); + if (dependency == getBaseLayer()) { + return new ForwardLayerDim<>(this, dependency.getDim(orientation)); + } + else { + return new Dim(this, dependency.getDim(orientation)); } } // Dependent layer accessors - protected void setHorizontalLayerDependency(final ILayer horizontalLayerDependency) { + protected void setHorizontalLayerDependency(final Layer horizontalLayerDependency) { this.horizontalLayerDependency= horizontalLayerDependency; // horizontalLayerDependency.addLayerListener(new ILayerListener() { @@ -198,10 +222,10 @@ public class DimensionallyDependentLayer extends TransformLayer { // // }); - initDims(); + init(); } - protected void setVerticalLayerDependency(final ILayer verticalLayerDependency) { + protected void setVerticalLayerDependency(final Layer verticalLayerDependency) { this.verticalLayerDependency= verticalLayerDependency; // verticalLayerDependency.addLayerListener(new ILayerListener() { @@ -214,29 +238,29 @@ public class DimensionallyDependentLayer extends TransformLayer { // // }); - initDims(); + init(); } - public ILayer getHorizontalLayerDependency() { + public Layer getHorizontalLayerDependency() { return this.horizontalLayerDependency; } - public ILayer getVerticalLayerDependency() { + public Layer getVerticalLayerDependency() { return this.verticalLayerDependency; } - public ILayer getLayerDependency(final Orientation orientation) { + public Layer getLayerDependency(final Orientation orientation) { return (orientation == HORIZONTAL) ? this.horizontalLayerDependency : this.verticalLayerDependency; } - public ILayer getBaseLayer() { + public Layer getBaseLayer() { return getUnderlyingLayer(); } // Commands @Override - public boolean doCommand(final ILayerCommand command) { + public boolean doCommand(final LayerCommand command) { if (super.doCommand(command)) { return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/PlaceholderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/PlaceholderLayer.java index 86398bb5..7850620c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/PlaceholderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/PlaceholderLayer.java @@ -12,32 +12,36 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionId; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.AbstractLayer; -import org.eclipse.statet.ecommons.waltable.layer.DataDim; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.LayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.CellLayerPainter; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionId; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.BasicLayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.CellLayerPainter; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayerDim; + +@NonNullByDefault public class PlaceholderLayer extends DimensionallyDependentLayer { - private static class DummyLayer extends AbstractLayer implements ILayer { + private static class DummyLayer extends AbstractLayer<DataLayerDim<DummyLayer>> implements Layer { - private static class Dim extends DataDim<DummyLayer> { + private static class Dim extends DataLayerDim<DummyLayer> { public Dim(final DummyLayer layer, final Orientation orientation, final long catId) { @@ -64,7 +68,7 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { @Override public long getPositionStart(final long position) { if (position != 0) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } return 0; } @@ -72,7 +76,7 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { @Override public int getPositionSize(final long position) { if (position != 0) { - throw PositionOutOfBoundsException.position(position, getOrientation()); + throw new PositionOutOfBoundsException(position, getOrientation()); } return this.layer.size; } @@ -88,29 +92,30 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { private static long idCounter; + private final long id; + private int size= DataLayer.DEFAULT_ROW_HEIGHT; public DummyLayer() { + this.id= PositionId.PLACEHOLDER_CAT + idCounter++; + + init(); } - @Override - protected void initDims() { - final long id= PositionId.PLACEHOLDER_CAT + idCounter++; - for (final Orientation orientation : Orientation.values()) { - setDim(new Dim(this, orientation, id)); - } + protected DataLayerDim<DummyLayer> createDim(final Orientation orientation) { + return new Dim(this, orientation, this.id); } @Override - public ILayer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { + public @Nullable Layer getUnderlyingLayerByPosition(final long columnPosition, final long rowPosition) { return null; } @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { throw new UnsupportedOperationException(); } @@ -125,7 +130,8 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { * @param verticalLayerDependency * The layer to link the vertical dimension to, typically the column header layer */ - public PlaceholderLayer(final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency) { + public PlaceholderLayer(final @Nullable Layer horizontalLayerDependency, + final @Nullable Layer verticalLayerDependency) { this(horizontalLayerDependency, verticalLayerDependency, true, new CellLayerPainter()); } @@ -139,16 +145,16 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { * @param layerPainter * The painter for this layer or <code>null</code> to use the painter of the base layer */ - public PlaceholderLayer(final ILayer horizontalLayerDependency, final ILayer verticalLayerDependency, - final boolean useDefaultConfiguration, final ILayerPainter layerPainter) { - super(new DummyLayer()); + public PlaceholderLayer(final @Nullable Layer horizontalLayerDependency, + final @Nullable Layer verticalLayerDependency, + final boolean useDefaultConfiguration, final LayerPainter layerPainter) { + super(new DummyLayer(), + layerPainter ); setHorizontalLayerDependency((horizontalLayerDependency != null) ? horizontalLayerDependency : getBaseLayer() ); setVerticalLayerDependency((verticalLayerDependency != null) ? verticalLayerDependency : getBaseLayer() ); - - this.layerPainter= layerPainter; } @@ -157,16 +163,16 @@ public class PlaceholderLayer extends DimensionallyDependentLayer { } @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { - final ILayerDim hDim= getDim(HORIZONTAL); - final ILayerDim vDim= getDim(VERTICAL); + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + final LayerDim hDim= getDim(HORIZONTAL); + final LayerDim vDim= getDim(VERTICAL); final long columnId= hDim.getPositionId(columnPosition, columnPosition); final long rowId= vDim.getPositionId(rowPosition, rowPosition); - return new LayerCell(this, - new LayerCellDim(HORIZONTAL, columnId, + return new BasicLayerCell(this, + new BasicLayerCellDim(HORIZONTAL, columnId, columnPosition, 0, hDim.getPositionCount() ), - new LayerCellDim(VERTICAL, rowId, + new BasicLayerCellDim(VERTICAL, rowId, rowPosition, 0, vDim.getPositionCount() )); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/RowHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/RowHeaderLayer.java index 2429ad0a..65ba0c2f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/layer/RowHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/core/layers/RowHeaderLayer.java @@ -11,20 +11,23 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.layer; +package org.eclipse.statet.ecommons.waltable.grid.core.layers; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; import org.eclipse.statet.ecommons.waltable.layer.config.DefaultRowHeaderLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; /** * Layer for the row headers of the grid layer */ +@NonNullByDefault public class RowHeaderLayer extends AbstractPositionHeaderLayer { @@ -38,11 +41,11 @@ public class RowHeaderLayer extends AbstractPositionHeaderLayer { * @param selectionLayer * The selection layer required to respond to selection events */ - public RowHeaderLayer(final ILayer baseLayer, final ILayer verticalLayerDependency, final SelectionLayer selectionLayer) { + public RowHeaderLayer(final Layer baseLayer, final Layer verticalLayerDependency, final SelectionLayer selectionLayer) { this(baseLayer, verticalLayerDependency, selectionLayer, true); } - public RowHeaderLayer(final ILayer baseLayer, final ILayer verticalLayerDependency, final SelectionLayer selectionLayer, + public RowHeaderLayer(final Layer baseLayer, final Layer verticalLayerDependency, final SelectionLayer selectionLayer, final boolean useDefaultConfiguration) { this(baseLayer, verticalLayerDependency, selectionLayer, useDefaultConfiguration, null); } @@ -59,8 +62,9 @@ public class RowHeaderLayer extends AbstractPositionHeaderLayer { * @param layerPainter * The painter for this layer or <code>null</code> to use the painter of the base layer */ - public RowHeaderLayer(final ILayer baseLayer, final ILayer verticalLayerDependency, - final SelectionLayer selectionLayer, final boolean useDefaultConfiguration, final ILayerPainter layerPainter) { + public RowHeaderLayer(final Layer baseLayer, final Layer verticalLayerDependency, + final SelectionLayer selectionLayer, final boolean useDefaultConfiguration, + final LayerPainter layerPainter) { super(baseLayer, VERTICAL, verticalLayerDependency, selectionLayer, SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE, layerPainter ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/swt/CornerGridLineCellLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/swt/CornerGridLineCellLayerPainter.java new file mode 100644 index 00000000..b8480700 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/grid/swt/CornerGridLineCellLayerPainter.java @@ -0,0 +1,102 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.grid.swt; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; + +import java.util.function.Function; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.GridLineCellLayerPainter; + + +@NonNullByDefault +public class CornerGridLineCellLayerPainter extends GridLineCellLayerPainter { + + + public CornerGridLineCellLayerPainter(final Function<ConfigRegistry, Color> gridLineColorSupplier) { + super(gridLineColorSupplier); + } + + public CornerGridLineCellLayerPainter() { + super(); + } + + + private Layer getCornerLayer(final Layer layer) { + return layer.getUnderlyingLayerByPosition(0, 0).getUnderlyingLayerByPosition(0, 0); + } + + + @Override + protected void drawHorizontalLines(final Layer natLayer, final GC gc, final Rectangle rectangle) { + final int startX, endX; + { final LayerDim hDim= natLayer.getDim(HORIZONTAL); + startX= safe(rectangle.x + hDim.getPositionStart( + getCornerLayer(natLayer).getColumnCount() - 1 ) - 1 ); + endX= safe(rectangle.x + Math.min(hDim.getSize() - 1, rectangle.width)); + } + + final LayerDim dim= natLayer.getDim(VERTICAL); + final long lastPosition= getEndPosition(dim, rectangle.y + rectangle.height) - 1; + if (startX < endX) { + for (long position= dim.getPositionByPixel(rectangle.y); position < lastPosition; position++) { + final int size= dim.getPositionSize(position); + if (size > 0) { + final int y= safe(dim.getPositionStart(position) + dim.getPositionSize(position) - 1); + gc.drawLine(startX, y, endX, y); + } + } + } + { final int y= safe(dim.getPositionStart(lastPosition) + dim.getPositionSize(lastPosition) - 1); + gc.drawLine(safe(rectangle.x), y, endX, y); + } + } + + @Override + protected void drawVerticalLines(final Layer natLayer, final GC gc, final Rectangle rectangle) { + final int startY, endY; + { final LayerDim vDim= natLayer.getDim(VERTICAL); + startY= safe(rectangle.y + vDim.getPositionStart( + getCornerLayer(natLayer).getRowCount() - 1 ) - 1 ); + endY= safe(rectangle.y + Math.min(vDim.getSize() - 1, rectangle.height)); + } + + final LayerDim dim= natLayer.getDim(HORIZONTAL); + final long lastPosition= getEndPosition(dim, rectangle.x + rectangle.width) - 1; + if (startY < endY) { + for (long position= dim.getPositionByPixel(rectangle.x); position < lastPosition; position++) { + final int size= dim.getPositionSize(position); + if (size > 0) { + final int x= safe(dim.getPositionStart(position) + size - 1); + gc.drawLine(x, startY, x, endY); + } + } + } + { final int x= safe(dim.getPositionStart(lastPosition) + dim.getPositionSize(lastPosition) - 1); + gc.drawLine(x, safe(rectangle.y), x, endY); + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/StructuralRefreshCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/StructuralRefreshCommand.java index f8713984..a7f2002b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/StructuralRefreshCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/StructuralRefreshCommand.java @@ -11,30 +11,22 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.refresh.core; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; /** - * Command that triggers a {@link StructuralRefreshEvent}. + * Command that triggers a {@link GeneralStructuralChangeEvent}. * To support refreshing of every layer in a NatTable the * {@link StructuralRefreshCommandHandler} should be registered * against the DataLayer. */ -public class StructuralRefreshCommand implements ILayerCommand { - - @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - // no need for a check as the command simply triggers the firing of a StructuralRefreshEvent - return true; - } - - @Override - public ILayerCommand cloneCommand() { - // as the command doesn't have a state, the clone is simply a new instance - return new StructuralRefreshCommand(); - } - +@NonNullByDefault +public class StructuralRefreshCommand extends AbstractContextFreeCommand { + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/StructuralRefreshCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/StructuralRefreshCommandHandler.java index 72c52ff1..e7d846db 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/StructuralRefreshCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/StructuralRefreshCommandHandler.java @@ -11,15 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.refresh.core; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; /** * Command handler for handling {@link StructuralRefreshCommand}s. - * Simply fires a {@link StructuralRefreshEvent}. + * Simply fires a {@link GeneralStructuralChangeEvent}. * * Needed to be able to refresh all layers by simply calling a command on the NatTable * instance itself (Remember that events are fired bottom up the layer stack while commands @@ -29,17 +32,27 @@ import org.eclipse.statet.ecommons.waltable.layer.event.StructuralRefreshEvent; * instance, the {@link StructuralRefreshCommandHandler} should be registered against * the DataLayer. */ -public class StructuralRefreshCommandHandler implements ILayerCommandHandler<StructuralRefreshCommand> { - +@NonNullByDefault +public class StructuralRefreshCommandHandler implements LayerCommandHandler<StructuralRefreshCommand> { + + + private final Layer layer; + + + public StructuralRefreshCommandHandler(final Layer layer) { + this.layer= layer; + } + + @Override public Class<StructuralRefreshCommand> getCommandClass() { return StructuralRefreshCommand.class; } - + @Override - public boolean doCommand(final ILayer targetLayer, final StructuralRefreshCommand command) { - targetLayer.fireLayerEvent(new StructuralRefreshEvent(targetLayer)); + public boolean executeCommand(final StructuralRefreshCommand command) { + this.layer.fireLayerEvent(new GeneralStructuralChangeEvent(this.layer)); return false; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/VisualRefreshCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/VisualRefreshCommand.java index 2aeab226..66d2cd99 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/VisualRefreshCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/VisualRefreshCommand.java @@ -11,30 +11,22 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.refresh.core; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.VisualRefreshEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralVisualChangeEvent; /** - * Command that triggers a {@link VisualRefreshEvent}. + * Command that triggers a {@link GeneralVisualChangeEvent}. * To support refreshing of every layer in a NatTable the * {@link VisualRefreshCommandHandler} should be registered * against the DataLayer. */ -public class VisualRefreshCommand implements ILayerCommand { - - @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - // no need for a check as the command simply triggers the firing of a VisualRefreshEvent - return true; - } - - @Override - public ILayerCommand cloneCommand() { - // as the command doesn't have a state, the clone is simply a new instance - return new VisualRefreshCommand(); - } - +@NonNullByDefault +public class VisualRefreshCommand extends AbstractContextFreeCommand { + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/VisualRefreshCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/VisualRefreshCommandHandler.java index 402129a9..b47dc74b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/command/VisualRefreshCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/refresh/core/VisualRefreshCommandHandler.java @@ -11,15 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.command; +package org.eclipse.statet.ecommons.waltable.refresh.core; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.VisualRefreshEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralVisualChangeEvent; /** * Command handler for handling {@link VisualRefreshCommand}s. - * Simply fires a {@link VisualRefreshEvent}. + * Simply fires a {@link GeneralVisualChangeEvent}. * * Needed to be able to refresh all layers by simply calling a command on the NatTable * instance itself (Remember that events are fired bottom up the layer stack while commands @@ -29,16 +32,26 @@ import org.eclipse.statet.ecommons.waltable.layer.event.VisualRefreshEvent; * instance, the {@link VisualRefreshCommandHandler} should be registered against * the DataLayer. */ -public class VisualRefreshCommandHandler implements ILayerCommandHandler<VisualRefreshCommand> { - +@NonNullByDefault +public class VisualRefreshCommandHandler implements LayerCommandHandler<VisualRefreshCommand> { + + + private final Layer layer; + + + public VisualRefreshCommandHandler(final Layer layer) { + this.layer= layer; + } + + @Override public Class<VisualRefreshCommand> getCommandClass() { return VisualRefreshCommand.class; } - + @Override - public boolean doCommand(final ILayer targetLayer, final VisualRefreshCommand command) { - targetLayer.fireLayerEvent(new VisualRefreshEvent(targetLayer)); + public boolean executeCommand(final VisualRefreshCommand command) { + this.layer.fireLayerEvent(new GeneralVisualChangeEvent(this.layer)); return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEventMatcher.java index b66b5355..db7601a9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ColumnResizeEventMatcher.java @@ -13,16 +13,16 @@ package org.eclipse.statet.ecommons.waltable.resize; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; @@ -31,11 +31,11 @@ public class ColumnResizeEventMatcher extends MouseEventMatcher { public ColumnResizeEventMatcher(final int button, final boolean rowColumn) { - super(SWT.NONE, GridRegion.COLUMN_HEADER, (rowColumn) ? GridRegion.CORNER : null, button); + super(SWT.NONE, GridLabels.COLUMN_HEADER, (rowColumn) ? GridLabels.CORNER : null, button); } public ColumnResizeEventMatcher(final int button) { - this(SWT.NONE, GridRegion.COLUMN_HEADER, button); + this(SWT.NONE, GridLabels.COLUMN_HEADER, button); } public ColumnResizeEventMatcher(final int stateMask, final String eventRegion, final int button) { @@ -48,7 +48,7 @@ public class ColumnResizeEventMatcher extends MouseEventMatcher { return super.matches(natTable, event, regionLabels) && isResizable(natTable, event); } - private boolean isResizable(final ILayer natLayer, final MouseEvent event) { + private boolean isResizable(final Layer natLayer, final MouseEvent event) { final long columnPosition= CellEdgeDetectUtil.getPositionToResize(natLayer, new LPoint(event.x, event.y), HORIZONTAL ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/PositionResizeDragMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/PositionResizeDragMode.java index 8efdc468..2d8fbcb3 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/PositionResizeDragMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/PositionResizeDragMode.java @@ -13,23 +13,23 @@ package org.eclipse.statet.ecommons.waltable.resize; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.check; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.NatTableDim; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.painter.IOverlayPainter; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.NatTableLayerDim; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.top.OverlayPainter; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; +import org.eclipse.statet.ecommons.waltable.resize.core.DimPositionResizeCommand; import org.eclipse.statet.ecommons.waltable.ui.action.IDragMode; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; @@ -46,7 +46,7 @@ public class PositionResizeDragMode implements IDragMode { private static final int RESIZE_OVERLAY_SIZE= 2; - private static void addPositions(final long pixel, final ILayerDim dim, final LRangeList positions) { + private static void addPositions(final long pixel, final LayerDim dim, final LRangeList positions) { final long startPixel= Math.max(pixel - RESIZE_OVERLAY_SIZE / 2, 0); final long endPixel= Math.min(pixel + RESIZE_OVERLAY_SIZE / 2, dim.getSize() - 1); if (startPixel < endPixel) { @@ -55,25 +55,25 @@ public class PositionResizeDragMode implements IDragMode { } - private class ColumnResizeOverlayPainter implements IOverlayPainter { + private class ColumnResizeOverlayPainter implements OverlayPainter { @Override - public void paintOverlay(final GC gc, final ILayer layer) { + public void paintOverlay(final GC gc, final Layer layer) { final Color originalBackgroundColor= gc.getBackground(); gc.setBackground(GUIHelper.COLOR_DARK_GRAY); - gc.fillRectangle(PositionResizeDragMode.this.currentPixel - (RESIZE_OVERLAY_SIZE / 2), 0, RESIZE_OVERLAY_SIZE, check(layer.getHeight())); + gc.fillRectangle(PositionResizeDragMode.this.currentPixel - (RESIZE_OVERLAY_SIZE / 2), 0, RESIZE_OVERLAY_SIZE, SwtUtils.toSWT(layer.getHeight())); gc.setBackground(originalBackgroundColor); } } - private class RowResizeOverlayPainter implements IOverlayPainter { + private class RowResizeOverlayPainter implements OverlayPainter { @Override - public void paintOverlay(final GC gc, final ILayer layer) { + public void paintOverlay(final GC gc, final Layer layer) { final Color originalBackgroundColor= gc.getBackground(); gc.setBackground(GUIHelper.COLOR_DARK_GRAY); - gc.fillRectangle(0, PositionResizeDragMode.this.currentPixel - (RESIZE_OVERLAY_SIZE / 2), check(layer.getWidth()), RESIZE_OVERLAY_SIZE); + gc.fillRectangle(0, PositionResizeDragMode.this.currentPixel - (RESIZE_OVERLAY_SIZE / 2), SwtUtils.toSWT(layer.getWidth()), RESIZE_OVERLAY_SIZE); gc.setBackground(originalBackgroundColor); } } @@ -90,7 +90,7 @@ public class PositionResizeDragMode implements IDragMode { private int currentPixel; private int lastPixel= -1; - private final IOverlayPainter overlayPainter; + private final OverlayPainter overlayPainter; public PositionResizeDragMode(final Orientation orientation) { @@ -114,11 +114,11 @@ public class PositionResizeDragMode implements IDragMode { this.positionToResize= CellEdgeDetectUtil.getPositionToResize(natTable, new LPoint(event.x, event.y), this.orientation ); if (this.positionToResize >= 0) { - final ILayerDim dim= natTable.getDim(this.orientation); + final LayerDim layerDim= natTable.getDim(this.orientation); - this.positionStart= check(dim.getPositionStart(this.positionToResize)); - this.positionSize= dim.getPositionSize(this.positionToResize); - this.startPixel= SWTUtil.get(event, this.orientation); + this.positionStart= SwtUtils.toSWT(layerDim.getPositionStart(this.positionToResize)); + this.positionSize= layerDim.getPositionSize(this.positionToResize); + this.startPixel= SwtUtils.getPixel(event, this.orientation); natTable.addOverlayPainter(this.overlayPainter); } @@ -126,10 +126,10 @@ public class PositionResizeDragMode implements IDragMode { @Override public void mouseMove(final NatTable natTable, final MouseEvent event) { - final NatTableDim dim= natTable.getDim(this.orientation); + final NatTableLayerDim layerDim= natTable.getDim(this.orientation); - final int pixel= SWTUtil.get(event, this.orientation); - if (pixel > dim.getSize()) { + final int pixel= SwtUtils.getPixel(event, this.orientation); + if (pixel > layerDim.getSize()) { return; } @@ -141,12 +141,12 @@ public class PositionResizeDragMode implements IDragMode { final LRangeList positionsToRepaint= new LRangeList(); - addPositions(this.currentPixel, dim, positionsToRepaint); + addPositions(this.currentPixel, layerDim, positionsToRepaint); if (this.lastPixel >= 0) { - addPositions(this.lastPixel, dim, positionsToRepaint); + addPositions(this.lastPixel, layerDim, positionsToRepaint); } for (final LRange positions : positionsToRepaint) { - dim.repaintPositions(positions); + layerDim.repaintPositions(positions); } this.lastPixel= this.currentPixel; @@ -155,21 +155,22 @@ public class PositionResizeDragMode implements IDragMode { @Override public void mouseUp(final NatTable natTable, final MouseEvent event) { - final NatTableDim dim= natTable.getDim(this.orientation); + final NatTableLayerDim layerDim= natTable.getDim(this.orientation); natTable.removeOverlayPainter(this.overlayPainter); - updatePositionSize(dim, SWTUtil.get(event, this.orientation)); + updatePositionSize(layerDim, SwtUtils.getPixel(event, this.orientation)); } - private void updatePositionSize(final ILayerDim dim, final int pixel) { + private void updatePositionSize(final LayerDim layerDim, final int pixel) { final int dragSize= pixel - this.startPixel; int newSize= this.positionSize + dragSize; if (newSize < getMinPositionSize()) { newSize= getMinPositionSize(); } - dim.getLayer().doCommand(new DimPositionResizeCommand(dim, this.positionToResize, newSize)); + layerDim.getLayer().doCommand( + new DimPositionResizeCommand(layerDim, this.positionToResize, newSize) ); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/RowResizeEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/RowResizeEventMatcher.java index 76d54d30..b0db6ba9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/RowResizeEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/RowResizeEventMatcher.java @@ -13,16 +13,16 @@ package org.eclipse.statet.ecommons.waltable.resize; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; @@ -31,7 +31,7 @@ public class RowResizeEventMatcher extends MouseEventMatcher { public RowResizeEventMatcher(final int button) { - this(SWT.NONE, GridRegion.ROW_HEADER, button); + this(SWT.NONE, GridLabels.ROW_HEADER, button); } public RowResizeEventMatcher(final int stateMask, final String eventRegion, final int button) { @@ -44,7 +44,7 @@ public class RowResizeEventMatcher extends MouseEventMatcher { return super.matches(natTable, event, regionLabels) && isResizable(natTable, event); } - private boolean isResizable(final ILayer natLayer, final MouseEvent event) { + private boolean isResizable(final Layer natLayer, final MouseEvent event) { final long rowPosition= CellEdgeDetectUtil.getPositionToResize(natLayer, new LPoint(event.x, event.y), VERTICAL ); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/AutoResizePositionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/AutoResizePositionsCommand.java index 2e0cda22..c4355c62 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/AutoResizePositionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/AutoResizePositionsCommand.java @@ -11,12 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; /** @@ -27,10 +29,11 @@ import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; * Note: The {@link InitializeAutoResizeCommand} has to be fired first * when autoresizing columns. */ +@NonNullByDefault public class AutoResizePositionsCommand extends AbstractDimPositionsCommand { - public AutoResizePositionsCommand(final ILayerDim layerDim, final LRangeList columnPositions) { + public AutoResizePositionsCommand(final LayerDim layerDim, final LRangeList columnPositions) { super(layerDim, columnPositions); } @@ -39,7 +42,7 @@ public class AutoResizePositionsCommand extends AbstractDimPositionsCommand { } @Override - public ILayerCommand cloneCommand() { + public LayerCommand cloneCommand() { return new AutoResizePositionsCommand(this); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/DimPositionResizeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/DimPositionResizeCommand.java index 8f76955f..a4c72b78 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/DimPositionResizeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/DimPositionResizeCommand.java @@ -11,22 +11,25 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; /** * Event indicating that a column has been resized. */ +@NonNullByDefault public class DimPositionResizeCommand extends AbstractDimPositionCommand { private final int newSize; - public DimPositionResizeCommand(final ILayerDim layerDim, final long position, final int newSize) { + public DimPositionResizeCommand(final LayerDim layerDim, final long position, final int newSize) { super(layerDim, position); this.newSize= newSize; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/DimResizeEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/DimResizeEvent.java new file mode 100644 index 00000000..cf436301 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/DimResizeEvent.java @@ -0,0 +1,67 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.resize.core; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.events.DimPositionsStructuralChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff.DiffType; + + +@NonNullByDefault +public class DimResizeEvent extends DimPositionsStructuralChangeEvent { + + + public DimResizeEvent(final LayerDim layerDim, final LRange positions) { + super(layerDim, ImCollections.newList(positions)); + } + + public DimResizeEvent(final LayerDim layerDim, final List<LRange> positions) { + super(layerDim, positions); + } + + + @Override + protected @Nullable DimResizeEvent toLayer(final LayerDim targetLayerDim, + final List<LRange> positions) { + return new DimResizeEvent(targetLayerDim, positions); + } + + + @Override + public @Nullable List<StructuralDiff> getDiffs(final Orientation orientation) { + if (orientation == getOrientation()) { + final var diffs= new ArrayList<StructuralDiff>(); + + for (final LRange lRange : getPositionRanges()) { + diffs.add(new StructuralDiff(DiffType.CHANGE, lRange, lRange)); + } + + return diffs; + } + else { + return null; + } + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/InitializeAutoResizeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/InitializeAutoResizeCommand.java index 9620130c..3618f0fc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/InitializeAutoResizeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/InitializeAutoResizeCommand.java @@ -11,13 +11,15 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionCommand; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.grid.layer.GridLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** @@ -25,10 +27,11 @@ import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; * columns from the {@link SelectionLayer} and fires the * {@link AutoResizePositionsCommand} on the {@link GridLayer} */ +@NonNullByDefault public class InitializeAutoResizeCommand extends AbstractDimPositionCommand { - public InitializeAutoResizeCommand(final ILayerDim layer, final long position) { + public InitializeAutoResizeCommand(final LayerDim layer, final long position) { super(layer, position); } @@ -37,7 +40,7 @@ public class InitializeAutoResizeCommand extends AbstractDimPositionCommand { } @Override - public ILayerCommand cloneCommand() { + public LayerCommand cloneCommand() { return new InitializeAutoResizeCommand(this); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/InitializeAutoResizeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/InitializeAutoResizeCommandHandler.java index 4b707b42..7d219d29 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/InitializeAutoResizeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/InitializeAutoResizeCommandHandler.java @@ -11,15 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; + +@NonNullByDefault public class InitializeAutoResizeCommandHandler extends AbstractLayerCommandHandler<InitializeAutoResizeCommand> { @@ -38,13 +41,13 @@ public class InitializeAutoResizeCommandHandler extends AbstractLayerCommandHand @Override protected boolean doCommand(final InitializeAutoResizeCommand initCommand) { - final ILayerDim layerDim= initCommand.getDim(); + final LayerDim layerDim= initCommand.getDim(); final long position= initCommand.getPosition(); final LRangeList positions; - final long selectionPosition= LayerUtil.convertPosition(layerDim, + final long selectionPosition= LayerUtils.convertPosition(layerDim, position, position, this.selectionLayer.getDim(layerDim.getOrientation()) ); - if (selectionPosition != ILayerDim.POSITION_NA + if (selectionPosition != LayerDim.POSITION_NA && this.selectionLayer.isPositionFullySelected(layerDim.getOrientation(), position) ) { positions= this.selectionLayer.getFullySelectedPositions(layerDim.getOrientation()); @@ -57,7 +60,6 @@ public class InitializeAutoResizeCommandHandler extends AbstractLayerCommandHand layerDim.getLayer().doCommand(new AutoResizePositionsCommand(layerDim, positions)); } - // Fire command carrying the selected columns return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiColumnResizeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiColumnResizeCommand.java index aa7454a3..66f85845 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiColumnResizeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiColumnResizeCommand.java @@ -11,24 +11,28 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.command.LayerCommandUtil; import org.eclipse.statet.ecommons.waltable.coordinate.ColumnPositionCoordinate; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +@NonNullByDefault public class MultiColumnResizeCommand extends AbstractDimPositionsCommand { - + + private int commonColumnWidth= -1; protected Map<ColumnPositionCoordinate, Integer> colPositionToWidth= new HashMap<>(); @@ -36,7 +40,7 @@ public class MultiColumnResizeCommand extends AbstractDimPositionsCommand { /** * All columns are being resized to the same width e.g. during a drag resize */ - public MultiColumnResizeCommand(final ILayer layer, final Collection<LRange> columnPositions, final int commonColumnWidth) { + public MultiColumnResizeCommand(final Layer layer, final Collection<LRange> columnPositions, final int commonColumnWidth) { super(layer.getDim(HORIZONTAL), columnPositions); this.commonColumnWidth= commonColumnWidth; } @@ -44,7 +48,7 @@ public class MultiColumnResizeCommand extends AbstractDimPositionsCommand { /** * Each column is being resized to a different size e.g. during auto resize */ - public MultiColumnResizeCommand(final ILayer layer, final long[] columnPositions, final int[] columnWidths) { + public MultiColumnResizeCommand(final Layer layer, final long[] columnPositions, final int[] columnWidths) { super(layer.getDim(HORIZONTAL), new LRangeList(columnPositions)); for (int i= 0; i < columnPositions.length; i++) { this.colPositionToWidth.put(new ColumnPositionCoordinate(layer, columnPositions[i]), Integer.valueOf(columnWidths[i])); @@ -77,7 +81,7 @@ public class MultiColumnResizeCommand extends AbstractDimPositionsCommand { } @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { if (super.convertToTargetLayer(targetLayer)) { // Ensure that the width associated with the column is now associated with the converted // column position. diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiColumnResizeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiColumnResizeCommandHandler.java index 9ca1100b..b2cbe3e9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiColumnResizeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiColumnResizeCommandHandler.java @@ -11,14 +11,17 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.ILValueIterator; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList.ValueIterator; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.collections.LongIterator; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList.ValueIterator; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; + +@NonNullByDefault public class MultiColumnResizeCommandHandler extends AbstractLayerCommandHandler<MultiColumnResizeCommand> { @@ -36,7 +39,7 @@ public class MultiColumnResizeCommandHandler extends AbstractLayerCommandHandler @Override protected boolean doCommand(final MultiColumnResizeCommand command) { - for (final ILValueIterator columnIter= new ValueIterator(command.getPositions()); columnIter.hasNext(); ) { + for (final LongIterator columnIter= new ValueIterator(command.getPositions()); columnIter.hasNext(); ) { final long columnPosition= columnIter.nextValue(); this.dataLayer.setColumnWidthByPosition(columnPosition, command.getColumnWidth(columnPosition)); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiRowResizeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiRowResizeCommand.java index 04debfdf..67714092 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiRowResizeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiRowResizeCommand.java @@ -11,20 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand; import org.eclipse.statet.ecommons.waltable.command.LayerCommandUtil; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; import org.eclipse.statet.ecommons.waltable.coordinate.RowPositionCoordinate; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; public class MultiRowResizeCommand extends AbstractDimPositionsCommand { @@ -36,7 +36,7 @@ public class MultiRowResizeCommand extends AbstractDimPositionsCommand { /** * All rows are being resized to the same height e.g. during a drag resize */ - public MultiRowResizeCommand(final ILayer layer, final Collection<LRange> rowPositions, final int commonRowHeight) { + public MultiRowResizeCommand(final Layer layer, final Collection<LRange> rowPositions, final int commonRowHeight) { super(layer.getDim(VERTICAL), rowPositions); this.commonRowHeight= commonRowHeight; } @@ -44,7 +44,7 @@ public class MultiRowResizeCommand extends AbstractDimPositionsCommand { /** * Each row is being resized to a different size e.g. during auto resize */ - public MultiRowResizeCommand(final ILayer layer, final long[] rowPositions, final int[] rowHeights) { + public MultiRowResizeCommand(final Layer layer, final long[] rowPositions, final int[] rowHeights) { super(layer.getDim(VERTICAL), new LRangeList(rowPositions)); for (int i= 0; i < rowPositions.length; i++) { this.rowPositionToHeight.put(new RowPositionCoordinate(layer, rowPositions[i]), Integer.valueOf(rowHeights[i])); @@ -77,7 +77,7 @@ public class MultiRowResizeCommand extends AbstractDimPositionsCommand { } @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { + public boolean convertToTargetLayer(final Layer targetLayer) { if (super.convertToTargetLayer(targetLayer)) { // Ensure that the height associated with the row is now associated with the converted // row position. diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiRowResizeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiRowResizeCommandHandler.java index dcdf65b4..1d911b7c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/MultiRowResizeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/MultiRowResizeCommandHandler.java @@ -11,18 +11,23 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.ILValueIterator; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList.ValueIterator; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.collections.LongIterator; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList.ValueIterator; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; -public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<MultiRowResizeCommand> { +@NonNullByDefault +public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<MultiRowResizeCommand> { + + private final DataLayer dataLayer; - + + public MultiRowResizeCommandHandler(final DataLayer dataLayer) { this.dataLayer= dataLayer; } @@ -31,14 +36,14 @@ public class MultiRowResizeCommandHandler extends AbstractLayerCommandHandler<Mu public Class<MultiRowResizeCommand> getCommandClass() { return MultiRowResizeCommand.class; } - + @Override protected boolean doCommand(final MultiRowResizeCommand command) { - for (final ILValueIterator rowIter= new ValueIterator(command.getPositions()); rowIter.hasNext(); ) { + for (final LongIterator rowIter= new ValueIterator(command.getPositions()); rowIter.hasNext(); ) { final long rowPosition= rowIter.nextValue(); this.dataLayer.setRowHeightByPosition(rowPosition, command.getRowHeight(rowPosition)); } return true; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/PositionResizeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/PositionResizeCommandHandler.java index a3eb5e42..6e39979a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/PositionResizeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/core/PositionResizeCommandHandler.java @@ -11,14 +11,17 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize; +package org.eclipse.statet.ecommons.waltable.resize.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.DataLayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.data.core.DataLayer; + +@NonNullByDefault public class PositionResizeCommandHandler extends AbstractLayerCommandHandler<DimPositionResizeCommand> { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/AutoResizeColumnAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/AutoResizeColumnAction.java index 07770dda..6746c674 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/AutoResizeColumnAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/AutoResizeColumnAction.java @@ -11,15 +11,15 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.action; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.resize.InitializeAutoResizeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.resize.core.InitializeAutoResizeCommand; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/AutoResizeRowAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/AutoResizeRowAction.java index 607572a5..dc1f3459 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/AutoResizeRowAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/AutoResizeRowAction.java @@ -11,15 +11,15 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.action; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.resize.InitializeAutoResizeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.resize.core.InitializeAutoResizeCommand; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/ColumnResizeCursorAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/ColumnResizeCursorAction.java index 4b72a6b4..65445f6f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/ColumnResizeCursorAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/ColumnResizeCursorAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.action; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/config/DefaultColumnResizeBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/DefaultColumnResizeBindings.java index ef67db7a..c6d04d2a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/config/DefaultColumnResizeBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/DefaultColumnResizeBindings.java @@ -11,15 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.config; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; import org.eclipse.statet.ecommons.waltable.resize.ColumnResizeEventMatcher; import org.eclipse.statet.ecommons.waltable.resize.PositionResizeDragMode; -import org.eclipse.statet.ecommons.waltable.resize.action.AutoResizeColumnAction; -import org.eclipse.statet.ecommons.waltable.resize.action.ColumnResizeCursorAction; import org.eclipse.statet.ecommons.waltable.ui.action.ClearCursorAction; import org.eclipse.statet.ecommons.waltable.ui.action.NoOpMouseAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/config/DefaultRowResizeBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/DefaultRowResizeBindings.java index 8fe8a9d6..f3b7591b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/config/DefaultRowResizeBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/DefaultRowResizeBindings.java @@ -11,15 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.config; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; import org.eclipse.statet.ecommons.waltable.resize.PositionResizeDragMode; import org.eclipse.statet.ecommons.waltable.resize.RowResizeEventMatcher; -import org.eclipse.statet.ecommons.waltable.resize.action.AutoResizeRowAction; -import org.eclipse.statet.ecommons.waltable.resize.action.RowResizeCursorAction; import org.eclipse.statet.ecommons.waltable.ui.action.ClearCursorAction; import org.eclipse.statet.ecommons.waltable.ui.action.NoOpMouseAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/RowResizeCursorAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/RowResizeCursorAction.java index a3bab5b8..5ff6a34a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/resize/action/RowResizeCursorAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/resize/ui/action/RowResizeCursorAction.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.resize.action; +package org.eclipse.statet.ecommons.waltable.resize.ui.action; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultMoveSelectionConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultMoveSelectionConfiguration.java index bade097d..cf1ebef6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultMoveSelectionConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultMoveSelectionConfiguration.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.selection.config; import org.eclipse.statet.ecommons.waltable.config.AbstractLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionBindings.java index 46a28c14..66e15358 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionBindings.java @@ -16,10 +16,10 @@ package org.eclipse.statet.ecommons.waltable.selection.config; import org.eclipse.swt.SWT; import org.eclipse.statet.ecommons.waltable.config.AbstractUiBindingConfiguration; -import org.eclipse.statet.ecommons.waltable.copy.action.CopyDataAction; -import org.eclipse.statet.ecommons.waltable.selection.action.CellSelectionDragMode; -import org.eclipse.statet.ecommons.waltable.selection.action.SelectAllAction; -import org.eclipse.statet.ecommons.waltable.selection.action.SelectCellAction; +import org.eclipse.statet.ecommons.waltable.copy.ui.action.CopyDataAction; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.CellSelectionDragMode; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.SelectAllAction; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.SelectCellAction; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.KeyEventMatcher; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionLayerConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionLayerConfiguration.java index d3eb9121..30381b33 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionLayerConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionLayerConfiguration.java @@ -14,7 +14,7 @@ package org.eclipse.statet.ecommons.waltable.selection.config; import org.eclipse.statet.ecommons.waltable.config.AggregateConfiguration; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; import org.eclipse.statet.ecommons.waltable.tickupdate.config.DefaultTickUpdateConfiguration; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java new file mode 100644 index 00000000..43cc6297 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/DefaultSelectionStyleConfiguration.java @@ -0,0 +1,126 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.selection.config; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; + +import org.eclipse.statet.ecommons.waltable.config.AbstractRegistryConfiguration; +import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.style.BasicStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle.LineStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; +import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; +import org.eclipse.statet.ecommons.waltable.util.GUIHelper; + + +/** + * Sets up rendering style used for selected areas and the selection anchor. + */ +public class DefaultSelectionStyleConfiguration extends AbstractRegistryConfiguration { + + // Selection style + public Font selectionFont= GUIHelper.getFont(new FontData("Verdana", 8, SWT.BOLD | SWT.ITALIC)); //$NON-NLS-1$ + public Color selectionBgColor= GUIHelper.COLOR_TITLE_INACTIVE_BACKGROUND; + public Color selectionFgColor= GUIHelper.COLOR_BLACK; + + // Anchor style + public Color anchorBorderColor= GUIHelper.COLOR_DARK_GRAY; + public BorderStyle anchorBorderStyle= new BorderStyle(1, this.anchorBorderColor, LineStyle.SOLID); + public Color anchorBgColor= GUIHelper.COLOR_GRAY; + public Color anchorFgColor= GUIHelper.COLOR_WHITE; + + // Selected headers style + public Color selectedHeaderBgColor= GUIHelper.COLOR_GRAY; + public Color selectedHeaderFgColor= GUIHelper.COLOR_WHITE; + public Font selectedHeaderFont= GUIHelper.getFont(new FontData("Verdana", 10, SWT.BOLD)); //$NON-NLS-1$ + public BorderStyle selectedHeaderBorderStyle= new BorderStyle(-1, this.selectedHeaderFgColor, LineStyle.SOLID); + + // Anchor grid line style + public Color anchorGridBorderColor= GUIHelper.COLOR_BLACK; + public BorderStyle anchorGridBorderStyle= new BorderStyle(1, this.anchorGridBorderColor, LineStyle.DOTTED); + + + @Override + public void configureRegistry(final ConfigRegistry configRegistry) { + configureSelectionStyle(configRegistry); + configureSelectionAnchorStyle(configRegistry); + configureSelectionAnchorGridLineStyle(configRegistry); + configureHeaderHasSelectionStyle(configRegistry); + configureHeaderFullySelectedStyle(configRegistry); + } + + protected void configureSelectionStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.FONT, this.selectionFont); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.selectionBgColor); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.selectionFgColor); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED ); + } + + protected void configureSelectionAnchorStyle(final ConfigRegistry configRegistry) { + // Selection anchor style for normal display mode + BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.anchorBorderStyle); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.NORMAL, SelectionStyleLabels.SELECTION_ANCHOR_STYLE ); + + // Selection anchor style for select display mode + cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.anchorBgColor); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.anchorFgColor); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.anchorBorderStyle); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, SelectionStyleLabels.SELECTION_ANCHOR_STYLE ); + } + + protected void configureSelectionAnchorGridLineStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.anchorGridBorderStyle); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE ); + } + + protected void configureHeaderHasSelectionStyle(final ConfigRegistry configRegistry) { + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.FOREGROUND_COLOR, this.selectedHeaderFgColor); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, this.selectedHeaderBgColor); + cellStyle.setAttributeValue(CellStyling.FONT, this.selectedHeaderFont); + cellStyle.setAttributeValue(CellStyling.BORDER_STYLE, this.selectedHeaderBorderStyle); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, GridLabels.COLUMN_HEADER ); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, GridLabels.CORNER ); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, GridLabels.ROW_HEADER ); + } + + protected void configureHeaderFullySelectedStyle(final ConfigRegistry configRegistry) { + // Header fully selected + final BasicStyle cellStyle= new BasicStyle(); + cellStyle.setAttributeValue(CellStyling.BACKGROUND_COLOR, GUIHelper.COLOR_WIDGET_NORMAL_SHADOW); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE); + configRegistry.registerAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, + DisplayMode.SELECTED, SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE); + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionBindings.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionBindings.java index a0ec2a8c..69d20d73 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionBindings.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionBindings.java @@ -15,8 +15,8 @@ package org.eclipse.statet.ecommons.waltable.selection.config; import org.eclipse.swt.SWT; -import org.eclipse.statet.ecommons.waltable.selection.action.RowSelectionDragMode; -import org.eclipse.statet.ecommons.waltable.selection.action.SelectRowAction; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.RowSelectionDragMode; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.SelectRowAction; import org.eclipse.statet.ecommons.waltable.ui.action.IDragMode; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionConfiguration.java index 2b4312b3..0e93ca91 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/config/RowOnlySelectionConfiguration.java @@ -14,13 +14,12 @@ package org.eclipse.statet.ecommons.waltable.selection.config; import org.eclipse.statet.ecommons.waltable.config.AbstractLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEventHandler; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** * Configure the move selection behavior so that we always move by a row. - * Add {@link ILayerEventHandler} to preserve row selection. + * Add {@link LayerEventHandler} to preserve row selection. * * @see DefaultMoveSelectionConfiguration */ diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/AbstractSelectDimPositionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/AbstractSelectDimPositionsCommand.java index 537645f8..f4a62f06 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/AbstractSelectDimPositionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/AbstractSelectDimPositionsCommand.java @@ -12,20 +12,23 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; import java.util.Collection; import java.util.Collections; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; /** * Abstract command to select column(s)/row(s). */ +@NonNullByDefault public abstract class AbstractSelectDimPositionsCommand extends AbstractDimPositionsCommand { @@ -34,18 +37,18 @@ public abstract class AbstractSelectDimPositionsCommand extends AbstractDimPosit private long positionToReveal; - public AbstractSelectDimPositionsCommand(final ILayerDim dim, + public AbstractSelectDimPositionsCommand(final LayerDim layerDim, final long position, final int selectionFlags) { - this(dim, position, + this(layerDim, position, Collections.singletonList(new LRange(position)), position, selectionFlags ); } - public AbstractSelectDimPositionsCommand(final ILayerDim dim, + public AbstractSelectDimPositionsCommand(final LayerDim layerDim, final long refPosition, final Collection<LRange> positions, final long positionToReveal, final int selectionFlags) { - super(dim, refPosition, positions); + super(layerDim, refPosition, positions); this.positionToReveal= positionToReveal; this.selectionFlags= selectionFlags; @@ -69,13 +72,13 @@ public abstract class AbstractSelectDimPositionsCommand extends AbstractDimPosit @Override - protected boolean convertToTargetLayer(final ILayerDim dim, final long refPosition, - final ILayerDim targetDim) { + protected boolean convertToTargetLayer(final LayerDim dim, final long refPosition, + final LayerDim targetDim) { if (super.convertToTargetLayer(dim, refPosition, targetDim)) { if (this.positionToReveal != Long.MIN_VALUE) { this.positionToReveal= (this.positionToReveal == refPosition) ? getRefPosition() : - LayerUtil.convertPosition(dim, refPosition, this.positionToReveal, + LayerUtils.convertPosition(dim, refPosition, this.positionToReveal, targetDim ); } return true; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/AbstractSelectRelativeCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/AbstractSelectRelativeCommand.java index a5b02eb8..9da74ff7 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/AbstractSelectRelativeCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/AbstractSelectRelativeCommand.java @@ -12,36 +12,30 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractRelativeCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public abstract class AbstractSelectRelativeCommand extends AbstractRelativeCommand { +import org.eclipse.statet.ecommons.waltable.core.command.AbstractRelativeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +@NonNullByDefault +public abstract class AbstractSelectRelativeCommand extends AbstractRelativeCommand { + + private final int selectionFlags; - - + + protected AbstractSelectRelativeCommand(final Direction direction, final long stepCount, final int selectionFlags) { super(direction, stepCount); this.selectionFlags= selectionFlags; } - - protected AbstractSelectRelativeCommand(final AbstractSelectRelativeCommand command) { - super(command); - - this.selectionFlags= command.selectionFlags; - } - - @Override - public abstract AbstractSelectRelativeCommand cloneCommand(); - - + + public int getSelectionFlags() { return this.selectionFlags; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionModel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/BasicSelectionModel.java index c0020998..48357287 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionModel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/BasicSelectionModel.java @@ -11,7 +11,9 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; import java.util.ArrayList; import java.util.LinkedList; @@ -19,11 +21,14 @@ import java.util.List; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -37,12 +42,13 @@ import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; * * @see SelectionLayer */ -public class SelectionModel implements ISelectionModel { +@NonNullByDefault +public class BasicSelectionModel implements SelectionModel { //-- Utility --// - private static final LRectangle getLeftSelection(final LRectangle intersection, final LRectangle selection) { + private static final @Nullable LRectangle getLeftSelection(final LRectangle intersection, final LRectangle selection) { if (intersection.x > selection.x) { return new LRectangle(selection.x, selection.y, intersection.x - selection.x, selection.height); @@ -50,7 +56,7 @@ public class SelectionModel implements ISelectionModel { return null; } - private static final LRectangle getRightSelection(final LRectangle intersection, final LRectangle selection) { + private static final @Nullable LRectangle getRightSelection(final LRectangle intersection, final LRectangle selection) { final long newX= intersection.x + intersection.width; if (newX < selection.x + selection.width) { return new LRectangle(newX, selection.y, @@ -59,7 +65,7 @@ public class SelectionModel implements ISelectionModel { return null; } - private static final LRectangle getTopSelection(final LRectangle intersection, final LRectangle selection) { + private static final @Nullable LRectangle getTopSelection(final LRectangle intersection, final LRectangle selection) { if (intersection.y > selection.y) { return new LRectangle(selection.x, selection.y, selection.width, intersection.y - selection.y); @@ -67,7 +73,7 @@ public class SelectionModel implements ISelectionModel { return null; } - private static final LRectangle getBottomSelection(final LRectangle intersection, final LRectangle selection) { + private static final @Nullable LRectangle getBottomSelection(final LRectangle intersection, final LRectangle selection) { final long newY= intersection.y + intersection.height; if (newY < selection.y + selection.height) { return new LRectangle(selection.x, newY, @@ -77,7 +83,7 @@ public class SelectionModel implements ISelectionModel { } - private final ILayer selectionLayer; + private final Layer selectionLayer; private boolean multipleSelectionAllowed; @@ -85,15 +91,12 @@ public class SelectionModel implements ISelectionModel { private final ReadWriteLock selectionsLock; - public SelectionModel(/*@NotNull*/ final ILayer selectionLayer) { + public BasicSelectionModel(final Layer selectionLayer) { this(selectionLayer, true); } - public SelectionModel(/*@NotNull*/ final ILayer selectionLayer, final boolean multipleSelectionAllowed) { - if (selectionLayer == null) { - throw new NullPointerException("selectionLayer"); //$NON-NLS-1$ - } - this.selectionLayer= selectionLayer; + public BasicSelectionModel(final Layer selectionLayer, final boolean multipleSelectionAllowed) { + this.selectionLayer= nonNullAssert(selectionLayer); this.multipleSelectionAllowed= multipleSelectionAllowed; this.selections= new LinkedList<>(); @@ -142,7 +145,8 @@ public class SelectionModel implements ISelectionModel { } itemsToRemove.add(r); - } else if (intersection.equals(selection)) { + } + else if (intersection.equals(selection)) { // selection is a subset of r break; } @@ -152,7 +156,8 @@ public class SelectionModel implements ISelectionModel { if (itemsToRemove != null) { this.selections.removeAll(itemsToRemove); } - } else { + } + else { this.selections.clear(); //as no multiple selection is allowed, ensure that only one column //and one row will be selected @@ -161,7 +166,8 @@ public class SelectionModel implements ISelectionModel { } this.selections.add(selection); - } finally { + } + finally { this.selectionsLock.writeLock().unlock(); } } @@ -171,7 +177,8 @@ public class SelectionModel implements ISelectionModel { this.selectionsLock.writeLock().lock(); try { this.selections.clear(); - } finally { + } + finally { this.selectionsLock.writeLock().unlock(); } } @@ -219,7 +226,8 @@ public class SelectionModel implements ISelectionModel { this.selectionsLock.writeLock().lock(); try { this.selections.removeAll(removedItems); - } finally { + } + finally { this.selectionsLock.writeLock().unlock(); } @@ -230,7 +238,8 @@ public class SelectionModel implements ISelectionModel { this.selectionsLock.writeLock().lock(); try { this.selections.addAll(addedItems); - } finally { + } + finally { this.selectionsLock.writeLock().unlock(); } @@ -244,7 +253,8 @@ public class SelectionModel implements ISelectionModel { this.selectionsLock.readLock().lock(); try { return this.selections.isEmpty(); - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -257,7 +267,7 @@ public class SelectionModel implements ISelectionModel { // Cell features @Override - public boolean isCellPositionSelected(final ILayerCell cell) { + public boolean isCellPositionSelected(final LayerCell cell) { this.selectionsLock.readLock().lock(); try { final LRectangle cellRectangle= new LRectangle( @@ -273,7 +283,8 @@ public class SelectionModel implements ISelectionModel { } return false; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -294,7 +305,8 @@ public class SelectionModel implements ISelectionModel { } return selected; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -314,7 +326,8 @@ public class SelectionModel implements ISelectionModel { } return false; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -338,7 +351,8 @@ public class SelectionModel implements ISelectionModel { } return selected; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -351,7 +365,8 @@ public class SelectionModel implements ISelectionModel { return ((rowCount > 0) && isColumnPositionFullySelected(columnPosition, rowCount) ); - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -391,7 +406,8 @@ public class SelectionModel implements ISelectionModel { } return selected; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -411,7 +427,8 @@ public class SelectionModel implements ISelectionModel { } return false; - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -449,7 +466,8 @@ public class SelectionModel implements ISelectionModel { return ((columnCount > 0) && isRowPositionFullySelected(rowPosition, columnCount) ); - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } @@ -475,7 +493,8 @@ public class SelectionModel implements ISelectionModel { this.selectionsLock.readLock().lock(); try { return this.selections.toString(); - } finally { + } + finally { this.selectionsLock.readLock().unlock(); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/CellSelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/CellSelectionEvent.java index 052e086d..343f247d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/CellSelectionEvent.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/CellSelectionEvent.java @@ -11,35 +11,44 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.event.CellVisualChangeEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.CellVisualChangeEvent; -public class CellSelectionEvent extends CellVisualChangeEvent implements ISelectionEvent { + +@NonNullByDefault +public class CellSelectionEvent extends CellVisualChangeEvent implements SelectionEvent { + private final SelectionLayer selectionLayer; private final boolean revealCell; - public CellSelectionEvent(final SelectionLayer selectionLayer, final long columnPosition, final long rowPosition, + public CellSelectionEvent(final SelectionLayer selectionLayer, + final long columnPosition, final long rowPosition, final boolean revealCell) { super(selectionLayer, columnPosition, rowPosition); this.selectionLayer= selectionLayer; this.revealCell= revealCell; } - protected CellSelectionEvent(final CellSelectionEvent event) { - super(event); - this.selectionLayer= event.selectionLayer; - this.revealCell= event.revealCell; + protected CellSelectionEvent(final SelectionLayer selectionLayer, + final Layer layer, final long columnPosition, final long rowPosition, final boolean revealCell) { + super(layer, columnPosition, rowPosition); + this.selectionLayer= selectionLayer; + this.revealCell= revealCell; } @Override - public CellSelectionEvent cloneEvent() { - return new CellSelectionEvent(this); + protected @Nullable CellSelectionEvent toLayer(final Layer targetLayer, + final long columnPosition, final long rowPosition) { + return new CellSelectionEvent(this.selectionLayer, + targetLayer, columnPosition, rowPosition, this.revealCell ); } @@ -52,12 +61,4 @@ public class CellSelectionEvent extends CellVisualChangeEvent implements ISelect return this.revealCell; } - @Override - public boolean convertToLocal(final ILayer localLayer) { - if(this.columnPosition == SelectionLayer.NO_SELECTION || this.rowPosition == SelectionLayer.NO_SELECTION){ - return true; - } - return super.convertToLocal(localLayer); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ClearAllSelectionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/ClearAllSelectionsCommand.java index 3e34356d..12243a5e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ClearAllSelectionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/ClearAllSelectionsCommand.java @@ -11,17 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public class ClearAllSelectionsCommand extends AbstractContextFreeCommand { +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +@NonNullByDefault +public class ClearAllSelectionsCommand extends AbstractContextFreeCommand { + + public ClearAllSelectionsCommand() { super(); } - - + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/DimSelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/DimSelectionEvent.java new file mode 100644 index 00000000..59b04e82 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/DimSelectionEvent.java @@ -0,0 +1,81 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.selection.core; + +import static org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer.NO_SELECTION; + +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.events.DimPositionsVisualChangeEvent; + + +@NonNullByDefault +public class DimSelectionEvent extends DimPositionsVisualChangeEvent implements SelectionEvent { + + + private final SelectionLayer selectionLayer; + + private final long positionToReveal; + + + public DimSelectionEvent(final SelectionLayer selectionLayer, final Orientation orientation, + final long position, final boolean revealPosition) { + this(selectionLayer, orientation, new LRangeList(position), + (revealPosition) ? position : NO_SELECTION ); + } + + public DimSelectionEvent(final SelectionLayer selectionLayer, final Orientation orientation, + final List<LRange> positions, final long positionToReveal) { + super(selectionLayer.getDim(orientation), positions); + this.selectionLayer= selectionLayer; + this.positionToReveal= positionToReveal; + } + + protected DimSelectionEvent(final SelectionLayer selectionLayer, final LayerDim layerDim, + final List<LRange> positions, final long positionToReveal) { + super(layerDim, positions); + this.selectionLayer= selectionLayer; + this.positionToReveal= positionToReveal; + } + + @Override + protected @Nullable DimPositionsVisualChangeEvent toLayer(final LayerDim targetLayerDim, + final List<LRange> positions) { + final long positionToReveal= (this.positionToReveal != NO_SELECTION) ? + targetLayerDim.underlyingToLocalPosition( + getLayerDim(), this.positionToReveal ) : + NO_SELECTION; + + return new DimSelectionEvent(this.selectionLayer, targetLayerDim, + positions, positionToReveal ); + } + + + @Override + public SelectionLayer getSelectionLayer() { + return this.selectionLayer; + } + + public long getPositionToReveal() { + return this.positionToReveal; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/EmptySelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/EmptySelectionEvent.java new file mode 100644 index 00000000..87dd6fe7 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/EmptySelectionEvent.java @@ -0,0 +1,57 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.selection.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralVisualChangeEvent; + + +@NonNullByDefault +public class EmptySelectionEvent extends GeneralVisualChangeEvent implements SelectionEvent { + + + private final SelectionLayer selectionLayer; + + + public EmptySelectionEvent(final SelectionLayer selectionLayer) { + super(selectionLayer); + this.selectionLayer= selectionLayer; + } + + protected EmptySelectionEvent(final SelectionLayer selectionLayer, final Layer layer) { + super(layer); + this.selectionLayer= selectionLayer; + } + + @Override + public @Nullable GeneralVisualChangeEvent toLayer(final Layer targetLayer) { + if (targetLayer == getLayer()) { + return this; + } + + return new EmptySelectionEvent(this.selectionLayer, targetLayer); + } + + + @Override + public SelectionLayer getSelectionLayer() { + return this.selectionLayer; + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectAllCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectAllCommand.java index 64bb22bb..06c2e683 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectAllCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectAllCommand.java @@ -11,16 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public class SelectAllCommand extends AbstractContextFreeCommand { +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; +@NonNullByDefault +public class SelectAllCommand extends AbstractContextFreeCommand { + + public SelectAllCommand() { } - - + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectCellCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectCellCommand.java index f204586a..d2b23714 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectCellCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectCellCommand.java @@ -11,10 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.ecommons.waltable.command.AbstractPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; /** @@ -25,46 +27,47 @@ import org.eclipse.statet.ecommons.waltable.layer.ILayer; * clicked. Do not pass it anything else or you will introduce very subtle and very difficult to debug bugs into the * code and then we will have to pay you a visit on one random Sunday morning when you least expect it.</strong> */ +@NonNullByDefault public class SelectCellCommand extends AbstractPositionCommand { - - + + private final int selectionFlags; - + private final boolean revealCell; - - - public SelectCellCommand(final ILayer layer, final long columnPosition, final long rowPosition, + + + public SelectCellCommand(final Layer layer, final long columnPosition, final long rowPosition, final int selectionFlags) { this(layer, columnPosition, rowPosition, selectionFlags, true); } - - public SelectCellCommand(final ILayer layer, final long columnPosition, final long rowPosition, + + public SelectCellCommand(final Layer layer, final long columnPosition, final long rowPosition, final int selectionFlags, final boolean revealCell) { super(layer, columnPosition, rowPosition); this.selectionFlags= selectionFlags; this.revealCell= revealCell; } - + protected SelectCellCommand(final SelectCellCommand command) { super(command); this.selectionFlags= command.selectionFlags; this.revealCell= command.revealCell; } - + @Override public SelectCellCommand cloneCommand() { return new SelectCellCommand(this); } - - + + public int getSelectionFlags() { return this.selectionFlags; } - + public boolean getRevealCell() { return this.revealCell; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectCellCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectCellCommandHandler.java index 0dc296bf..a98afd94 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectCellCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectCellCommandHandler.java @@ -11,23 +11,26 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public class SelectCellCommandHandler extends AbstractLayerCommandHandler<SelectCellCommand> { +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +@NonNullByDefault +public class SelectCellCommandHandler extends AbstractLayerCommandHandler<SelectCellCommand> { + + private final SelectionLayer selectionLayer; - - + + public SelectCellCommandHandler(final SelectionLayer selectionLayer) { this.selectionLayer= selectionLayer; } - - + + @Override public Class<SelectCellCommand> getCommandClass() { return SelectCellCommand.class; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectDimPositionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectDimPositionsCommand.java index 17f6d8fa..92742986 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectDimPositionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectDimPositionsCommand.java @@ -11,18 +11,21 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; import java.util.Collection; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionsCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.LayerUtil; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerUtils; + +@NonNullByDefault public class SelectDimPositionsCommand extends AbstractDimPositionsCommand { @@ -33,14 +36,14 @@ public class SelectDimPositionsCommand extends AbstractDimPositionsCommand { private long positionToReveal; - public SelectDimPositionsCommand(final ILayerDim layerDim, + public SelectDimPositionsCommand(final LayerDim layerDim, final long position, final long orthogonalPosition, final int selectionFlags) { this(layerDim, position, new LRangeList(position), orthogonalPosition, selectionFlags, position ); } - public SelectDimPositionsCommand(final ILayerDim layerDim, + public SelectDimPositionsCommand(final LayerDim layerDim, final long refPosition, final Collection<LRange> positions, final long orthogonalPosition, final int selectionFlags, final long positionToReveal) { super(layerDim, refPosition, positions); @@ -65,16 +68,16 @@ public class SelectDimPositionsCommand extends AbstractDimPositionsCommand { @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - final ILayerDim layerDim= getDim(); - final long targetOrthogonalPosition= LayerUtil.convertPosition( + public boolean convertToTargetLayer(final Layer targetLayer) { + final LayerDim layerDim= getDim(); + final long targetOrthogonalPosition= LayerUtils.convertPosition( layerDim.getLayer().getDim(getOrientation().getOrthogonal()), this.orthogonalPosition, this.orthogonalPosition, targetLayer.getDim(getOrientation().getOrthogonal()) ); - if (targetOrthogonalPosition != ILayerDim.POSITION_NA + if (targetOrthogonalPosition != LayerDim.POSITION_NA && super.convertToTargetLayer(targetLayer) ) { this.orthogonalPosition= targetOrthogonalPosition; - this.positionToReveal= LayerUtil.convertPosition(layerDim, + this.positionToReveal= LayerUtils.convertPosition(layerDim, this.positionToReveal, this.positionToReveal, targetLayer.getDim(getOrientation()) ); return true; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectDimPositionsCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectDimPositionsCommandHandler.java index f1fffc9d..d5a344b6 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectDimPositionsCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectDimPositionsCommandHandler.java @@ -11,16 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; + +@NonNullByDefault public class SelectDimPositionsCommandHandler extends AbstractLayerCommandHandler<SelectDimPositionsCommand> { @@ -63,7 +67,7 @@ public class SelectDimPositionsCommandHandler extends AbstractLayerCommandHandle final LRectangle columnRegion= new LRectangle( singleColumnPosition, 0, 1, this.selectionLayer.getRowCount()); this.selectionLayer.clearSelection(columnRegion); - this.selectionLayer.fireLayerEvent(new ColumnSelectionEvent(this.selectionLayer, + this.selectionLayer.fireLayerEvent(new DimSelectionEvent(this.selectionLayer, HORIZONTAL, singleColumnPosition, (columnPositionToReveal == singleColumnPosition) )); return; } @@ -118,7 +122,7 @@ public class SelectDimPositionsCommandHandler extends AbstractLayerCommandHandle } // TODO correct change set - this.selectionLayer.fireLayerEvent(new ColumnSelectionEvent(this.selectionLayer, + this.selectionLayer.fireLayerEvent(new DimSelectionEvent(this.selectionLayer, HORIZONTAL, columnPositions, columnPositionToReveal )); } @@ -133,7 +137,8 @@ public class SelectDimPositionsCommandHandler extends AbstractLayerCommandHandle final LRectangle columnRegion= new LRectangle( 0, singleRowPosition, this.selectionLayer.getColumnCount(), 1); this.selectionLayer.clearSelection(columnRegion); - this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, singleRowPosition, false)); + this.selectionLayer.fireLayerEvent(new DimSelectionEvent(this.selectionLayer, VERTICAL, + singleRowPosition, false )); return; } selectRows(columnPosition, rowPositions, selectionFlags, rowPositionToShow); @@ -192,7 +197,8 @@ public class SelectDimPositionsCommandHandler extends AbstractLayerCommandHandle this.selectionLayer.lastSelectedCell.rowPosition= lastPosition; } - this.selectionLayer.fireLayerEvent(new RowSelectionEvent(this.selectionLayer, changedRowRanges, rowPositionToShow)); + this.selectionLayer.fireLayerEvent(new DimSelectionEvent(this.selectionLayer, VERTICAL, + changedRowRanges, rowPositionToShow )); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectRelativeCellCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectRelativeCellCommand.java index df6cdb83..7f12d1a4 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectRelativeCellCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectRelativeCellCommand.java @@ -12,14 +12,17 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public class SelectRelativeCellCommand extends AbstractSelectRelativeCommand { +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +@NonNullByDefault +public class SelectRelativeCellCommand extends AbstractSelectRelativeCommand { + + public SelectRelativeCellCommand(final Direction direction) { this(direction, 1, 0); } @@ -27,15 +30,6 @@ public class SelectRelativeCellCommand extends AbstractSelectRelativeCommand { public SelectRelativeCellCommand(final Direction direction, final long stepCount, final int selectionFlags) { super(direction, stepCount, selectionFlags); } - - protected SelectRelativeCellCommand(final SelectRelativeCellCommand command) { - super(command); - } - - @Override - public SelectRelativeCellCommand cloneCommand() { - return new SelectRelativeCellCommand(this); - } - - + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectRelativeCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectRelativeCommandHandler.java index 3757c070..e58373aa 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectRelativeCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectRelativeCommandHandler.java @@ -12,35 +12,38 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; - -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +package org.eclipse.statet.ecommons.waltable.selection.core; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -public class SelectRelativeCommandHandler extends AbstractLayerCommandHandler<SelectRelativeCellCommand> { +import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +@NonNullByDefault +public class SelectRelativeCommandHandler implements LayerCommandHandler<SelectRelativeCellCommand> { + + protected final SelectionLayer selectionLayer; - - + + public SelectRelativeCommandHandler(final SelectionLayer selectionLayer) { this.selectionLayer= selectionLayer; } - - + + @Override public Class<SelectRelativeCellCommand> getCommandClass() { return SelectRelativeCellCommand.class; } - - + + @Override - protected boolean doCommand(final SelectRelativeCellCommand command) { + public boolean executeCommand(final SelectRelativeCellCommand command) { select(command); return true; } - + protected boolean select(final SelectRelativeCellCommand command) { long row; long column; @@ -141,5 +144,5 @@ public class SelectRelativeCommandHandler extends AbstractLayerCommandHandler<Se this.selectionLayer.fireCellSelectionEvent(column, row, true); return true; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ISelectionEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionEvent.java index 4e12c7ab..84364931 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ISelectionEvent.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionEvent.java @@ -11,14 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** * Marker interface for selection events. */ -public interface ISelectionEvent { - - public SelectionLayer getSelectionLayer(); +@NonNullByDefault +public interface SelectionEvent { + + + SelectionLayer getSelectionLayer(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/IStyle.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionFlags.java index 494ecc29..94d43fb0 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/style/IStyle.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionFlags.java @@ -11,17 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.style; +package org.eclipse.statet.ecommons.waltable.selection.core; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -/** - * Used to store attributes reflecting a (usually display) style. - */ -public interface IStyle { + +@NonNullByDefault +public class SelectionFlags { - <T> T getAttributeValue(ConfigAttribute<T> styleAttribute); + /** Extend current selection */ + public static final int RANGE_SELECTION= 1 << 17; // SWT.SHIFT; + /** Retain or toggle */ + public static final int RETAIN_SELECTION= 1 << 18; // SWT.CTRL; - <T> void setAttributeValue(ConfigAttribute<T> styleAttribute, T value); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionLayer.java index e12ae703..dd991760 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionLayer.java @@ -11,9 +11,9 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import java.util.ArrayList; import java.util.Collection; @@ -21,72 +21,74 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; -import org.eclipse.statet.ecommons.waltable.coordinate.ILValueIterator; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; +import org.eclipse.statet.jcommons.collections.LongIterator; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + import org.eclipse.statet.ecommons.waltable.coordinate.PositionCoordinate; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerPainter; import org.eclipse.statet.ecommons.waltable.edit.EditSelectionCommandHandler; -import org.eclipse.statet.ecommons.waltable.layer.ForwardLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.painter.layer.ILayerPainter; import org.eclipse.statet.ecommons.waltable.selection.config.DefaultSelectionLayerConfiguration; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.ecommons.waltable.selection.swt.SelectionLayerPainter; import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; /** * Enables selection of column, rows, cells etc. on the table. * Also responds to UI bindings by changing the current selection. - * Internally it uses the {@link ISelectionModel} to track the selection state.<br/> + * Internally it uses the {@link SelectionModel} to track the selection state.<br/> * * @see DefaultSelectionLayerConfiguration - * @see Direction */ -public class SelectionLayer extends ForwardLayer { +@NonNullByDefault +public class SelectionLayer extends ForwardLayer<ForwardLayerDim<? extends SelectionLayer>> { public static final int MOVE_ALL= -1; public static final long NO_SELECTION= Long.MIN_VALUE; - protected ISelectionModel selectionModel; - protected ILayer underlyingLayer; + protected SelectionModel selectionModel; + protected Layer underlyingLayer; protected final PositionCoordinate lastSelectedCell; protected final PositionCoordinate selectionAnchor; - protected LRectangle lastSelectedRegion; + protected @Nullable LRectangle lastSelectedRegion; private final SelectCellCommandHandler selectCellCommandHandler; private final SelectDimPositionsCommandHandler selectDimPositionsCommandHandler; - public SelectionLayer(final ILayer underlyingLayer) { + public SelectionLayer(final Layer underlyingLayer) { this(underlyingLayer, null, true); } - public SelectionLayer(final ILayer underlyingLayer, final boolean useDefaultConfiguration) { + public SelectionLayer(final Layer underlyingLayer, final boolean useDefaultConfiguration) { this(underlyingLayer, null, useDefaultConfiguration); } - public SelectionLayer(final ILayer underlyingLayer, final ISelectionModel selectionModel, final boolean useDefaultConfiguration) { + public SelectionLayer(final Layer underlyingLayer, final SelectionModel selectionModel, final boolean useDefaultConfiguration) { this(underlyingLayer, selectionModel, useDefaultConfiguration, true); } - public SelectionLayer(final ILayer underlyingLayer, final ISelectionModel selectionModel, final boolean useDefaultConfiguration, final boolean registerDefaultEventHandler) { + public SelectionLayer(final Layer underlyingLayer, final SelectionModel selectionModel, final boolean useDefaultConfiguration, final boolean registerDefaultEventHandler) { super(underlyingLayer); this.underlyingLayer= underlyingLayer; - setLayerPainter(new SelectionLayerPainter()); - - this.selectionModel= selectionModel != null ? selectionModel : new SelectionModel(this); + this.selectionModel= selectionModel != null ? selectionModel : new BasicSelectionModel(this); this.lastSelectedCell= new PositionCoordinate(this, NO_SELECTION, NO_SELECTION); this.selectionAnchor= new PositionCoordinate(this, NO_SELECTION, NO_SELECTION); @@ -94,6 +96,8 @@ public class SelectionLayer extends ForwardLayer { this.selectCellCommandHandler= new SelectCellCommandHandler(this); this.selectDimPositionsCommandHandler= new SelectDimPositionsCommandHandler(this); + init(); + registerCommandHandlers(); if(registerDefaultEventHandler){ @@ -104,18 +108,24 @@ public class SelectionLayer extends ForwardLayer { } } + @Override + protected ForwardLayerDim<? extends SelectionLayer> createDim(final Orientation orientation) { + return new ForwardLayerDim<>(this, getUnderlyingLayer().getDim(orientation)); + } - public ISelectionModel getSelectionModel() { - return this.selectionModel; + + @Override + protected LayerPainter createPainter() { + return new SelectionLayerPainter(); } - public void setSelectionModel(final ISelectionModel selectionModel) { - this.selectionModel= selectionModel; + + public SelectionModel getSelectionModel() { + return this.selectionModel; } - @Override - public ILayerPainter getLayerPainter() { - return this.layerPainter; + public void setSelectionModel(final SelectionModel selectionModel) { + this.selectionModel= selectionModel; } protected void addSelection(final LRectangle selection) { @@ -132,7 +142,7 @@ public class SelectionLayer extends ForwardLayer { public void clear() { clearSelections(); - fireLayerEvent(new CellSelectionEvent(this, NO_SELECTION, NO_SELECTION, false)); + fireLayerEvent(new EmptySelectionEvent(this)); } protected void resetLastSelection() { @@ -172,8 +182,8 @@ public class SelectionLayer extends ForwardLayer { // Cell features public boolean isCellPositionSelected(final long columnPosition, final long rowPosition) { - final ILayerCell cell= getCellByPosition(columnPosition, rowPosition); - return (cell != null && cell.getDisplayMode() == DisplayMode.SELECT); + final LayerCell cell= getCellByPosition(columnPosition, rowPosition); + return (cell != null && cell.getDisplayMode() == DisplayMode.SELECTED); } /** @@ -196,9 +206,9 @@ public class SelectionLayer extends ForwardLayer { final List<PositionCoordinate> selectedCells= new ArrayList<>(); - for (final ILValueIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); ) { + for (final LongIterator columnIter= selectedColumnPositions.values().iterator(); columnIter.hasNext(); ) { final long columnPosition= columnIter.nextValue(); - for (final ILValueIterator rowIter= selectedRowPositions.values().iterator(); rowIter.hasNext(); ) { + for (final LongIterator rowIter= selectedRowPositions.values().iterator(); rowIter.hasNext(); ) { final long rowPosition= rowIter.nextValue(); if (isCellPositionSelected(columnPosition, rowPosition)) { selectedCells.add(new PositionCoordinate(this, columnPosition, rowPosition)); @@ -214,8 +224,8 @@ public class SelectionLayer extends ForwardLayer { * the SelectionModel. Takes spanning into account. * @return The selected ILayerCells */ - public Collection<ILayerCell> getSelectedCells() { - final Set<ILayerCell> selectedCells= new HashSet<>(); + public Collection<LayerCell> getSelectedCells() { + final Set<LayerCell> selectedCells= new HashSet<>(); final List<PositionCoordinate> selectedCoords= getSelectedCellPositions(); for (final PositionCoordinate coord : selectedCoords) { @@ -378,21 +388,21 @@ public class SelectionLayer extends ForwardLayer { // ILayer methods @Override - protected ILayerCell createCell(final ILayerCellDim hDim, final ILayerCellDim vDim, - final ILayerCell underlyingCell) { + protected LayerCell createCell(final LayerCellDim hDim, final LayerCellDim vDim, + final LayerCell underlyingCell) { return new ForwardLayerCell(this, hDim, vDim, underlyingCell) { @Override public DisplayMode getDisplayMode() { if (SelectionLayer.this.selectionModel.isCellPositionSelected(this)) { - return DisplayMode.SELECT; + return DisplayMode.SELECTED; } return super.getDisplayMode(); } @Override - public LabelStack getConfigLabels() { - final LabelStack configLabels= super.getConfigLabels(); + public LabelStack getLabels() { + final LabelStack configLabels= super.getLabels(); final LRectangle cellRectangle= new LRectangle( getOriginColumnPosition(), @@ -423,14 +433,12 @@ public class SelectionLayer extends ForwardLayer { } @Override - public boolean doCommand(final ILayerCommand command) { - if (command instanceof SelectAllCommand - && command.cloneCommand().convertToTargetLayer(this)) { + public boolean doCommand(final LayerCommand command) { + if (command instanceof SelectAllCommand) { selectAll(); return true; } - else if (command instanceof ClearAllSelectionsCommand - && command.cloneCommand().convertToTargetLayer(this)) { + else if (command instanceof ClearAllSelectionsCommand) { clear(); return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionLayerStructuralChangeEventHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionLayerStructuralChangeEventHandler.java new file mode 100644 index 00000000..871b274d --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionLayerStructuralChangeEventHandler.java @@ -0,0 +1,105 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.selection.core; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerListener; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff.DiffType; + + +@NonNullByDefault +public class SelectionLayerStructuralChangeEventHandler implements LayerListener { + + + private final SelectionModel selectionModel; + private final SelectionLayer selectionLayer; + + + public SelectionLayerStructuralChangeEventHandler(final SelectionLayer selectionLayer, final SelectionModel selectionModel) { + this.selectionLayer= selectionLayer; + this.selectionModel= selectionModel; + } + + + @Override + public void handleLayerEvent(final LayerEvent event) { + if (event instanceof StructuralChangeEvent) { + final var changeEvent= (StructuralChangeEvent)event; + if (changeEvent.isStructureChanged(HORIZONTAL)) { + // TODO handle column deletion + this.selectionLayer.clear(); + return; + } + + if (changeEvent.isStructureChanged(VERTICAL)) { + final List<StructuralDiff> rowDiffs= changeEvent.getDiffs(VERTICAL); + if (rowDiffs == null) { + //if there are no row diffs, it is a complete refresh + final Collection<LRectangle> lRectangles= changeEvent.getChangedPositionRectangles(); + for (final LRectangle lRectangle : lRectangles) { + final LRange changedRange= new LRange(lRectangle.y, lRectangle.y + lRectangle.height); + if (selectedRowModified(changedRange)) { + if (this.selectionLayer.getRowCount() > 0) { + long columnPosition= this.selectionLayer.getSelectionAnchor().columnPosition; + if (columnPosition == SelectionLayer.NO_SELECTION) { + columnPosition= 0; + } + this.selectionLayer.setSelectionToCell(columnPosition, 0, false); + } + else { + this.selectionLayer.clear(); + } + return; + } + } + } + else { + //there are row diffs so we try to determine the diffs to process + for (final StructuralDiff diff : rowDiffs) { + //DiffTypeEnum.CHANGE is used for resizing and shouldn't result in clearing the selection + if (diff.getDiffType() != DiffType.CHANGE) { + if (selectedRowModified(diff.getBeforePositionRange())) { + this.selectionLayer.clear(); + return; + } + } + } + } + } + } + } + + private boolean selectedRowModified(final LRange changedRange){ + final List<LRange> selectedRows= this.selectionModel.getSelectedRowPositions(); + for (final var range : selectedRows) { + if (range.overlap(changedRange)){ + return true; + } + } + return false; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ISelectionModel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionModel.java index 0794c789..c5896e44 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/ISelectionModel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/core/SelectionModel.java @@ -11,13 +11,15 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.core; import java.util.List; -import org.eclipse.statet.ecommons.waltable.coordinate.LRangeList; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; /** @@ -28,7 +30,8 @@ import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; * A column or row is not selected and not fully selected, if the selection layer is empty * (any dim has size 0).</p> */ -public interface ISelectionModel { +@NonNullByDefault +public interface SelectionModel { boolean isMultipleSelectionAllowed(); @@ -93,7 +96,7 @@ public interface ISelectionModel { * @param rowPosition the row position in the selection layer * @return <code>true</code> if the position is selected, otherwise <code>false</code> */ - boolean isCellPositionSelected(ILayerCell cell); + boolean isCellPositionSelected(LayerCell cell); //-- Column features --// diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayerPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/swt/SelectionLayerPainter.java index 2161446e..be19f504 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/SelectionLayerPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/swt/SelectionLayerPainter.java @@ -11,7 +11,7 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection; +package org.eclipse.statet.ecommons.waltable.selection.swt; import static org.eclipse.statet.ecommons.waltable.painter.cell.GraphicsUtils.safe; @@ -23,22 +23,25 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.painter.layer.GridLineCellLayerPainter; -import org.eclipse.statet.ecommons.waltable.style.BorderStyle; -import org.eclipse.statet.ecommons.waltable.style.CellStyleAttributes; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; -import org.eclipse.statet.ecommons.waltable.style.IStyle; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.style.BorderStyle; +import org.eclipse.statet.ecommons.waltable.core.style.CellStyling; +import org.eclipse.statet.ecommons.waltable.core.style.Style; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; +import org.eclipse.statet.ecommons.waltable.core.swt.painters.GridLineCellLayerPainter; import org.eclipse.statet.ecommons.waltable.style.SelectionStyleLabels; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; +@NonNullByDefault public class SelectionLayerPainter extends GridLineCellLayerPainter { @@ -46,13 +49,18 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { private long rowPositionOffset; - private Map<LPoint, ILayerCell> cells; + private Map<LPoint, LayerCell> cells; + + + public SelectionLayerPainter() { + super(); + } @Override - public void paintLayer(final ILayer natLayer, final GC gc, + public void paintLayer(final Layer natLayer, final GC gc, final int xOffset, final int yOffset, final Rectangle pixelRectangle, - final IConfigRegistry configRegistry) { + final ConfigRegistry configRegistry) { final LRectangle positionRectangle= getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle); this.columnPositionOffset= positionRectangle.x; this.rowPositionOffset= positionRectangle.y; @@ -73,8 +81,8 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { // Draw horizontal borders boolean selectedMode= false; for (long columnPosition= this.columnPositionOffset; columnPosition < this.columnPositionOffset + positionRectangle.width; columnPosition++) { - ILayerCell previousCell= null; - ILayerCell currentCell= null; + LayerCell previousCell= null; + LayerCell currentCell= null; for (long rowPosition= this.rowPositionOffset; rowPosition < this.rowPositionOffset + positionRectangle.height; rowPosition++) { currentCell= this.cells.get(new LPoint(columnPosition, rowPosition)); if (currentCell != null) { @@ -112,8 +120,8 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { // Draw vertical borders for (long rowPosition= this.rowPositionOffset; rowPosition < this.rowPositionOffset + positionRectangle.height; rowPosition++) { - ILayerCell previousCell= null; - ILayerCell currentCell= null; + LayerCell previousCell= null; + LayerCell currentCell= null; for (long columnPosition= this.columnPositionOffset; columnPosition < this.columnPositionOffset + positionRectangle.width; columnPosition++) { currentCell= this.cells.get(new LPoint(columnPosition, rowPosition)); if (currentCell != null) { @@ -156,7 +164,7 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { } @Override - protected void paintCell(final ILayerCell cell, final GC gc, final IConfigRegistry configRegistry) { + protected void paintCell(final LayerCell cell, final GC gc, final ConfigRegistry configRegistry) { for (long columnPosition= cell.getOriginColumnPosition(); columnPosition < cell.getOriginColumnPosition() + cell.getColumnSpan(); columnPosition++) { for (long rowPosition= cell.getOriginRowPosition(); rowPosition < cell.getOriginRowPosition() + cell.getRowSpan(); rowPosition++) { this.cells.put(new LPoint(columnPosition, rowPosition), cell); @@ -166,22 +174,22 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { super.paintCell(cell, gc, configRegistry); } - private boolean isSelected(final ILayerCell cell) { - return (cell.getDisplayMode() == DisplayMode.SELECT); + private boolean isSelected(final LayerCell cell) { + return (cell.getDisplayMode() == DisplayMode.SELECTED); } - private void applyBorderStyle(final GC gc, final IConfigRegistry configRegistry) { + private void applyBorderStyle(final GC gc, final ConfigRegistry configRegistry) { //Note: If there is no style configured for the SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE // label, the style configured for DisplayMode.SELECT will be retrieved by this call. // Ensure that the selection style configuration does not contain a border style configuration // to avoid strange rendering behaviour. By default there is no border configuration added, // so there shouldn't be issues with backwards compatibility. And if there are some, they can // be solved easily by adding the necessary border style configuration. - final IStyle cellStyle= configRegistry.getConfigAttribute( + final Style cellStyle= configRegistry.getAttribute( CellConfigAttributes.CELL_STYLE, - DisplayMode.SELECT, + DisplayMode.SELECTED, SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE); - final BorderStyle borderStyle= cellStyle != null ? cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE) : null; + final BorderStyle borderStyle= cellStyle != null ? cellStyle.getAttributeValue(CellStyling.BORDER_STYLE) : null; //if there is no border style configured, use the default one for backwards compatibility if (borderStyle == null) { @@ -190,7 +198,7 @@ public class SelectionLayerPainter extends GridLineCellLayerPainter { gc.setForeground(GUIHelper.COLOR_BLACK); } else { - gc.setLineStyle(SWTUtil.toSWT(borderStyle.getLineStyle())); + gc.setLineStyle(SwtUtils.toSWT(borderStyle.getLineStyle())); gc.setLineWidth(borderStyle.getThickness()); gc.setForeground(borderStyle.getColor()); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/CellSelectionDragMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/CellSelectionDragMode.java index 1df988a9..f637a53a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/CellSelectionDragMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/CellSelectionDragMode.java @@ -11,14 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection.action; +package org.eclipse.statet.ecommons.waltable.selection.ui.action; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.selection.SelectCellCommand; -import org.eclipse.statet.ecommons.waltable.selection.SelectionFlags; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectCellCommand; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionFlags; import org.eclipse.statet.ecommons.waltable.ui.action.IDragMode; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/RowSelectionDragMode.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/RowSelectionDragMode.java index d94d07ff..1861b240 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/RowSelectionDragMode.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/RowSelectionDragMode.java @@ -11,13 +11,13 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection.action; +package org.eclipse.statet.ecommons.waltable.selection.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.selection.SelectDimPositionsCommand; import org.eclipse.statet.ecommons.waltable.selection.config.RowOnlySelectionBindings; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectDimPositionsCommand; /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectAllAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectAllAction.java index 9639272b..f506261e 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectAllAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectAllAction.java @@ -11,12 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection.action; +package org.eclipse.statet.ecommons.waltable.selection.ui.action; import org.eclipse.swt.events.KeyEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.selection.SelectAllCommand; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectAllCommand; import org.eclipse.statet.ecommons.waltable.ui.action.IKeyAction; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectCellAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectCellAction.java index 21405d41..2189df66 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectCellAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectCellAction.java @@ -11,13 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection.action; +package org.eclipse.statet.ecommons.waltable.selection.ui.action; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.selection.SelectCellCommand; -import org.eclipse.statet.ecommons.waltable.selection.SelectionFlags; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectCellCommand; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionFlags; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; @@ -27,6 +28,18 @@ import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; public class SelectCellAction implements IMouseAction { + public static final int swt2Flags(final int swtMask) { + int flags= 0; + if ((swtMask & SWT.MOD2) != 0) { + flags |= SelectionFlags.RANGE_SELECTION; + } + if ((swtMask & SWT.MOD1) != 0) { + flags |= SelectionFlags.RETAIN_SELECTION; + } + return flags; + } + + public SelectCellAction() { } @@ -36,8 +49,9 @@ public class SelectCellAction implements IMouseAction { natTable.doCommand(new SelectCellCommand(natTable, natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y), - SelectionFlags.swt2Flags(event.stateMask), + SelectCellAction.swt2Flags(event.stateMask), true )); } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectRowAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectRowAction.java index d9b42427..ed57a608 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/selection/action/SelectRowAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/selection/ui/action/SelectRowAction.java @@ -11,15 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.selection.action; +package org.eclipse.statet.ecommons.waltable.selection.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.selection.SelectDimPositionsCommand; -import org.eclipse.statet.ecommons.waltable.selection.SelectionFlags; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectDimPositionsCommand; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; @@ -38,7 +37,7 @@ public class SelectRowAction implements IMouseAction { natTable.doCommand(new SelectDimPositionsCommand(natTable.getDim(VERTICAL), natTable.getRowPositionByY(event.y), natTable.getColumnPositionByX(event.x), - SelectionFlags.swt2Flags(event.stateMask) )); + SelectCellAction.swt2Flags(event.stateMask) )); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ColumnHeaderClickEventMatcher.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/ColumnHeaderClickEventMatcher.java index 6e625329..cf1f02ce 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ColumnHeaderClickEventMatcher.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/ColumnHeaderClickEventMatcher.java @@ -16,10 +16,10 @@ package org.eclipse.statet.ecommons.waltable.sort; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeDetectUtil; import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum; @@ -32,7 +32,7 @@ import org.eclipse.statet.ecommons.waltable.util.GUIHelper; public class ColumnHeaderClickEventMatcher extends MouseEventMatcher { public ColumnHeaderClickEventMatcher(final int stateMask, final int button) { - super(stateMask, GridRegion.COLUMN_HEADER, button); + super(stateMask, GridLabels.COLUMN_HEADER, button); } @Override @@ -40,7 +40,7 @@ public class ColumnHeaderClickEventMatcher extends MouseEventMatcher { return super.matches(natTable, event, regionLabels) && isNearTheHeaderEdge(natTable, event) && isNotFilterRegion(regionLabels); } - private boolean isNearTheHeaderEdge(final ILayer natLayer, final MouseEvent event) { + private boolean isNearTheHeaderEdge(final Layer natLayer, final MouseEvent event) { final CellEdgeEnum cellEdge= CellEdgeDetectUtil.getHorizontalCellEdge( natLayer, new LPoint(event.x, event.y), @@ -50,7 +50,7 @@ public class ColumnHeaderClickEventMatcher extends MouseEventMatcher { private boolean isNotFilterRegion(final LabelStack regionLabels) { if (regionLabels != null) { - return !regionLabels.getLabels().contains(GridRegion.FILTER_ROW); + return !regionLabels.getLabels().contains(GridLabels.FILTER_ROW); } return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortStatePersistor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/SortStatePersistor.java index 677f0eb2..61722caa 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortStatePersistor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/SortStatePersistor.java @@ -17,28 +17,30 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Properties; +import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.sort.core.SortDirection; +import org.eclipse.statet.ecommons.waltable.sort.core.SortModel; import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; /** * Handles persisting of the sorting state. - * The sorting state is read from and restored to the {@link ISortModel}. + * The sorting state is read from and restored to the {@link SortModel}. * * @param <T> Type of the Beans in the backing data source. */ -public class SortStatePersistor<T> implements IPersistable { +public class SortStatePersistor<T> implements Persistable { public static final String PERSISTENCE_KEY_SORTING_STATE= ".SortHeaderLayer.sortingState"; //$NON-NLS-1$ - private final ISortModel sortModel; + private final SortModel sortModel; - public SortStatePersistor(final ISortModel sortModel) { + public SortStatePersistor(final SortModel sortModel) { this.sortModel= sortModel; } @@ -52,7 +54,7 @@ public class SortStatePersistor<T> implements IPersistable { * column index : sort direction : sort order | */ @Override - public void saveState(final String prefix, final Properties properties) { + public void saveState(final String prefix, final Map<String, String> properties) { final StringBuilder buffer= new StringBuilder(); for (final long id : this.sortModel.getSortedColumnIds()) { @@ -73,10 +75,10 @@ public class SortStatePersistor<T> implements IPersistable { } /** - * Parses the saved string and restores the state to the {@link ISortModel}. + * Parses the saved string and restores the state to the {@link SortModel}. */ @Override - public void loadState(final String prefix, final Properties properties) { + public void loadState(final String prefix, final Map<String, String> properties) { /* * restoring the sortState starts with a clean sortModel. This step diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/config/DefaultSortConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/config/DefaultSortConfiguration.java index 25a53c16..31a14aa5 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/config/DefaultSortConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/config/DefaultSortConfiguration.java @@ -16,17 +16,15 @@ package org.eclipse.statet.ecommons.waltable.sort.config; import org.eclipse.swt.SWT; import org.eclipse.statet.ecommons.waltable.config.CellConfigAttributes; -import org.eclipse.statet.ecommons.waltable.config.DefaultComparator; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; import org.eclipse.statet.ecommons.waltable.config.IConfiguration; -import org.eclipse.statet.ecommons.waltable.grid.GridRegion; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.config.DisplayMode; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; +import org.eclipse.statet.ecommons.waltable.grid.core.GridLabels; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.BeveledBorderDecorator; -import org.eclipse.statet.ecommons.waltable.sort.SortConfigAttributes; -import org.eclipse.statet.ecommons.waltable.sort.action.SortColumnAction; -import org.eclipse.statet.ecommons.waltable.sort.painter.SortableHeaderTextPainter; -import org.eclipse.statet.ecommons.waltable.style.DisplayMode; +import org.eclipse.statet.ecommons.waltable.sort.swt.SortableHeaderTextPainter; +import org.eclipse.statet.ecommons.waltable.sort.ui.action.SortColumnAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; @@ -39,34 +37,32 @@ public class DefaultSortConfiguration implements IConfiguration { /** The sort sequence can be appended to this base */ public static final String SORT_SEQ_CONFIG_TYPE= "SORT_SEQ_"; //$NON-NLS-1$ - private final ICellPainter cellPainter; + private final LayerCellPainter layerCellPainter; public DefaultSortConfiguration() { this(new BeveledBorderDecorator(new SortableHeaderTextPainter())); } - public DefaultSortConfiguration(final ICellPainter cellPainter) { - this.cellPainter= cellPainter; + public DefaultSortConfiguration(final LayerCellPainter layerCellPainter) { + this.layerCellPainter= layerCellPainter; } @Override - public void configureLayer(final ILayer layer) {} + public void configureLayer(final Layer layer) {} @Override - public void configureRegistry(final IConfigRegistry configRegistry) { - configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new DefaultComparator()); - - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter, DisplayMode.NORMAL, SORT_DOWN_CONFIG_TYPE); - configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.cellPainter, DisplayMode.NORMAL, SORT_UP_CONFIG_TYPE); + public void configureRegistry(final ConfigRegistry configRegistry) { + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter, DisplayMode.NORMAL, SORT_DOWN_CONFIG_TYPE); + configRegistry.registerAttribute(CellConfigAttributes.CELL_PAINTER, this.layerCellPainter, DisplayMode.NORMAL, SORT_UP_CONFIG_TYPE); } @Override public void configureUiBindings(final UiBindingRegistry uiBindingRegistry) { uiBindingRegistry.registerSingleClickBinding( - new MouseEventMatcher(SWT.ALT, GridRegion.COLUMN_HEADER.toString(), 1), new SortColumnAction(false)); + new MouseEventMatcher(SWT.ALT, GridLabels.COLUMN_HEADER.toString(), 1), new SortColumnAction(false)); uiBindingRegistry.registerSingleClickBinding( - new MouseEventMatcher(SWT.ALT | SWT.MOD2, GridRegion.COLUMN_HEADER.toString(), 1), new SortColumnAction(true)); + new MouseEventMatcher(SWT.ALT | SWT.MOD2, GridLabels.COLUMN_HEADER.toString(), 1), new SortColumnAction(true)); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/config/SingleClickSortConfiguration.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/config/SingleClickSortConfiguration.java index 0b1ead0b..4027bf9c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/config/SingleClickSortConfiguration.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/config/SingleClickSortConfiguration.java @@ -15,9 +15,9 @@ package org.eclipse.statet.ecommons.waltable.sort.config; import org.eclipse.swt.SWT; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.sort.ColumnHeaderClickEventMatcher; -import org.eclipse.statet.ecommons.waltable.sort.action.SortColumnAction; +import org.eclipse.statet.ecommons.waltable.sort.ui.action.SortColumnAction; import org.eclipse.statet.ecommons.waltable.ui.binding.UiBindingRegistry; import org.eclipse.statet.ecommons.waltable.ui.matcher.MouseEventMatcher; @@ -32,8 +32,8 @@ public class SingleClickSortConfiguration extends DefaultSortConfiguration { super(); } - public SingleClickSortConfiguration(final ICellPainter cellPainter) { - super(cellPainter); + public SingleClickSortConfiguration(final LayerCellPainter layerCellPainter) { + super(layerCellPainter); } /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ClearSortCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/ClearSortCommand.java index 80a361cd..eb979fcb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ClearSortCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/ClearSortCommand.java @@ -11,11 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort; +package org.eclipse.statet.ecommons.waltable.sort.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; + +@NonNullByDefault public class ClearSortCommand extends AbstractContextFreeCommand { + + public ClearSortCommand() { + } + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/ClearSortCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/ClearSortCommandHandler.java new file mode 100644 index 00000000..c4acad20 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/ClearSortCommandHandler.java @@ -0,0 +1,67 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.sort.core; + +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; + +import java.util.List; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRangeList; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +@NonNullByDefault +public class ClearSortCommandHandler implements LayerCommandHandler<ClearSortCommand> { + + + private final SortModel sortModel; + + + public ClearSortCommandHandler(final SortModel sortModel) { + this.sortModel= sortModel; + } + + + @Override + public Class<ClearSortCommand> getCommandClass() { + return ClearSortCommand.class; + } + + @Override + public boolean doCommand(final Layer targetLayer, final ClearSortCommand command) { + final LayerDim layerDim= targetLayer.getDim(HORIZONTAL); + + final List<Long> sortedIds= this.sortModel.getSortedColumnIds(); + final LRangeList sortedPositions= new LRangeList(); + for (final Long id : sortedIds) { + final long position= layerDim.getPositionById(id); + if (position != LayerDim.POSITION_NA) { + sortedPositions.values().add(position); + } + } + + this.sortModel.clear(); + + // Fire event + final SortColumnEvent sortEvent= new SortColumnEvent(layerDim, sortedPositions); + layerDim.getLayer().fireLayerEvent(sortEvent); + + return true; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortColumnEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortColumnEvent.java new file mode 100644 index 00000000..1ac7da37 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortColumnEvent.java @@ -0,0 +1,47 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.sort.core; + +import java.util.List; + +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.events.DimPositionsVisualChangeEvent; + + +@NonNullByDefault +public class SortColumnEvent extends DimPositionsVisualChangeEvent { + + + public SortColumnEvent(final LayerDim layerDim, final List<LRange> positions) { + super(layerDim, positions); + } + + public SortColumnEvent(final LayerDim layerDim, final LRange positions) { + super(layerDim, ImCollections.newList(positions)); + } + + @Override + protected @Nullable DimPositionsVisualChangeEvent toLayer(final LayerDim targetLayerDim, + @NonNull final List<@NonNull LRange> positionRanges) { + return new SortColumnEvent(targetLayerDim, positionRanges); + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortDimPositionCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortDimPositionCommand.java index faa49834..ee5019cf 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortDimPositionCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortDimPositionCommand.java @@ -11,26 +11,33 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort; +package org.eclipse.statet.ecommons.waltable.sort.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + +@NonNullByDefault public class SortDimPositionCommand extends AbstractDimPositionCommand { private final boolean accumulate; - private final SortDirection direction; + private final @Nullable SortDirection direction; - public SortDimPositionCommand(final ILayerDim layerDim, final long columnPosition, + public SortDimPositionCommand(final LayerDim layerDim, final long columnPosition, final boolean accumulate) { - this(layerDim, columnPosition, null, accumulate); + super(layerDim, columnPosition); + + this.accumulate= accumulate; + this.direction= null; } - public SortDimPositionCommand(final ILayerDim layerDim, final long columnPosition, + public SortDimPositionCommand(final LayerDim layerDim, final long columnPosition, final SortDirection direction, final boolean accumulate) { super(layerDim, columnPosition); @@ -60,7 +67,7 @@ public class SortDimPositionCommand extends AbstractDimPositionCommand { * * @return the sort direction or <code>null</code> for automatic iteration */ - public SortDirection getDirection() { + public @Nullable SortDirection getDirection() { return this.direction; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortDirection.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortDirection.java index 6e27eb8a..221b3316 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortDirection.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortDirection.java @@ -11,15 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort; +package org.eclipse.statet.ecommons.waltable.sort.core; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +@NonNullByDefault public enum SortDirection { NONE("Unsorted"), //$NON-NLS-1$ ASC("Ascending"), //$NON-NLS-1$ - DESC("Ascending"); //$NON-NLS-1$ + DESC("Descending"); //$NON-NLS-1$ private final String description; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortHeaderLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortHeaderLayer.java index 5166882e..d8c225c8 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/SortHeaderLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortHeaderLayer.java @@ -11,42 +11,50 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort; +package org.eclipse.statet.ecommons.waltable.sort.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; -import org.eclipse.statet.ecommons.waltable.layer.ForwardLayer; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.LabelStack; -import org.eclipse.statet.ecommons.waltable.layer.cell.ForwardLayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.ForwardLayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LabelStack; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellDim; +import org.eclipse.statet.ecommons.waltable.sort.SortStatePersistor; import org.eclipse.statet.ecommons.waltable.sort.config.DefaultSortConfiguration; /** - * Enables sorting of the data. Uses an {@link ISortModel} to do/track the sorting. + * Enables sorting of the data. Uses an {@link SortModel} to do/track the sorting. * @param <T> Type of the Beans in the backing data source. * * @see DefaultSortConfiguration * @see SortStatePersistor */ -public class SortHeaderLayer<T> extends ForwardLayer implements IPersistable { +@NonNullByDefault +public class SortHeaderLayer<T> extends ForwardLayer<ForwardLayerDim<? extends SortHeaderLayer<T>>> implements Persistable { /** Handles the actual sorting of underlying data */ - private final ISortModel sortModel; + private final SortModel sortModel; - public SortHeaderLayer(final ILayer underlyingLayer, final ISortModel sortModel) { + public SortHeaderLayer(final Layer underlyingLayer, final SortModel sortModel) { this(underlyingLayer, sortModel, true); } - public SortHeaderLayer(final ILayer underlyingLayer, final ISortModel sortModel, final boolean useDefaultConfiguration) { + public SortHeaderLayer(final Layer underlyingLayer, final SortModel sortModel, final boolean useDefaultConfiguration) { super(underlyingLayer); this.sortModel= sortModel; + init(); + registerPersistable(new SortStatePersistor<T>(sortModel)); if (useDefaultConfiguration) { @@ -54,23 +62,28 @@ public class SortHeaderLayer<T> extends ForwardLayer implements IPersistable { } } + @Override + protected ForwardLayerDim<? extends SortHeaderLayer<T>> createDim(final Orientation orientation) { + return new ForwardLayerDim<>(this, getUnderlyingLayer().getDim(orientation)); + } + /** * @return The ISortModel that is used to handle the sorting of the underlying data. */ - public ISortModel getSortModel() { + public SortModel getSortModel() { return this.sortModel; } @Override - protected ILayerCell createCell(final ILayerCellDim hDim, final ILayerCellDim vDim, - final ILayerCell underlyingCell) { + protected LayerCell createCell(final LayerCellDim hDim, final LayerCellDim vDim, + final LayerCell underlyingCell) { return new ForwardLayerCell(this, hDim, vDim, underlyingCell) { @Override - public LabelStack getConfigLabels() { - final LabelStack configLabels= super.getConfigLabels(); + public LabelStack getLabels() { + final LabelStack configLabels= super.getLabels(); final long id= getDim(HORIZONTAL).getId(); if (SortHeaderLayer.this.sortModel.isSorted(id)) { @@ -85,6 +98,8 @@ public class SortHeaderLayer<T> extends ForwardLayer implements IPersistable { case DESC: configLabels.addLabelOnTop(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE); break; + default: + break; } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ISortModel.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortModel.java index 160e0662..deabdc74 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/ISortModel.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortModel.java @@ -11,31 +11,35 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort; +package org.eclipse.statet.ecommons.waltable.sort.core; import java.util.List; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + /** * Interface providing sorting functionality. */ -public interface ISortModel { +@NonNullByDefault +public interface SortModel { + /** * @return List of column ids that are sorted. */ - public List<Long> getSortedColumnIds(); + List<Long> getSortedColumnIds(); /** * @return TRUE if the column with the given id is sorted at the moment. */ - public boolean isSorted(long columnId); + boolean isSorted(long columnId); /** * @return the direction in which the column with the given id is * currently sorted */ - public SortDirection getSortDirection(long columnId); + SortDirection getSortDirection(long columnId); /** * @return when multiple columns are sorted, this returns the order of the @@ -44,7 +48,7 @@ public interface ISortModel { * Example: If column ids 3, 6, 9 are sorted (in that order) the sort order * for id 6 is 1. */ - public int getSortOrder(long columnId); + int getSortOrder(long columnId); /** * This method is called by the {@link SortCommandHandler} in response to a sort command. @@ -52,11 +56,11 @@ public interface ISortModel { * * @param accumulate flag indicating if the column should added to a previous sort. */ - public void sort(long columnId, SortDirection sortDirection, boolean accumulate); + void sort(long columnId, SortDirection sortDirection, boolean accumulate); /** * Remove all sorting */ - public void clear(); + void clear(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortPositionCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortPositionCommandHandler.java new file mode 100644 index 00000000..3ce0deeb --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/core/SortPositionCommandHandler.java @@ -0,0 +1,62 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.sort.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + + +/** + * Handle sort commands + */ +@NonNullByDefault +public class SortPositionCommandHandler extends AbstractLayerCommandHandler<SortDimPositionCommand> { + + + private final SortModel sortModel; + + + public SortPositionCommandHandler(final SortModel sortModel) { + this.sortModel= sortModel; + } + + + @Override + public Class<SortDimPositionCommand> getCommandClass() { + return SortDimPositionCommand.class; + } + + @Override + protected boolean doCommand(final SortDimPositionCommand command) { + final LayerDim layerDim= command.getDim(); + final long columnId= layerDim.getPositionId(command.getPosition(), command.getPosition()); + + SortDirection newSortDirection= command.getDirection(); + if (newSortDirection == null) { + newSortDirection= this.sortModel.getSortDirection(columnId).getNextSortDirection(); + } + this.sortModel.sort(columnId, newSortDirection, command.isAccumulate()); + + // Fire event + final SortColumnEvent sortEvent= new SortColumnEvent(layerDim, + new LRange(command.getPosition()) ); + layerDim.getLayer().fireLayerEvent(sortEvent); + + return true; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/painter/SortableHeaderTextPainter.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/swt/SortableHeaderTextPainter.java index eddbc08d..09801f5a 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/painter/SortableHeaderTextPainter.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/swt/SortableHeaderTextPainter.java @@ -11,14 +11,16 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort.painter; +package org.eclipse.statet.ecommons.waltable.sort.swt; import org.eclipse.swt.graphics.Image; -import org.eclipse.statet.ecommons.waltable.config.IConfigRegistry; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.config.ConfigRegistry; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.CellPainterWrapper; -import org.eclipse.statet.ecommons.waltable.painter.cell.ICellPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.ImagePainter; import org.eclipse.statet.ecommons.waltable.painter.cell.TextPainter; import org.eclipse.statet.ecommons.waltable.painter.cell.decorator.CellPainterDecorator; @@ -27,97 +29,99 @@ import org.eclipse.statet.ecommons.waltable.ui.util.CellEdgeEnum; import org.eclipse.statet.ecommons.waltable.util.GUIHelper; +@NonNullByDefault public class SortableHeaderTextPainter extends CellPainterWrapper { - + + /** * Creates the default {@link SortableHeaderTextPainter} that uses a {@link TextPainter} - * as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the right + * as base {@link LayerCellPainter} and decorate it with the {@link SortIconPainter} on the right * edge of the cell. */ public SortableHeaderTextPainter() { this(new TextPainter()); } - + /** - * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} - * as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the right + * Creates a {@link SortableHeaderTextPainter} that uses the given {@link LayerCellPainter} + * as base {@link LayerCellPainter} and decorate it with the {@link SortIconPainter} on the right * edge of the cell. - * @param interiorPainter the base {@link ICellPainter} to use + * @param interiorPainter the base {@link LayerCellPainter} to use */ - public SortableHeaderTextPainter(final ICellPainter interiorPainter) { + public SortableHeaderTextPainter(final LayerCellPainter interiorPainter) { this(interiorPainter, CellEdgeEnum.RIGHT); } - + /** - * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} - * as base {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the specified + * Creates a {@link SortableHeaderTextPainter} that uses the given {@link LayerCellPainter} + * as base {@link LayerCellPainter} and decorate it with the {@link SortIconPainter} on the specified * edge of the cell. - * @param interiorPainter the base {@link ICellPainter} to use + * @param interiorPainter the base {@link LayerCellPainter} to use * @param cellEdge the edge of the cell on which the sort indicator decoration should be applied */ - public SortableHeaderTextPainter(final ICellPainter interiorPainter, final CellEdgeEnum cellEdge) { + public SortableHeaderTextPainter(final LayerCellPainter interiorPainter, final CellEdgeEnum cellEdge) { this(interiorPainter, cellEdge, new SortIconPainter(true)); } - + /** - * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} - * as base {@link ICellPainter} and decorate it with the given {@link ICellPainter} to use for sort + * Creates a {@link SortableHeaderTextPainter} that uses the given {@link LayerCellPainter} + * as base {@link LayerCellPainter} and decorate it with the given {@link LayerCellPainter} to use for sort * related decoration on the specified edge of the cell. - * @param interiorPainter the base {@link ICellPainter} to use + * @param interiorPainter the base {@link LayerCellPainter} to use * @param cellEdge the edge of the cell on which the sort indicator decoration should be applied - * @param decoratorPainter the {@link ICellPainter} that should be used to paint the sort related + * @param decoratorPainter the {@link LayerCellPainter} that should be used to paint the sort related * decoration (by default the {@link SortIconPainter} will be used) */ - public SortableHeaderTextPainter(final ICellPainter interiorPainter, final CellEdgeEnum cellEdge, final ICellPainter decoratorPainter) { + public SortableHeaderTextPainter(final LayerCellPainter interiorPainter, final CellEdgeEnum cellEdge, final LayerCellPainter decoratorPainter) { setWrappedPainter(new CellPainterDecorator(interiorPainter, cellEdge, decoratorPainter)); } - + //the following constructors are intended to configure the CellPainterDecorator that is created as //the wrapped painter of this SortableHeaderTextPainter - - /** - * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} as base - * {@link ICellPainter}. It will use the {@link SortIconPainter} as decorator for sort related + + /** + * Creates a {@link SortableHeaderTextPainter} that uses the given {@link LayerCellPainter} as base + * {@link LayerCellPainter}. It will use the {@link SortIconPainter} as decorator for sort related * decorations at the specified cell edge, which can be configured to render the background or * not via method parameter. With the additional parameters, the behaviour of the created * {@link CellPainterDecorator} can be configured in terms of rendering. - * @param interiorPainter the base {@link ICellPainter} to use + * @param interiorPainter the base {@link LayerCellPainter} to use * @param cellEdge the edge of the cell on which the sort indicator decoration should be applied * @param paintBg flag to configure whether the {@link SortIconPainter} should paint the background or not - * @param spacing the number of pixels that should be used as spacing between cell edge and decoration - * @param paintDecorationDependent flag to configure if the base {@link ICellPainter} should render - * decoration dependent or not. If it is set to <code>false</code>, the base painter will - * always paint at the same coordinates, using the whole cell bounds, <code>true</code> - * will cause the bounds of the cell to shrink for the base painter. - */ - public SortableHeaderTextPainter(final ICellPainter interiorPainter, final CellEdgeEnum cellEdge, - final boolean paintBg, final long spacing, final boolean paintDecorationDependent) { - - final ICellPainter sortPainter= new SortIconPainter(paintBg); - final CellPainterDecorator painter= new CellPainterDecorator(interiorPainter, cellEdge, - spacing, sortPainter, paintDecorationDependent); - setWrappedPainter(painter); - } + * @param spacing the number of pixels that should be used as spacing between cell edge and decoration + * @param paintDecorationDependent flag to configure if the base {@link LayerCellPainter} should render + * decoration dependent or not. If it is set to <code>false</code>, the base painter will + * always paint at the same coordinates, using the whole cell bounds, <code>true</code> + * will cause the bounds of the cell to shrink for the base painter. + */ + public SortableHeaderTextPainter(final LayerCellPainter interiorPainter, final CellEdgeEnum cellEdge, + final boolean paintBg, final long spacing, final boolean paintDecorationDependent) { + final LayerCellPainter sortPainter= new SortIconPainter(paintBg); + final CellPainterDecorator painter= new CellPainterDecorator(interiorPainter, cellEdge, + spacing, sortPainter, paintDecorationDependent); + setWrappedPainter(painter); + } /** - * Creates a {@link SortableHeaderTextPainter} that uses the given {@link ICellPainter} as base - * {@link ICellPainter} and decorate it with the {@link SortIconPainter} on the right + * Creates a {@link SortableHeaderTextPainter} that uses the given {@link LayerCellPainter} as base + * {@link LayerCellPainter} and decorate it with the {@link SortIconPainter} on the right * edge of the cell. This constructor gives the opportunity to configure the behaviour of the * {@link SortIconPainter} and the {@link CellPainterDecorator} for some attributes. * Remains because of downwards compatibility. - * @param interiorPainter the base {@link ICellPainter} to use + * @param interiorPainter the base {@link LayerCellPainter} to use * @param paintBg flag to configure whether the {@link SortIconPainter} should paint the background or not - * @param interiorPainterToSpanFullWidth flag to configure how the bounds of the base painter should be - * calculated + * @param interiorPainterToSpanFullWidth flag to configure how the bounds of the base painter + * should be calculated */ - public SortableHeaderTextPainter(final ICellPainter interiorPainter, final boolean paintBg, final boolean interiorPainterToSpanFullWidth) { - final ICellPainter sortPainter= new SortIconPainter(paintBg); - final CellPainterDecorator painter= new CellPainterDecorator(interiorPainter, CellEdgeEnum.RIGHT, 0, sortPainter); - painter.setPaintDecorationDependent(!interiorPainterToSpanFullWidth); - setWrappedPainter(painter); + public SortableHeaderTextPainter(final LayerCellPainter interiorPainter, final boolean paintBg, + final boolean interiorPainterToSpanFullWidth) { + final LayerCellPainter sortPainter= new SortIconPainter(paintBg); + final CellPainterDecorator painter= new CellPainterDecorator(interiorPainter, CellEdgeEnum.RIGHT, 0, sortPainter); + painter.setPaintDecorationDependent(!interiorPainterToSpanFullWidth); + setWrappedPainter(painter); } - - + + /** * Paints the triangular sort icon images. */ @@ -130,7 +134,7 @@ public class SortableHeaderTextPainter extends CellPainterWrapper { @Override - protected Image getImage(final ILayerCell cell, final IConfigRegistry configRegistry) { + protected Image getImage(final LayerCell cell, final ConfigRegistry configRegistry) { Image icon= null; if (isSortedAscending(cell)) { @@ -142,16 +146,16 @@ public class SortableHeaderTextPainter extends CellPainterWrapper { return icon; } - private boolean isSortedAscending(final ILayerCell cell) { - return cell.getConfigLabels().hasLabel(DefaultSortConfiguration.SORT_UP_CONFIG_TYPE); + private boolean isSortedAscending(final LayerCell cell) { + return cell.getLabels().hasLabel(DefaultSortConfiguration.SORT_UP_CONFIG_TYPE); } - private boolean isSortedDescending(final ILayerCell cell) { - return cell.getConfigLabels().hasLabel(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE); + private boolean isSortedDescending(final LayerCell cell) { + return cell.getLabels().hasLabel(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE); } - private int getSortSequence(final ILayerCell cell) { - for (final String configLabel : cell.getConfigLabels().getLabels()) { + private int getSortSequence(final LayerCell cell) { + for (final String configLabel : cell.getLabels().getLabels()) { if (configLabel.startsWith(DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE)) { return Integer.parseInt(configLabel.substring( DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE.length() )); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/action/SortColumnAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/ui/action/SortColumnAction.java index 0932a89f..647921fc 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/sort/action/SortColumnAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/sort/ui/action/SortColumnAction.java @@ -11,14 +11,14 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.sort.action; +package org.eclipse.statet.ecommons.waltable.sort.ui.action; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; import org.eclipse.swt.events.MouseEvent; import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.sort.SortDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.sort.core.SortDimPositionCommand; import org.eclipse.statet.ecommons.waltable.ui.NatEventData; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/AutomaticSpanningDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/AutomaticSpanningDataProvider.java index d8762e40..a72381f9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/AutomaticSpanningDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/AutomaticSpanningDataProvider.java @@ -11,19 +11,24 @@ # Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.util.data; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.Properties; import java.util.StringTokenizer; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.layer.cell.DataCell; -import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.Persistable; +import org.eclipse.statet.ecommons.waltable.core.data.DataCell; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; +import org.eclipse.statet.ecommons.waltable.core.data.SpanningDataProvider; /** @@ -45,7 +50,8 @@ import org.eclipse.statet.ecommons.waltable.persistence.IPersistable; * by building the spanning cell for the matching rectangle. As this would be quite time consuming * calculations, this is not supported out of the box by NatTable. */ -public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPersistable { +@NonNullByDefault +public class AutomaticSpanningDataProvider implements SpanningDataProvider, Persistable { public static final String PERSISTENCE_KEY_AUTO_COLUMN_SPAN= ".autoColumnSpan"; //$NON-NLS-1$ @@ -57,7 +63,7 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe /** * The IDataProvider that is wrapped by this AutomaticSpanningDataProvider */ - private final IDataProvider underlyingDataProvider; + private final DataProvider underlyingDataProvider; /** * Flag to configure this AutomaticSpanningDataProvider to perform automatic column spanning @@ -93,7 +99,7 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe * @param autoRowSpan Flag to configure this AutomaticSpanningDataProvider to perform * automatic row spanning */ - public AutomaticSpanningDataProvider(final IDataProvider underlyingDataProvider, + public AutomaticSpanningDataProvider(final DataProvider underlyingDataProvider, final boolean autoColumnSpan, final boolean autoRowSpan) { this.underlyingDataProvider= underlyingDataProvider; this.autoColumnSpan= autoColumnSpan; @@ -101,12 +107,14 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe } @Override - public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, final IProgressMonitor monitor) { + public @Nullable Object getDataValue(final long columnIndex, final long rowIndex, + final int flags, final @Nullable IProgressMonitor monitor) { return this.underlyingDataProvider.getDataValue(columnIndex, rowIndex, flags, monitor); } @Override - public void setDataValue(final long columnIndex, final long rowIndex, final Object newValue) { + public void setDataValue(final long columnIndex, final long rowIndex, + final @Nullable Object newValue) { this.underlyingDataProvider.setDataValue(columnIndex, rowIndex, newValue); } @@ -135,6 +143,7 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe return new DataCell(cellColumnPosition, cellRowPosition, columnSpan, rowSpan); } + /** * Check if the given column should be used for auto spanning. * @param columnPosition The column position to check for auto spanning @@ -144,7 +153,7 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe protected boolean isAutoSpanEnabledForColumn(final long columnPosition, final long rowPosition) { return (this.autoColumnSpan && isAutoSpanRow(rowPosition)); } - + /** * Check if the given row should be used for auto spanning. * @param columnPosition The column position for which the row spanning should be checked. @@ -180,8 +189,8 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe * won't be auto spanned anymore. * @param columnPositions The column positions to add for auto spanning. */ - public void addAutoSpanningColumnPositions(final Long... columnPositions) { - this.autoSpanColumns.addAll(Arrays.asList(columnPositions)); + public void addAutoSpanningColumnPositions(final ImList<Long> columnPositions) { + this.autoSpanColumns.addAll(columnPositions); } /** @@ -191,24 +200,24 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe * be auto spanned anymore. * @param rowPositions The row positions to add for auto spanning. */ - public void addAutoSpanningRowPositions(final Long... rowPositions) { - this.autoSpanRows.addAll(Arrays.asList(rowPositions)); + public void addAutoSpanningRowPositions(final ImList<Long> rowPositions) { + this.autoSpanRows.addAll(rowPositions); } /** * Removes the given column positions for auto spanning. * @param columnPositions The column positions to remove for auto spanning. */ - public void removeAutoSpanningColumnPositions(final Long... columnPositions) { - this.autoSpanColumns.removeAll(Arrays.asList(columnPositions)); + public void removeAutoSpanningColumnPositions(final ImList<Long> columnPositions) { + this.autoSpanColumns.removeAll(columnPositions); } /** * Removes the given row positions for auto spanning. * @param rowPositions The row positions to remove for auto spanning. */ - public void removeAutoSpanningRowPositions(final Long... rowPositions) { - this.autoSpanRows.removeAll(Arrays.asList(rowPositions)); + public void removeAutoSpanningRowPositions(final ImList<Long> rowPositions) { + this.autoSpanRows.removeAll(rowPositions); } /** @@ -236,7 +245,7 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe * @param columnPosition The column position whose spanning starting column is searched * @param rowPosition The row position where the column spanning should be performed. * @return The column position where the spanning starts or the given column position - * if it is not spanned with the columns to the left. + * if it is not spanned with the columns to the left. */ protected long getStartColumnPosition(final long columnPosition, final long rowPosition) { if (columnPosition <= 0 || !isAutoSpanColumn(columnPosition) || !isAutoSpanColumn(columnPosition-1)) { @@ -357,47 +366,48 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe this.autoRowSpan= autoRowSpan; } + @Override - public void saveState(final String prefix, final Properties properties) { - properties.setProperty(prefix + PERSISTENCE_KEY_AUTO_COLUMN_SPAN, Boolean.valueOf(this.autoColumnSpan).toString()); - properties.setProperty(prefix + PERSISTENCE_KEY_AUTO_ROW_SPAN, Boolean.valueOf(this.autoRowSpan).toString()); + public void saveState(final String prefix, final Map<String, String> properties) { + properties.put(prefix + PERSISTENCE_KEY_AUTO_COLUMN_SPAN, Boolean.toString(this.autoColumnSpan)); + properties.put(prefix + PERSISTENCE_KEY_AUTO_ROW_SPAN, Boolean.toString(this.autoRowSpan)); if (this.autoSpanColumns.size() > 0) { final StringBuilder strBuilder= new StringBuilder(); for (final Long index : this.autoSpanColumns) { strBuilder.append(index); - strBuilder.append(IPersistable.VALUE_SEPARATOR); + strBuilder.append(Persistable.VALUE_SEPARATOR); } - properties.setProperty(prefix + PERSISTENCE_KEY_AUTO_SPAN_COLUMNS, strBuilder.toString()); + properties.put(prefix + PERSISTENCE_KEY_AUTO_SPAN_COLUMNS, strBuilder.toString()); } if (this.autoSpanRows.size() > 0) { final StringBuilder strBuilder= new StringBuilder(); for (final Long index : this.autoSpanRows) { strBuilder.append(index); - strBuilder.append(IPersistable.VALUE_SEPARATOR); + strBuilder.append(Persistable.VALUE_SEPARATOR); } - properties.setProperty(prefix + PERSISTENCE_KEY_AUTO_SPAN_ROWS, strBuilder.toString()); + properties.put(prefix + PERSISTENCE_KEY_AUTO_SPAN_ROWS, strBuilder.toString()); } } @Override - public void loadState(final String prefix, final Properties properties) { - String property= properties.getProperty(prefix + PERSISTENCE_KEY_AUTO_COLUMN_SPAN); + public void loadState(final String prefix, final Map<String, String> properties) { + String property= properties.get(prefix + PERSISTENCE_KEY_AUTO_COLUMN_SPAN); if (property != null) { - this.autoColumnSpan= Boolean.valueOf(property); + this.autoColumnSpan= Boolean.parseBoolean(property); } - property= properties.getProperty(prefix + PERSISTENCE_KEY_AUTO_ROW_SPAN); + property= properties.get(prefix + PERSISTENCE_KEY_AUTO_ROW_SPAN); if (property != null) { - this.autoRowSpan= Boolean.valueOf(property); + this.autoRowSpan= Boolean.parseBoolean(property); } this.autoSpanColumns.clear(); - property= properties.getProperty(prefix + PERSISTENCE_KEY_AUTO_SPAN_COLUMNS); + property= properties.get(prefix + PERSISTENCE_KEY_AUTO_SPAN_COLUMNS); if (property != null) { final List<Long> newAutoSpanColumns= new ArrayList<>(); - final StringTokenizer tok= new StringTokenizer(property, IPersistable.VALUE_SEPARATOR); + final StringTokenizer tok= new StringTokenizer(property, Persistable.VALUE_SEPARATOR); while (tok.hasMoreTokens()) { final String index= tok.nextToken(); newAutoSpanColumns.add(Long.valueOf(index)); @@ -407,10 +417,10 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe } this.autoSpanRows.clear(); - property= properties.getProperty(prefix + PERSISTENCE_KEY_AUTO_SPAN_ROWS); + property= properties.get(prefix + PERSISTENCE_KEY_AUTO_SPAN_ROWS); if (property != null) { final List<Long> newAutoSpanRows= new ArrayList<>(); - final StringTokenizer tok= new StringTokenizer(property, IPersistable.VALUE_SEPARATOR); + final StringTokenizer tok= new StringTokenizer(property, Persistable.VALUE_SEPARATOR); while (tok.hasMoreTokens()) { final String index= tok.nextToken(); newAutoSpanRows.add(Long.valueOf(index)); @@ -419,4 +429,5 @@ public class AutomaticSpanningDataProvider implements ISpanningDataProvider, IPe this.autoSpanRows.addAll(newAutoSpanRows); } } + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummyBodyDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummyBodyDataProvider.java index 5ddd0c6d..f3743ecd 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummyBodyDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummyBodyDataProvider.java @@ -11,18 +11,18 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.util.data; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.coordinate.LPoint; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LPoint; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; -public class DummyBodyDataProvider implements IDataProvider { +public class DummyBodyDataProvider implements DataProvider { private final long columnCount; diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummyColumnHeaderDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummyColumnHeaderDataProvider.java index 414cec3a..5d9d0524 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummyColumnHeaderDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummyColumnHeaderDataProvider.java @@ -11,20 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.util.data; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; -public class DummyColumnHeaderDataProvider implements IDataProvider { +public class DummyColumnHeaderDataProvider implements DataProvider { - private final IDataProvider bodyDataProvider; + private final DataProvider bodyDataProvider; - public DummyColumnHeaderDataProvider(final IDataProvider bodyDataProvider) { + public DummyColumnHeaderDataProvider(final DataProvider bodyDataProvider) { this.bodyDataProvider= bodyDataProvider; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummySpanningBodyDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummySpanningBodyDataProvider.java index 27fa3177..b9b16c15 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DummySpanningBodyDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/DummySpanningBodyDataProvider.java @@ -11,18 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.util.data; -import org.eclipse.statet.ecommons.waltable.data.ISpanningDataProvider; -import org.eclipse.statet.ecommons.waltable.layer.cell.DataCell; +import org.eclipse.statet.ecommons.waltable.core.data.DataCell; +import org.eclipse.statet.ecommons.waltable.core.data.SpanningDataProvider; -public class DummySpanningBodyDataProvider extends DummyBodyDataProvider implements ISpanningDataProvider { +public class DummySpanningBodyDataProvider extends DummyBodyDataProvider implements SpanningDataProvider { private static final long BLOCK_SIZE= 4; - + private static final long CELL_SPAN= 2; + public DummySpanningBodyDataProvider(final long columnCount, final long rowCount) { super(columnCount, rowCount); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnPropertyAccessor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnAccessor.java index 094364fb..6a83c480 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnPropertyAccessor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnAccessor.java @@ -11,9 +11,11 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.util.data; +import org.eclipse.statet.ecommons.waltable.core.data.ColumnAccessor; -public interface IColumnPropertyAccessor<T> extends IColumnAccessor<T>, IColumnPropertyResolver { + +public interface PropertyColumnAccessor<T> extends ColumnAccessor<T>, PropertyColumnResolver { } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultColumnHeaderDataProvider.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnHeaderDataProvider.java index f38d5727..823fc5aa 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/grid/data/DefaultColumnHeaderDataProvider.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnHeaderDataProvider.java @@ -11,50 +11,40 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.grid.data; +package org.eclipse.statet.ecommons.waltable.util.data; + +import static org.eclipse.statet.jcommons.lang.ObjectUtils.nonNullAssert; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.statet.ecommons.waltable.data.IDataProvider; +import org.eclipse.statet.jcommons.collections.ImList; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.data.DataProvider; -public class DefaultColumnHeaderDataProvider implements IDataProvider { - + +@NonNullByDefault +public class PropertyColumnHeaderDataProvider implements DataProvider { - private final String[] propertyNames; - private Map<String, String> propertyToLabelMap; + private final ImList<String> propertyNames; + private final @Nullable Map<String, String> propertyToLabelMap; - public DefaultColumnHeaderDataProvider(final String[] columnLabels) { - this.propertyNames= columnLabels; - } - public DefaultColumnHeaderDataProvider(final String[] propertyNames, final Map<String, String> propertyToLabelMap) { - this.propertyNames= propertyNames; + public PropertyColumnHeaderDataProvider(final ImList<String> propertyNames, + final Map<String, String> propertyToLabelMap) { + this.propertyNames= nonNullAssert(propertyNames); this.propertyToLabelMap= propertyToLabelMap; } - public String getColumnHeaderLabel(final long columnIndex) { - if (columnIndex >= Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - final String propertyName= this.propertyNames[(int) columnIndex]; - if (this.propertyToLabelMap != null) { - final String label= this.propertyToLabelMap.get(propertyName); - if (label != null) { - return label; - } - } - return propertyName; - } - @Override public long getColumnCount() { - return this.propertyNames.length; + return this.propertyNames.size(); } @Override @@ -66,12 +56,23 @@ public class DefaultColumnHeaderDataProvider implements IDataProvider { * This class does not support multiple rows in the column header layer. */ @Override - public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, final IProgressMonitor monitor) { - return getColumnHeaderLabel(columnIndex); + public Object getDataValue(final long columnIndex, final long rowIndex, final int flags, + final @Nullable IProgressMonitor monitor) { + if (columnIndex < 0 || columnIndex >= this.propertyNames.size()) { + throw new IndexOutOfBoundsException(); + } + final String propertyName= this.propertyNames.get((int)columnIndex); + if (this.propertyToLabelMap != null) { + final String label= this.propertyToLabelMap.get(propertyName); + if (label != null) { + return label; + } + } + return propertyName; } @Override - public void setDataValue(final long columnIndex, final long rowIndex, final Object newValue) { + public void setDataValue(final long columnIndex, final long rowIndex, final @Nullable Object newValue) { throw new UnsupportedOperationException(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnPropertyResolver.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnResolver.java index ceefa29a..9376ba49 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/IColumnPropertyResolver.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/PropertyColumnResolver.java @@ -11,14 +11,17 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.util.data; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; /** * Maps between the column property name in the backing data bean * and its corresponding column index. */ -public interface IColumnPropertyResolver { +@NonNullByDefault +public interface PropertyColumnResolver { /** diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ReflectiveColumnPropertyAccessor.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/ReflectivePropertyColumnAccessor.java index f8cbc82b..b06facea 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/data/ReflectiveColumnPropertyAccessor.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/util/data/ReflectivePropertyColumnAccessor.java @@ -11,13 +11,12 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.data; +package org.eclipse.statet.ecommons.waltable.util.data; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,92 +24,106 @@ import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.lang.NonNull; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + import org.eclipse.statet.internal.ecommons.waltable.WaLTablePlugin; /** - * Convenience class which uses java reflection to get/set property names - * from the row bean. It looks for getter methods for reading and setter - * methods for writing according to the Java conventions. + * Convenience class which uses java reflection to get/set property names from the row bean. It + * looks for getter methods for reading and setter methods for writing according to the Java + * conventions. * * @param <R> type of the row object/bean */ -public class ReflectiveColumnPropertyAccessor<R> implements IColumnPropertyAccessor<R> { +@NonNullByDefault +public class ReflectivePropertyColumnAccessor<R> implements PropertyColumnAccessor<R> { private final List<String> propertyNames; - - private Map<String, PropertyDescriptor> propertyDescriptorMap; - + + private final Map<Class<?>, Map<String, PropertyDescriptor>> propertyDescriptorMap= new HashMap<>(); + + /** * @param propertyNames of the members of the row bean */ - public ReflectiveColumnPropertyAccessor(final String[] propertyNames) { - this.propertyNames= Arrays.asList(propertyNames); + public ReflectivePropertyColumnAccessor(final @NonNull String... propertyNames) { + this.propertyNames= ImCollections.newList(propertyNames); } - + + @Override public long getColumnCount() { return this.propertyNames.size(); } @Override - public Object getDataValue(final R rowObj, final long columnIndex) { + public @Nullable Object getDataValue(final R rowObj, final long columnIndex) { try { - final PropertyDescriptor propertyDesc= getPropertyDescriptor(rowObj, columnIndex); + final PropertyDescriptor propertyDesc= getPropertyDescriptor(rowObj, + getColumnProperty(columnIndex) ); final Method readMethod= propertyDesc.getReadMethod(); return readMethod.invoke(rowObj); - } catch (final Exception e) { + } + catch (final Exception e) { throw new RuntimeException(e); } } - + @Override - public void setDataValue(final R rowObj, final long columnIndex, final Object newValue) { + public void setDataValue(final @NonNull R rowObj, final long columnIndex, final @Nullable Object newValue) { try { - final PropertyDescriptor propertyDesc= getPropertyDescriptor(rowObj, columnIndex); + final PropertyDescriptor propertyDesc= getPropertyDescriptor(rowObj, + getColumnProperty(columnIndex) ); final Method writeMethod= propertyDesc.getWriteMethod(); if (writeMethod == null) { throw new RuntimeException("Setter method not found in backing bean for value at column index: " + columnIndex); //$NON-NLS-1$ } writeMethod.invoke(rowObj, newValue); - } catch (final IllegalArgumentException ex) { + } + catch (final IllegalArgumentException ex) { WaLTablePlugin.log(new Status(IStatus.WARNING, WaLTablePlugin.BUNDLE_ID, "Data type being set does not match the data type of the setter method in the backing bean", ex )); //$NON-NLS-1$ - } catch (final Exception e) { + } + catch (final Exception e) { WaLTablePlugin.log(new Status(IStatus.ERROR, WaLTablePlugin.BUNDLE_ID, "Error while setting data value", e )); //$NON-NLS-1$ throw new RuntimeException("Error while setting data value"); //$NON-NLS-1$ } } - + @Override public String getColumnProperty(final long columnIndex) { - if (columnIndex >= Integer.MAX_VALUE) { + if (columnIndex < 0 || columnIndex >= Integer.MAX_VALUE) { throw new IndexOutOfBoundsException(); } - return this.propertyNames.get((int) columnIndex); + return this.propertyNames.get((int)columnIndex); } - + @Override public long getColumnIndex(final String propertyName) { return this.propertyNames.indexOf(propertyName); } - - private PropertyDescriptor getPropertyDescriptor(final R rowObj, final long columnIndex) throws IntrospectionException { - if (columnIndex >= Integer.MAX_VALUE) { - throw new IndexOutOfBoundsException(); - } - if (this.propertyDescriptorMap == null) { - this.propertyDescriptorMap= new HashMap<>(); - final PropertyDescriptor[] propertyDescriptors= Introspector.getBeanInfo(rowObj.getClass()).getPropertyDescriptors(); - for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { - this.propertyDescriptorMap.put(propertyDescriptor.getName(), propertyDescriptor); + + protected PropertyDescriptor getPropertyDescriptor(final @NonNull R rowObj, + final String propertyName) throws IntrospectionException { + synchronized (this.propertyDescriptorMap) { + var map= this.propertyDescriptorMap.get(rowObj.getClass()); + if (map == null) { + final PropertyDescriptor[] propertyDescriptors= + Introspector.getBeanInfo(rowObj.getClass()).getPropertyDescriptors(); + map= new HashMap<>(); + for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { + map.put(propertyDescriptor.getName(), propertyDescriptor); + } + this.propertyDescriptorMap.put(rowObj.getClass(), map); } + return map.get(propertyName); } - - final String propertyName= this.propertyNames.get((int) columnIndex); - return this.propertyDescriptorMap.get(propertyName); } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/RecalculateScrollBarsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/RecalculateScrollBarsCommand.java index 6b10646a..47c7eb65 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/RecalculateScrollBarsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/RecalculateScrollBarsCommand.java @@ -11,13 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractContextFreeCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; + +@NonNullByDefault public class RecalculateScrollBarsCommand extends AbstractContextFreeCommand { + public RecalculateScrollBarsCommand() { } + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/RecalculateScrollBarsCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/RecalculateScrollBarsCommandHandler.java index 0d04a07b..cd766612 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/RecalculateScrollBarsCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/RecalculateScrollBarsCommandHandler.java @@ -11,15 +11,20 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; + +@NonNullByDefault public class RecalculateScrollBarsCommandHandler extends AbstractLayerCommandHandler<RecalculateScrollBarsCommand> { + private final ViewportLayer viewportLayer; - + + public RecalculateScrollBarsCommandHandler(final ViewportLayer viewportLayer) { this.viewportLayer= viewportLayer; } @@ -28,11 +33,11 @@ public class RecalculateScrollBarsCommandHandler extends AbstractLayerCommandHan public Class<RecalculateScrollBarsCommand> getCommandClass() { return RecalculateScrollBarsCommand.class; } - + @Override protected boolean doCommand(final RecalculateScrollBarsCommand command) { this.viewportLayer.recalculateScrollBars(); return true; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollEvent.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollEvent.java new file mode 100644 index 00000000..b7fdf9f0 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollEvent.java @@ -0,0 +1,45 @@ +/*=============================================================================# + # Copyright (c) 2012, 2021 Original NatTable authors and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0. + # + # SPDX-License-Identifier: EPL-2.0 + # + # Contributors: + # Original NatTable authors and others - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.viewport.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.GeneralStructuralChangeEvent; + + +@NonNullByDefault +public class ScrollEvent extends GeneralStructuralChangeEvent { + + + public ScrollEvent(final ViewportLayer viewportLayer) { + super(viewportLayer); + } + + protected ScrollEvent(final Layer event) { + super(event); + } + + @Override + public @Nullable ScrollEvent toLayer(final Layer targetLayer) { + if (targetLayer == getLayer()) { + return this; + } + + return new ScrollEvent(targetLayer); + } + + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollPageCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollPageCommand.java index 7c341cf8..8c1ae69c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollPageCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollPageCommand.java @@ -12,12 +12,15 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractRelativeCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractRelativeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; + +@NonNullByDefault public class ScrollPageCommand extends AbstractRelativeCommand { @@ -25,14 +28,5 @@ public class ScrollPageCommand extends AbstractRelativeCommand { super(direction, 1); } - protected ScrollPageCommand(final ScrollPageCommand command) { - super(command); - } - - @Override - public ScrollPageCommand cloneCommand() { - return new ScrollPageCommand(this); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollPageCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollPageCommandHandler.java index 63919c69..8de22557 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollPageCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollPageCommandHandler.java @@ -12,13 +12,16 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; -public class ScrollPageCommandHandler extends AbstractLayerCommandHandler<ScrollPageCommand> { + +@NonNullByDefault +public class ScrollPageCommandHandler implements LayerCommandHandler<ScrollPageCommand> { private final ViewportLayer viewportLayer; @@ -35,14 +38,14 @@ public class ScrollPageCommandHandler extends AbstractLayerCommandHandler<Scroll @Override - protected boolean doCommand(final ScrollPageCommand command) { + public boolean executeCommand(final ScrollPageCommand command) { final Direction direction= command.getDirection(); - final IViewportDim dim= this.viewportLayer.getDim(direction.getOrientation()); + final var viewportDim= this.viewportLayer.getDim(direction.getOrientation()); if (direction.isBackward()) { - dim.scrollBackwardByPage(); + viewportDim.scrollBackwardByPage(); } else /*if (direction.isForward())*/ { - dim.scrollForwardByPage(); + viewportDim.scrollForwardByPage(); } return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollStepCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollStepCommand.java index 80b9b5ad..80d23f40 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollStepCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollStepCommand.java @@ -12,12 +12,15 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractRelativeCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractRelativeCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; + +@NonNullByDefault public class ScrollStepCommand extends AbstractRelativeCommand { @@ -25,14 +28,5 @@ public class ScrollStepCommand extends AbstractRelativeCommand { super(direction, 1); } - protected ScrollStepCommand(final ScrollStepCommand command) { - super(command); - } - - @Override - public ScrollStepCommand cloneCommand() { - return new ScrollStepCommand(this); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollStepCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollStepCommandHandler.java index 68a9afc6..7e68899d 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollStepCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ScrollStepCommandHandler.java @@ -12,13 +12,16 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; -public class ScrollStepCommandHandler extends AbstractLayerCommandHandler<ScrollStepCommand> { + +@NonNullByDefault +public class ScrollStepCommandHandler implements LayerCommandHandler<ScrollStepCommand> { private final ViewportLayer viewportLayer; @@ -35,14 +38,14 @@ public class ScrollStepCommandHandler extends AbstractLayerCommandHandler<Scroll @Override - protected boolean doCommand(final ScrollStepCommand command) { + public boolean executeCommand(final ScrollStepCommand command) { final Direction direction= command.getDirection(); - final IViewportDim dim= this.viewportLayer.getDim(direction.getOrientation()); + final var viewportDim= this.viewportLayer.getDim(direction.getOrientation()); if (direction.isBackward()) { - dim.scrollBackwardByStep(); + viewportDim.scrollBackwardByStep(); } else /*if (direction.isForward())*/ { - dim.scrollForwardByStep(); + viewportDim.scrollForwardByStep(); } return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/SelectRelativePageCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/SelectRelativePageCommand.java index a93ca861..9f94b89b 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/SelectRelativePageCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/SelectRelativePageCommand.java @@ -12,27 +12,21 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.coordinate.Direction; -import org.eclipse.statet.ecommons.waltable.selection.AbstractSelectRelativeCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; - -public class SelectRelativePageCommand extends AbstractSelectRelativeCommand { +import org.eclipse.statet.ecommons.waltable.core.coordinate.Direction; +import org.eclipse.statet.ecommons.waltable.selection.core.AbstractSelectRelativeCommand; +@NonNullByDefault +public class SelectRelativePageCommand extends AbstractSelectRelativeCommand { + + public SelectRelativePageCommand(final Direction direction, final int selectionFlags) { super(direction, 1, selectionFlags); } - - protected SelectRelativePageCommand(final SelectRelativePageCommand command) { - super(command); - } - - @Override - public SelectRelativePageCommand cloneCommand() { - return new SelectRelativePageCommand(this); - } - - + + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/SelectRelativePageCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/SelectRelativePageCommandHandler.java new file mode 100644 index 00000000..d6652e41 --- /dev/null +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/SelectRelativePageCommandHandler.java @@ -0,0 +1,61 @@ +/*=============================================================================# + # Copyright (c) 2010, 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.ecommons.waltable.viewport.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectRelativeCellCommand; + + +@NonNullByDefault +public class SelectRelativePageCommandHandler implements LayerCommandHandler<SelectRelativePageCommand> { + + + private final Layer viewportLayer; + + + public SelectRelativePageCommandHandler(final Layer viewportLayer) { + this.viewportLayer= viewportLayer; + } + + + @Override + public Class<SelectRelativePageCommand> getCommandClass() { + return SelectRelativePageCommand.class; + } + + @Override + public boolean executeCommand(final SelectRelativePageCommand command) { + long stepCount; + switch (command.getDirection()) { + case UP: + case DOWN: + stepCount= this.viewportLayer.getRowCount(); + break; + case LEFT: + case RIGHT: + stepCount= this.viewportLayer.getColumnCount(); + break; + default: + throw new IllegalStateException(); + } + this.viewportLayer.doCommand(new SelectRelativeCellCommand( + command.getDirection(), stepCount, command.getSelectionFlags() )); + return true; + } + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowCellInViewportCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowCellInViewportCommand.java index 5a43c654..72e82dfb 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowCellInViewportCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowCellInViewportCommand.java @@ -11,15 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; import org.eclipse.statet.ecommons.waltable.command.AbstractPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +@NonNullByDefault public class ShowCellInViewportCommand extends AbstractPositionCommand { - public ShowCellInViewportCommand(final ILayer layer, final long columnPosition, final long rowPosition) { + + public ShowCellInViewportCommand(final Layer layer, final long columnPosition, final long rowPosition) { super(layer, columnPosition, rowPosition); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowCellInViewportCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowCellInViewportCommandHandler.java index 94fe98e1..19df0c19 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowCellInViewportCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowCellInViewportCommandHandler.java @@ -11,14 +11,17 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; + +@NonNullByDefault public class ShowCellInViewportCommandHandler extends AbstractLayerCommandHandler<ShowCellInViewportCommand> { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowDimPositionInViewportCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowDimPositionInViewportCommand.java index 70fc4c4b..bbc20086 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowDimPositionInViewportCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowDimPositionInViewportCommand.java @@ -11,16 +11,19 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractDimPositionCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractDimPositionCommand; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; + +@NonNullByDefault public class ShowDimPositionInViewportCommand extends AbstractDimPositionCommand { - public ShowDimPositionInViewportCommand(final ILayerDim layerDim, final long position) { + public ShowDimPositionInViewportCommand(final LayerDim layerDim, final long position) { super(layerDim, position); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowPositionInViewportCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowDimPositionInViewportCommandHandler.java index 3b8f4cf5..e8c58162 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ShowPositionInViewportCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ShowDimPositionInViewportCommandHandler.java @@ -11,27 +11,34 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; -public class ShowPositionInViewportCommandHandler extends AbstractLayerCommandHandler<ShowDimPositionInViewportCommand> { + +@NonNullByDefault +public class ShowDimPositionInViewportCommandHandler extends AbstractLayerCommandHandler<ShowDimPositionInViewportCommand> { + + + private final ViewportLayer viewportLayer; - public ShowPositionInViewportCommandHandler() { + public ShowDimPositionInViewportCommandHandler(final ViewportLayer viewportLayer) { + this.viewportLayer= viewportLayer; } + @Override public Class<ShowDimPositionInViewportCommand> getCommandClass() { return ShowDimPositionInViewportCommand.class; } - @Override protected boolean doCommand(final ShowDimPositionInViewportCommand command) { - final IViewportDim dim= (IViewportDim) command.getDim(); - dim.movePositionIntoViewport(command.getPosition()); + final var viewportDim= this.viewportLayer.getDim(command.getOrientation()); + viewportDim.movePositionIntoViewport(command.getPosition()); return true; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportDragCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportDragCommand.java index 75ef483e..0c5fcf65 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportDragCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportDragCommand.java @@ -11,17 +11,21 @@ # Edwin Park - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractContextFreeCommand; -public class ViewportDragCommand implements ILayerCommand { +@NonNullByDefault +public class ViewportDragCommand extends AbstractContextFreeCommand { + + private final long x; private final long y; - + + public ViewportDragCommand(final long x, final long y) { this.x= x; this.y= y; @@ -35,14 +39,4 @@ public class ViewportDragCommand implements ILayerCommand { return this.y; } - @Override - public boolean convertToTargetLayer(final ILayer targetLayer) { - return true; - } - - @Override - public ILayerCommand cloneCommand() { - return new ViewportDragCommand(this.x, this.y); - } - } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportDragCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportDragCommandHandler.java index 32876bbb..6016fa11 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportDragCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportDragCommandHandler.java @@ -11,28 +11,35 @@ # Edwin Park - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommandHandler; -public class ViewportDragCommandHandler extends AbstractLayerCommandHandler<ViewportDragCommand> { +@NonNullByDefault +public class ViewportDragCommandHandler implements LayerCommandHandler<ViewportDragCommand> { + + private final ViewportLayer viewportLayer; - + + public ViewportDragCommandHandler(final ViewportLayer viewportLayer) { this.viewportLayer= viewportLayer; } - + + @Override public Class<ViewportDragCommand> getCommandClass() { return ViewportDragCommand.class; } - + + @Override - protected boolean doCommand(final ViewportDragCommand command) { + public boolean executeCommand(final ViewportDragCommand command) { this.viewportLayer.drag(command.getX(), command.getY()); return true; } - + } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportLayer.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayer.java index cd890199..3230ac3f 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportLayer.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayer.java @@ -12,31 +12,32 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - dim-based implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL; -import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.VERTICAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.HORIZONTAL; +import static org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation.VERTICAL; import org.eclipse.swt.widgets.Display; -import org.eclipse.statet.ecommons.waltable.command.ILayerCommand; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.LRectangle; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.grid.ClientAreaResizeCommand; -import org.eclipse.statet.ecommons.waltable.layer.ILayer; -import org.eclipse.statet.ecommons.waltable.layer.TransformLayer; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.event.ILayerEvent; -import org.eclipse.statet.ecommons.waltable.layer.event.IStructuralChangeEvent; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.command.LayerCommand; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRectangle; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.Layer; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerEvent; +import org.eclipse.statet.ecommons.waltable.core.layer.TransformLayer; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralChangeEvent; +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; +import org.eclipse.statet.ecommons.waltable.grid.core.ClientAreaResizeCommand; import org.eclipse.statet.ecommons.waltable.print.PrintEntireGridCommand; import org.eclipse.statet.ecommons.waltable.print.TurnViewportOffCommand; import org.eclipse.statet.ecommons.waltable.print.TurnViewportOnCommand; -import org.eclipse.statet.ecommons.waltable.selection.CellSelectionEvent; -import org.eclipse.statet.ecommons.waltable.selection.ColumnSelectionEvent; -import org.eclipse.statet.ecommons.waltable.selection.RowSelectionEvent; -import org.eclipse.statet.ecommons.waltable.selection.SelectionLayer; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.selection.core.CellSelectionEvent; +import org.eclipse.statet.ecommons.waltable.selection.core.DimSelectionEvent; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectionLayer; /** @@ -46,14 +47,15 @@ import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; * keeps them in sync with the data being displayed. This is typically placed over the * {@link SelectionLayer}. */ -public class ViewportLayer extends TransformLayer { +@NonNullByDefault +public class ViewportLayer extends TransformLayer<ViewportLayerDim> { static final int EDGE_HOVER_REGION_SIZE= 16; static final int PAGE_INTERSECTION_SIZE= EDGE_HOVER_REGION_SIZE; - private final ILayer scrollableLayer; + private final Layer scrollableLayer; // The viewport current origin private boolean viewportOff= false; @@ -68,15 +70,20 @@ public class ViewportLayer extends TransformLayer { * * @param underlyingLayer the underlying scrollable layer */ - public ViewportLayer(/*@NonNull*/ final ILayer underlyingLayer) { + public ViewportLayer(final Layer underlyingLayer) { super(underlyingLayer); this.scrollableLayer= underlyingLayer; - registerCommandHandlers(); + init(); - initDims(); + registerCommandHandlers(); } + @Override + protected ViewportLayerDimImpl createDim(final Orientation orientation) { + final Layer scrollable= getScrollableLayer(); + return new ViewportLayerDimImpl(this, scrollable.getDim(orientation)); + } @Override public void dispose() { @@ -95,32 +102,20 @@ public class ViewportLayer extends TransformLayer { } - @Override - protected void initDims() { - final ILayer scrollable= getScrollableLayer(); - if (scrollable == null) { - return; - } - for (final Orientation orientation : Orientation.values()) { - disposeDim(orientation); - setDim(new ViewportLayerDim(this, scrollable.getDim(orientation))); - } - } - protected void disposeDim(final Orientation orientation) { - final ViewportLayerDim dim= get(orientation); + final ViewportLayerDimImpl dim= get(orientation); if (dim != null) { dim.dispose(); } } @Override - public IViewportDim getDim(final Orientation orientation) { - return (IViewportDim) super.getDim(orientation); + public ViewportLayerDim getDim(final Orientation orientation) { + return super.getDim(orientation); } - final ViewportLayerDim get(final Orientation orientation) { - return (ViewportLayerDim) super.getDim(orientation); + final ViewportLayerDimImpl get(final Orientation orientation) { + return (ViewportLayerDimImpl)super.getDim(orientation); } // Configuration @@ -129,7 +124,7 @@ public class ViewportLayer extends TransformLayer { protected void registerCommandHandlers() { registerCommandHandler(new RecalculateScrollBarsCommandHandler(this)); registerCommandHandler(new ShowCellInViewportCommandHandler(this)); - registerCommandHandler(new ShowPositionInViewportCommandHandler()); + registerCommandHandler(new ShowDimPositionInViewportCommandHandler(this)); registerCommandHandler(new ViewportSelectDimPositionsCommandHandler(this)); registerCommandHandler(new ViewportDragCommandHandler(this)); registerCommandHandler(new SelectRelativePageCommandHandler(this)); @@ -141,7 +136,7 @@ public class ViewportLayer extends TransformLayer { // Cell features @Override - public ILayerCell getCellByPosition(final long columnPosition, final long rowPosition) { + public LayerCell getCellByPosition(final long columnPosition, final long rowPosition) { return super.getCellByPosition(columnPosition, rowPosition); } @@ -150,32 +145,30 @@ public class ViewportLayer extends TransformLayer { } @Override - public boolean doCommand(final ILayerCommand command) { + public boolean doCommand(final LayerCommand command) { if (command instanceof ClientAreaResizeCommand) { final ClientAreaResizeCommand clientAreaResizeCommand= (ClientAreaResizeCommand) command.cloneCommand(); - if (clientAreaResizeCommand.convertToTargetLayer(this)) { - //remember the difference from client area to body region area - //needed because the scrollbar will be removed and therefore the client area will become bigger - final long widthDiff= clientAreaResizeCommand.getScrollable().getClientArea().width - clientAreaResizeCommand.getCalcArea().width; - final long heightDiff= clientAreaResizeCommand.getScrollable().getClientArea().height - clientAreaResizeCommand.getCalcArea().height; - - get(HORIZONTAL).checkScrollBar(clientAreaResizeCommand.getScrollable()); - get(VERTICAL).checkScrollBar(clientAreaResizeCommand.getScrollable()); - - get(HORIZONTAL).handleResize(); - get(VERTICAL).handleResize(); - - //after handling the scrollbars recalculate the area to use for percentage calculation - final LRectangle possibleArea= SWTUtil.toNatTable(clientAreaResizeCommand.getScrollable().getClientArea()); - possibleArea.width-= widthDiff; - possibleArea.height-= heightDiff; - clientAreaResizeCommand.setCalcArea(possibleArea); - //we don't return true here because the ClientAreaResizeCommand needs to be handled - //by the DataLayer in case percentage sizing is enabled - //if we would return true, the DataLayer wouldn't be able to calculate the column/row - //sizes regarding the client area - return super.doCommand(clientAreaResizeCommand); - } + //remember the difference from client area to body region area + //needed because the scrollbar will be removed and therefore the client area will become bigger + final long widthDiff= clientAreaResizeCommand.getScrollable().getClientArea().width - clientAreaResizeCommand.getCalcArea().width; + final long heightDiff= clientAreaResizeCommand.getScrollable().getClientArea().height - clientAreaResizeCommand.getCalcArea().height; + + get(HORIZONTAL).checkScrollBar(clientAreaResizeCommand.getScrollable()); + get(VERTICAL).checkScrollBar(clientAreaResizeCommand.getScrollable()); + + get(HORIZONTAL).handleResize(); + get(VERTICAL).handleResize(); + + //after handling the scrollbars recalculate the area to use for percentage calculation + final LRectangle possibleArea= SwtUtils.toNatTable(clientAreaResizeCommand.getScrollable().getClientArea()); + possibleArea.width-= widthDiff; + possibleArea.height-= heightDiff; + clientAreaResizeCommand.setCalcArea(possibleArea); + //we don't return true here because the ClientAreaResizeCommand needs to be handled + //by the DataLayer in case percentage sizing is enabled + //if we would return true, the DataLayer wouldn't be able to calculate the column/row + //sizes regarding the client area + return super.doCommand(clientAreaResizeCommand); } else if (command instanceof TurnViewportOffCommand) { if (!isViewportOff()) { @@ -215,23 +208,22 @@ public class ViewportLayer extends TransformLayer { // Event handling @Override - public void handleLayerEvent(final ILayerEvent event) { - if (event instanceof IStructuralChangeEvent) { - final IStructuralChangeEvent structuralChangeEvent= (IStructuralChangeEvent) event; - if (structuralChangeEvent.isHorizontalStructureChanged()) { - get(HORIZONTAL).handleStructuralChange(structuralChangeEvent.getColumnDiffs()); - } - if (structuralChangeEvent.isVerticalStructureChanged()) { - get(VERTICAL).handleStructuralChange(structuralChangeEvent.getRowDiffs()); + public void handleLayerEvent(final LayerEvent event) { + if (event instanceof StructuralChangeEvent) { + final StructuralChangeEvent structuralChangeEvent= (StructuralChangeEvent)event; + for (final var orientation : Orientation.values()) { + if (structuralChangeEvent.isStructureChanged(orientation)) { + final var dim= get(orientation); + dim.handleStructuralChange(structuralChangeEvent.getDiffs(orientation)); + } } } if (event instanceof CellSelectionEvent) { processSelection((CellSelectionEvent) event); - } else if (event instanceof ColumnSelectionEvent) { - processColumnSelection((ColumnSelectionEvent) event); - } else if (event instanceof RowSelectionEvent) { - processRowSelection((RowSelectionEvent) event); + } + else if (event instanceof DimSelectionEvent) { + processDimSelection((DimSelectionEvent)event); } super.handleLayerEvent(event); @@ -249,34 +241,23 @@ public class ViewportLayer extends TransformLayer { } /** - * Handle {@link ColumnSelectionEvent} + * Handle {@link DimSelectionEvent} * @param selectionEvent */ - private void processColumnSelection(final ColumnSelectionEvent selectionEvent) { - final long explicitePosition= selectionEvent.getColumnPositionToReveal(); + private void processDimSelection(final DimSelectionEvent selectionEvent) { + final long explicitePosition= selectionEvent.getPositionToReveal(); if (explicitePosition >= 0) { - get(HORIZONTAL).movePositionIntoViewport(explicitePosition); + get(selectionEvent.getOrientation()).movePositionIntoViewport(explicitePosition); } } - /** - * Handle {@link RowSelectionEvent} - * @param selectionEvent - */ - private void processRowSelection(final RowSelectionEvent selectionEvent) { - final long explicitePosition= selectionEvent.getRowPositionToReveal(); - if (explicitePosition >= 0) { - get(VERTICAL).movePositionIntoViewport(explicitePosition); - return; - } - } // Accessors /** * @return The scrollable layer underlying the viewport. */ - public ILayer getScrollableLayer() { + public Layer getScrollableLayer() { return this.scrollableLayer; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/IViewportDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayerDim.java index fd296c58..f2011a44 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/IViewportDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayerDim.java @@ -12,16 +12,25 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.TransformLayerDim; /** * Dimension of a viewport layer. */ -public interface IViewportDim extends ILayerDim { +@NonNullByDefault +public abstract class ViewportLayerDim extends TransformLayerDim<ViewportLayer> { + + + public ViewportLayerDim(final ViewportLayer layer, final LayerDim underlyingDim) { + super(layer, underlyingDim); + } /** @@ -29,7 +38,7 @@ public interface IViewportDim extends ILayerDim { * * @return the underlying scrollable layer dimension */ - ILayerDim getScrollable(); + public abstract LayerDim getScrollable(); /** @@ -37,14 +46,14 @@ public interface IViewportDim extends ILayerDim { * * @return the pixel coordinate of the minimum origin in terms of the scrollable layer */ - long getMinimumOriginPixel(); + public abstract long getMinimumOriginPixel(); /** * Returns the minimum origin. * * @return the position of the minimum origin in terms of the scrollable layer */ - long getMinimumOriginPosition(); + public abstract long getMinimumOriginPosition(); /** * Sets the minimum origin. @@ -54,7 +63,7 @@ public interface IViewportDim extends ILayerDim { * * @param scrollablePosition position of the origin in terms of the scrollable layer */ - void setMinimumOriginPosition(long scrollablePosition); + public abstract void setMinimumOriginPosition(long scrollablePosition); /** @@ -62,14 +71,14 @@ public interface IViewportDim extends ILayerDim { * * @return the pixel coordinate of the current origin in terms of the scrollable layer */ - long getOriginPixel(); + public abstract long getOriginPixel(); /** * Returns the current origin. * * @return the position of the current origin in terms of the scrollable layer */ - long getOriginPosition(); + public abstract long getOriginPosition(); /** * Sets the current origin. @@ -78,7 +87,7 @@ public interface IViewportDim extends ILayerDim { * * @param scrollablePixel pixel coordinate of the origin in terms of the scrollable layer */ - void setOriginPixel(long scrollablePixel); + public abstract void setOriginPixel(long scrollablePixel); /** * Sets the current origin. @@ -87,7 +96,7 @@ public interface IViewportDim extends ILayerDim { * * @throws PositionOutOfBoundsException if scrollablePosition is not a valid position */ - void setOriginPosition(long scrollablePosition); + public abstract void setOriginPosition(long scrollablePosition); /** * Resets the viewport dimension. @@ -99,7 +108,7 @@ public interface IViewportDim extends ILayerDim { * * @throws PositionOutOfBoundsException if scrollablePosition is not a valid position */ - void reset(long scrollablePosition); + public abstract void reset(long scrollablePosition); /** @@ -107,50 +116,50 @@ public interface IViewportDim extends ILayerDim { * * @param scrollablePosition position in terms of the scrollable layer */ - void movePositionIntoViewport(long scrollablePosition); + public abstract void movePositionIntoViewport(long scrollablePosition); /** * Scrolls the viewport content backward by one step. */ - void scrollBackwardByStep(); + public abstract void scrollBackwardByStep(); /** * Scrolls the viewport content forward by one step. */ - void scrollForwardByStep(); + public abstract void scrollForwardByStep(); /** * Scrolls the viewport content backward by one position. */ - void scrollBackwardByPosition(); + public abstract void scrollBackwardByPosition(); /** * Scrolls the viewport content forward by one position. */ - void scrollForwardByPosition(); + public abstract void scrollForwardByPosition(); /** * Scrolls the viewport content backward by one viewport page. */ - void scrollBackwardByPage(); + public abstract void scrollBackwardByPage(); /** * Scrolls the viewport content forward by one viewport page. */ - void scrollForwardByPage(); + public abstract void scrollForwardByPage(); /** * Scrolls the viewport content to the first position (minimum origin). */ - void scrollBackwardToBound(); + public abstract void scrollBackwardToBound(); /** * Scrolls the viewport content to the last position. */ - void scrollForwardToBound(); + public abstract void scrollForwardToBound(); } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportLayerDim.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayerDimImpl.java index f6259c12..7ad6bdbe 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportLayerDim.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportLayerDimImpl.java @@ -13,26 +13,26 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and dim-based implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import static org.eclipse.statet.ecommons.waltable.viewport.ViewportLayer.PAGE_INTERSECTION_SIZE; +import static org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayer.PAGE_INTERSECTION_SIZE; import java.util.Collection; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Scrollable; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; -import org.eclipse.statet.ecommons.waltable.coordinate.PositionOutOfBoundsException; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.TransformLayerDim; -import org.eclipse.statet.ecommons.waltable.layer.event.StructuralDiff; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.core.coordinate.PositionOutOfBoundsException; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.core.layer.events.StructuralDiff; +import org.eclipse.statet.ecommons.waltable.viewport.swt.ScrollBarHandler; /** - * Implementation of {@link IViewportDim} for {@link ViewportLayer}. + * Implementation of {@link ViewportLayerDim} for {@link ViewportLayer}. */ -public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implements IViewportDim { +@NonNullByDefault +class ViewportLayerDimImpl extends ViewportLayerDim { private long minimumOriginPosition; @@ -46,10 +46,10 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement private long cachedPositionCount; private long cachedSize; - private ScrollBarHandler scrollBarHandler; + private @Nullable ScrollBarHandler scrollBarAdapter; - public ViewportLayerDim(/*@NonNull*/ final ViewportLayer layer, /*@NonNull*/ final ILayerDim underlyingDim) { + public ViewportLayerDimImpl(final ViewportLayer layer, final LayerDim underlyingDim) { super(layer, underlyingDim); invalidateStructure(); @@ -57,9 +57,9 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement protected void dispose() { - if (this.scrollBarHandler != null) { - this.scrollBarHandler.dispose(); - this.scrollBarHandler= null; + if (this.scrollBarAdapter != null) { + this.scrollBarAdapter.dispose(); + this.scrollBarAdapter= null; } } @@ -68,8 +68,8 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement * information if the size has changed. */ protected long getClientAreaSize() { - final long clientAreaSize= SWTUtil.getRange(this.layer.getClientAreaProvider().getClientArea(), - this.orientation).size(); + final long clientAreaSize= this.layer.getClientAreaProvider().getClientArea() + .getSize(this.orientation); if (clientAreaSize != this.cachedClientAreaSize) { invalidateStructure(); this.cachedClientAreaSize= clientAreaSize; @@ -182,7 +182,7 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement @Override - public final ILayerDim getScrollable() { + public final LayerDim getScrollable() { return this.underlyingDim; } @@ -519,13 +519,9 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement } - protected void checkScrollBar(final Scrollable control) { - if (this.scrollBarHandler != null) { - return; - } - final ScrollBar scrollBar= SWTUtil.getScrollBar(control, this.orientation); - if (scrollBar != null) { - this.scrollBarHandler= new ScrollBarHandler(this, scrollBar); + protected void checkScrollBar(final Object control) { + if (this.scrollBarAdapter == null) { + this.scrollBarAdapter= ScrollBarHandler.create(this, control); } } @@ -533,8 +529,9 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement * Adjusts scrollbar to sync with current state of viewport. */ private void adjustScrollBar() { - if (this.scrollBarHandler != null) { - this.scrollBarHandler.adjustScrollBar(); + final var scrollBarAdapter= this.scrollBarAdapter; + if (scrollBarAdapter != null) { + scrollBarAdapter.adjustScrollBar(); } } @@ -542,10 +539,10 @@ public class ViewportLayerDim extends TransformLayerDim<ViewportLayer> implement * Recalculate scrollbar characteristics; */ private void recalculateScrollBar() { - if (this.scrollBarHandler != null) { - this.scrollBarHandler.recalculateScrollBarSize(); + if (this.scrollBarAdapter != null) { + this.scrollBarAdapter.recalculateScrollBarSize(); - if (!this.scrollBarHandler.getScrollBar().getEnabled()) { + if (!this.scrollBarAdapter.getScrollBar().getEnabled()) { setOriginPosition(getMinimumOriginPosition()); } } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportSelectDimPositionsCommand.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportSelectDimPositionsCommand.java index 9c321648..27c56935 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportSelectDimPositionsCommand.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportSelectDimPositionsCommand.java @@ -11,30 +11,33 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; import java.util.Collection; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.selection.AbstractSelectDimPositionsCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.selection.core.AbstractSelectDimPositionsCommand; /** * Command to select column(s)/row(s) in the viewport. */ +@NonNullByDefault public class ViewportSelectDimPositionsCommand extends AbstractSelectDimPositionsCommand { - public ViewportSelectDimPositionsCommand(final ILayerDim dim, + public ViewportSelectDimPositionsCommand(final LayerDim layerDim, final long position, final int selectionFlags) { - super(dim, position, selectionFlags); + super(layerDim, position, selectionFlags); } - public ViewportSelectDimPositionsCommand(final ILayerDim dim, + public ViewportSelectDimPositionsCommand(final LayerDim layerDim, final long refPosition, final Collection<LRange> positions, final long positionToReveal, final int selectionFlags) { - super(dim, refPosition, positions, positionToReveal, selectionFlags); + super(layerDim, refPosition, positions, positionToReveal, selectionFlags); } protected ViewportSelectDimPositionsCommand(final ViewportSelectDimPositionsCommand command) { diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportSelectDimPositionsCommandHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportSelectDimPositionsCommandHandler.java index fe32836d..910da01c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ViewportSelectDimPositionsCommandHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/core/ViewportSelectDimPositionsCommandHandler.java @@ -11,20 +11,24 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.core; -import org.eclipse.statet.ecommons.waltable.command.AbstractLayerCommandHandler; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.AbstractLayer; -import org.eclipse.statet.ecommons.waltable.selection.SelectDimPositionsCommand; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; +import org.eclipse.statet.ecommons.waltable.core.command.AbstractLayerCommandHandler; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.AbstractLayer; +import org.eclipse.statet.ecommons.waltable.selection.core.SelectDimPositionsCommand; + +@NonNullByDefault public class ViewportSelectDimPositionsCommandHandler extends AbstractLayerCommandHandler<ViewportSelectDimPositionsCommand> { private final AbstractLayer viewportLayer; - private final Orientation orientation; + private final @Nullable Orientation orientation; public ViewportSelectDimPositionsCommandHandler(final AbstractLayer viewportLayer) { @@ -32,7 +36,7 @@ public class ViewportSelectDimPositionsCommandHandler extends AbstractLayerComma } public ViewportSelectDimPositionsCommandHandler(final AbstractLayer viewportLayer, - final Orientation orientation) { + final @Nullable Orientation orientation) { this.viewportLayer= viewportLayer; this.orientation= orientation; } diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollBarHandler.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/swt/ScrollBarHandler.java index 0ab0111e..e3571951 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/ScrollBarHandler.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/swt/ScrollBarHandler.java @@ -12,21 +12,38 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - dim-based implementation prepared for long datasets #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport; +package org.eclipse.statet.ecommons.waltable.viewport.swt; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.swt.widgets.Scrollable; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; +import org.eclipse.statet.jcommons.lang.Nullable; + +import org.eclipse.statet.ecommons.waltable.core.swt.SwtUtils; import org.eclipse.statet.ecommons.waltable.edit.EditUtils; -import org.eclipse.statet.ecommons.waltable.swt.SWTUtil; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportLayerDim; +@NonNullByDefault public class ScrollBarHandler implements Listener { - private final IViewportDim dim; + public static @Nullable ScrollBarHandler create(final ViewportLayerDim layerDim, final Object control) { + if (control instanceof Scrollable) { + final ScrollBar scrollBar= SwtUtils.getScrollBar((Scrollable)control, layerDim.getOrientation()); + if (scrollBar != null) { + return new ScrollBarHandler(layerDim, scrollBar); + } + } + return null; + } + + + private final ViewportLayerDim dim; private final ScrollBar scrollBar; @@ -43,19 +60,19 @@ public class ScrollBarHandler implements Listener { private boolean dragging= false; - public ScrollBarHandler(final IViewportDim dim, final ScrollBar scrollBar) { + public ScrollBarHandler(final ViewportLayerDim dim, final ScrollBar scrollBar) { this.dim= dim; this.scrollBar= scrollBar; this.scrollBar.addListener(SWT.Selection, this); - scrollBar.getParent().addListener(SWTUtil.getMouseWheelEventType(this.dim.getOrientation()), this); + scrollBar.getParent().addListener(SwtUtils.getMouseWheelEventType(this.dim.getOrientation()), this); } public void dispose() { if (this.scrollBar != null && !this.scrollBar.isDisposed()) { this.scrollBar.removeListener(SWT.Selection, this); - this.scrollBar.removeListener(SWTUtil.getMouseWheelEventType(this.dim.getOrientation()), this); + this.scrollBar.removeListener(SwtUtils.getMouseWheelEventType(this.dim.getOrientation()), this); } } @@ -121,11 +138,11 @@ public class ScrollBarHandler implements Listener { } } - ScrollBar getScrollBar() { + public ScrollBar getScrollBar() { return this.scrollBar; } - void adjustScrollBar() { + public void adjustScrollBar() { if (this.scrollBar.isDisposed()) { return; } @@ -134,7 +151,7 @@ public class ScrollBarHandler implements Listener { this.scrollBar.setSelection((int) (this.factor * startPixel)); } - void recalculateScrollBarSize() { + public void recalculateScrollBarSize() { if (this.scrollBar.isDisposed()) { return; } @@ -171,7 +188,8 @@ public class ScrollBarHandler implements Listener { this.scrollBar.setThumb(viewportWindowSpan); this.scrollBar.setEnabled(true); this.scrollBar.setVisible(true); - } else { + } + else { this.scrollBar.setThumb(max); this.scrollBar.setEnabled(false); this.scrollBar.setVisible(false); diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/action/ViewportSelectDimPositionsAction.java b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/ui/action/ViewportSelectDimPositionsAction.java index 1ab48da5..93268a5c 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/viewport/action/ViewportSelectDimPositionsAction.java +++ b/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/srcBase/org/eclipse/statet/ecommons/waltable/viewport/ui/action/ViewportSelectDimPositionsAction.java @@ -11,27 +11,28 @@ # Original NatTable authors and others - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.viewport.action; - -import java.util.Collections; -import java.util.List; +package org.eclipse.statet.ecommons.waltable.viewport.ui.action; import org.eclipse.swt.events.MouseEvent; +import org.eclipse.statet.jcommons.collections.ImCollections; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + import org.eclipse.statet.ecommons.waltable.NatTable; -import org.eclipse.statet.ecommons.waltable.coordinate.LRange; -import org.eclipse.statet.ecommons.waltable.coordinate.Orientation; -import org.eclipse.statet.ecommons.waltable.layer.ILayerDim; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCell; -import org.eclipse.statet.ecommons.waltable.layer.cell.ILayerCellDim; -import org.eclipse.statet.ecommons.waltable.selection.SelectionFlags; +import org.eclipse.statet.ecommons.waltable.core.coordinate.LRange; +import org.eclipse.statet.ecommons.waltable.core.coordinate.Orientation; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCell; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerCellDim; +import org.eclipse.statet.ecommons.waltable.core.layer.LayerDim; +import org.eclipse.statet.ecommons.waltable.selection.ui.action.SelectCellAction; import org.eclipse.statet.ecommons.waltable.ui.action.IMouseAction; -import org.eclipse.statet.ecommons.waltable.viewport.ViewportSelectDimPositionsCommand; +import org.eclipse.statet.ecommons.waltable.viewport.core.ViewportSelectDimPositionsCommand; /** * Action to select the column/row at the mouse position. */ +@NonNullByDefault public class ViewportSelectDimPositionsAction implements IMouseAction { @@ -45,25 +46,25 @@ public class ViewportSelectDimPositionsAction implements IMouseAction { @Override public void run(final NatTable natTable, final MouseEvent event) { - final ILayerCell cell= natTable.getCellByPosition( + final LayerCell cell= natTable.getCellByPosition( natTable.getColumnPositionByX(event.x), natTable.getRowPositionByY(event.y) ); if (cell == null) { return; } - final ILayerDim layerDim= natTable.getDim(this.orientation); - final ILayerCellDim cellDim= cell.getDim(this.orientation); + final LayerDim layerDim= natTable.getDim(this.orientation); + final LayerCellDim cellDim= cell.getDim(this.orientation); if (cellDim.getPositionSpan() > 1) { - final List<LRange> positions= Collections.singletonList( + final var positions= ImCollections.newList( new LRange(cellDim.getOriginPosition(), cellDim.getOriginPosition() + cellDim.getPositionSpan()) ); natTable.doCommand(new ViewportSelectDimPositionsCommand(layerDim, cellDim.getPosition(), positions, cellDim.getPosition(), - SelectionFlags.swt2Flags(event.stateMask) )); + SelectCellAction.swt2Flags(event.stateMask) )); } else { natTable.doCommand(new ViewportSelectDimPositionsCommand(layerDim, cellDim.getPosition(), - SelectionFlags.swt2Flags(event.stateMask) )); + SelectCellAction.swt2Flags(event.stateMask) )); } } diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/collections/IntIterator.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/collections/IntIterator.java new file mode 100644 index 00000000..3c10bdb0 --- /dev/null +++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/collections/IntIterator.java @@ -0,0 +1,37 @@ +/*=============================================================================# + # Copyright (c) 2021 Stephan Wahlbrink and others. + # + # This program and the accompanying materials are made available under the + # terms of the Eclipse Public License 2.0 which is available at + # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + # which is available at https://www.apache.org/licenses/LICENSE-2.0. + # + # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + # + # Contributors: + # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation + #=============================================================================*/ + +package org.eclipse.statet.jcommons.collections; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.eclipse.statet.jcommons.lang.NonNullByDefault; + + +@NonNullByDefault +public interface IntIterator extends Iterator<Integer> { + + + /** + * Returns the next value in the iteration. + * <p> + * Like {@link #next()}, but returns directly the primitiv value. + * + * @return the next value in the iteration + * @throws NoSuchElementException if the iteration has no more elements + */ + int nextValue(); + +} diff --git a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ILValueIterator.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/collections/LongIterator.java index 586d43c0..dda4e0d9 100644 --- a/ecommons.waltable/org.eclipse.statet.ecommons.waltable.core/src/org/eclipse/statet/ecommons/waltable/coordinate/ILValueIterator.java +++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/collections/LongIterator.java @@ -1,5 +1,5 @@ /*=============================================================================# - # Copyright (c) 2013, 2021 Stephan Wahlbrink and others. + # Copyright (c) 2021 Stephan Wahlbrink and others. # # This program and the accompanying materials are made available under the # terms of the Eclipse Public License 2.0 which is available at @@ -12,13 +12,16 @@ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation #=============================================================================*/ -package org.eclipse.statet.ecommons.waltable.coordinate; +package org.eclipse.statet.jcommons.collections; import java.util.Iterator; import java.util.NoSuchElementException; +import org.eclipse.statet.jcommons.lang.NonNullByDefault; -public interface ILValueIterator extends Iterator<Long> { + +@NonNullByDefault +public interface LongIterator extends Iterator<Long> { /** |
