introduction to presentation model
diff --git a/org.eclipse.nebula.widgets.nattable.app/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.app/META-INF/MANIFEST.MF
index c1b280b..44c75e0 100644
--- a/org.eclipse.nebula.widgets.nattable.app/META-INF/MANIFEST.MF
+++ b/org.eclipse.nebula.widgets.nattable.app/META-INF/MANIFEST.MF
@@ -22,5 +22,7 @@
org.w3c.css.sac;bundle-version="1.3.1",
org.eclipse.e4.core.commands;bundle-version="0.10.1",
org.eclipse.e4.ui.bindings;bundle-version="0.10.1",
- org.eclipse.nebula.widgets.nattable.core;bundle-version="1.0.0"
+ org.eclipse.nebula.widgets.nattable.core;bundle-version="1.0.0",
+ org.eclipse.nebula.widgets.nattable.extension.e4;bundle-version="1.0.0",
+ org.eclipse.nebula.widgets.nattable.renderer.swt;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
diff --git a/org.eclipse.nebula.widgets.nattable.app/src/org/eclipse/nebula/widgets/nattable/app/parts/SamplePart.java b/org.eclipse.nebula.widgets.nattable.app/src/org/eclipse/nebula/widgets/nattable/app/parts/SamplePart.java
index a24db27..3241019 100644
--- a/org.eclipse.nebula.widgets.nattable.app/src/org/eclipse/nebula/widgets/nattable/app/parts/SamplePart.java
+++ b/org.eclipse.nebula.widgets.nattable.app/src/org/eclipse/nebula/widgets/nattable/app/parts/SamplePart.java
@@ -11,9 +11,12 @@
package org.eclipse.nebula.widgets.nattable.app.parts;
import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.di.Focus;
-import org.eclipse.nebula.widgets.nattable.core.NatTable;
+import org.eclipse.nebula.widgets.nattable.extension.e4.E4NatTableConfiguration;
+import org.eclipse.nebula.widgets.nattable.renderer.swt.NatTable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -24,6 +27,9 @@
private Label label;
private NatTable natTable;
+
+ @Inject
+ private IEclipseContext context;
@PostConstruct
public void createComposite(Composite parent) {
@@ -32,7 +38,7 @@
label = new Label(parent, SWT.NONE);
label.setText("Sample table");
- natTable = new NatTable(parent);
+ natTable = new NatTable(parent, new E4NatTableConfiguration(context));
natTable.setLayoutData(new GridData(GridData.FILL_BOTH));
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.core/META-INF/MANIFEST.MF
index cdaf85a..08c8611 100644
--- a/org.eclipse.nebula.widgets.nattable.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.nebula.widgets.nattable.core/META-INF/MANIFEST.MF
@@ -8,4 +8,6 @@
org.eclipse.swt.events,
org.eclipse.swt.graphics,
org.eclipse.swt.widgets
-Export-Package: org.eclipse.nebula.widgets.nattable.core
+Export-Package: org.eclipse.nebula.widgets.nattable.core,
+ org.eclipse.nebula.widgets.nattable.core.layer,
+ org.eclipse.nebula.widgets.nattable.core.layer.event
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/NatTable.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/MNatTable.java
similarity index 84%
rename from org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/NatTable.java
rename to org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/MNatTable.java
index a63c108..799bb4e 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/NatTable.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/MNatTable.java
@@ -10,19 +10,25 @@
******************************************************************************/
package org.eclipse.nebula.widgets.nattable.core;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.ScrollBar;
+import java.util.ArrayList;
+import java.util.List;
-public class NatTable extends Canvas implements PaintListener
-// , ILayer, IClientAreaProvider, ILayerListener, IPersistable
+import org.eclipse.nebula.widgets.nattable.core.layer.ILayer;
+import org.eclipse.nebula.widgets.nattable.core.layer.ILayerListener;
+import org.eclipse.nebula.widgets.nattable.core.layer.event.ILayerEvent;
+import org.eclipse.swt.events.PaintEvent;
+
+/**
+ * Presentation model of the NatTable.
+ *
+ * @author Dirk Fauth
+ *
+ */
+public class MNatTable implements ILayer
+// , IClientAreaProvider, ILayerListener, IPersistable
{
- public static final int DEFAULT_STYLE_OPTIONS = SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL;
-
+
// private UiBindingRegistry uiBindingRegistry;
//
// private ModeSupport modeSupport;
@@ -45,51 +51,9 @@
//
// private final boolean autoconfigure;
- public NatTable(Composite parent) {
- this(parent, DEFAULT_STYLE_OPTIONS);
- }
-// /**
-// * @param parent widget for the table.
-// * @param autoconfigure if set to False
-// * - No auto configuration is done
-// * - Default settings are <i>not</i> loaded. Configuration(s) have to be manually
-// * added by invoking addConfiguration(). At the minimum the {@link DefaultNatTableStyleConfiguration}
-// * must be added for the table to render.
-// */
-// public NatTable(Composite parent, boolean autoconfigure) {
-// this(parent, DEFAULT_STYLE_OPTIONS, autoconfigure);
-// }
-//
-// public NatTable(Composite parent, ILayer layer) {
-// this(parent, DEFAULT_STYLE_OPTIONS, layer);
-// }
-//
-// public NatTable(Composite parent, ILayer layer, boolean autoconfigure) {
-// this(parent, DEFAULT_STYLE_OPTIONS, layer, autoconfigure);
-// }
- public NatTable(Composite parent, final int style) {
- this(parent, style, null);
- }
-
- public NatTable(Composite parent, final int style, NatTableConfiguration natConfig) {
-
-// this(parent, style, new DummyGridLayerStack());
-// }
-//
-// public NatTable(Composite parent, final int style, boolean autoconfigure) {
-// this(parent, style, new DummyGridLayerStack(), autoconfigure);
-// }
-//
-// public NatTable(final Composite parent, final int style, ILayer layer) {
-// this(parent, style, layer, true);
-// }
-//
-// public NatTable(final Composite parent, final int style, final ILayer layer, boolean autoconfigure) {
- super(parent, style);
-
-
+ public MNatTable(NatTableConfiguration natConfig) {
if (natConfig != null) {
//if a NatTableConfiguration is given, start configuring it by this
//e.g. if using the E4 extension, the layers and other configurations will
@@ -97,10 +61,6 @@
natConfig.startConstruction();
}
- // Disable scroll bars by default; if a Viewport is available, it will enable the scroll bars
- disableScrollBar(getHorizontalBar());
- disableScrollBar(getVerticalBar());
-
// initInternalListener();
//
// internalSetLayer(layer);
@@ -132,12 +92,6 @@
// return new VisualChangeEventConflater(this);
// }
- private void disableScrollBar(ScrollBar scrollBar) {
- scrollBar.setMinimum(0);
- scrollBar.setMaximum(1);
- scrollBar.setThumb(1);
- scrollBar.setEnabled(false);
- }
// public ILayer getLayer() {
// return underlyingLayer;
@@ -237,10 +191,6 @@
// return id;
// }
- @Override
- protected void checkSubclass() {
- }
-
// protected void initInternalListener() {
// modeSupport = new ModeSupport(this);
// modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(modeSupport, this));
@@ -267,11 +217,6 @@
// });
// }
- @Override
- public boolean forceFocus() {
- return super.forceFocus();
- }
-
// Painting ///////////////////////////////////////////////////////////////
// public List<IOverlayPainter> getOverlayPainters() {
@@ -330,26 +275,6 @@
// redraw(0, yOffset, getWidth(), getRowHeightByPosition(rowPosition), true);
// }
- public void updateResize() {
- updateResize(true);
- }
-
- /**
- * Update the table screen by re-calculating everything again. It should not
- * be called too frequently.
- *
- * @param redraw
- * true to redraw the table
- */
- private void updateResize(final boolean redraw) {
- if (isDisposed()) {
- return;
- }
-// doCommand(new RecalculateScrollBarsCommand());
- if (redraw) {
- redraw();
- }
- }
// /**
// * Refreshes the entire NatTable as every layer will be refreshed.
@@ -387,13 +312,33 @@
// doCommand(new InitializeGridCommand(this));
// }
//
-// // Events /////////////////////////////////////////////////////////////////
-//
-// public void handleLayerEvent(ILayerEvent event) {
-// for (ILayerListener layerListener : listeners) {
-// layerListener.handleLayerEvent(event);
-// }
-//
+ // Events /////////////////////////////////////////////////////////////////
+
+ private final List<ILayerListener> listeners = new ArrayList<ILayerListener>();
+
+ public void fireLayerEvent(ILayerEvent event) {
+ for (ILayerListener layerListener : listeners) {
+ layerListener.handleLayerEvent(event);
+ }
+ //TODO the following line was inserted before, can this be correct?
+ //IMHO this is wrong because events are defined to be fired upwards, while
+ //this line will fire the event downwards again
+// underlyingLayer.fireLayerEvent(event);
+ }
+
+ public void addLayerListener(ILayerListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeLayerListener(ILayerListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void handleLayerEvent(ILayerEvent event) {
+ for (ILayerListener layerListener : listeners) {
+ layerListener.handleLayerEvent(event);
+ }
+
// if (event instanceof IVisualChangeEvent) {
// conflaterChain.addEvent(event);
// }
@@ -407,7 +352,13 @@
// re.printStackTrace();
// }
// }
-// }
+ }
+
+ @Override
+ public void dispose() {
+ //TODO tell the presentation to dispose
+ }
+
//
//
// // ILayer /////////////////////////////////////////////////////////////////
@@ -449,21 +400,6 @@
// return underlyingLayer.doCommand(command);
// }
//
-// // Events
-//
-// private final List<ILayerListener> listeners = new ArrayList<ILayerListener>();
-//
-// public void fireLayerEvent(ILayerEvent event) {
-// underlyingLayer.fireLayerEvent(event);
-// }
-//
-// public void addLayerListener(ILayerListener listener) {
-// listeners.add(listener);
-// }
-//
-// public void removeLayerListener(ILayerListener listener) {
-// listeners.remove(listener);
-// }
//
// // Columns
//
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayer.java
new file mode 100644
index 0000000..b6edce8
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayer.java
@@ -0,0 +1,311 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.core.layer;
+
+
+/**
+ * <p>
+ * A Layer is a rectangular region of grid cells. A layer has methods to access its columns, rows, width and height. A
+ * layer can be stacked on top of another layer in order to expose a transformed view of its underlying layer's grid
+ * cell structure.
+ * </p>
+ * <p>
+ * Columns and rows in a layer are referenced either by <b>position</b> or <b>index</b>. The position of a column/row in
+ * a layer corresponds to the physical location of the column/row in the layer. The index of a column/row in a layer
+ * corresponds to the location of the column/row in the lowest level layer in the layer stack. These concepts are
+ * illustrated by the following example:
+ * </p>
+ * <pre>
+ * Hide Layer C
+ * 0 1 2 3 4 <- column positions
+ * 1 0 3 4 5 <- column indexes
+ *
+ * Reorder Layer B
+ * 0 1 2 3 4 5 <- column positions
+ * 2 1 0 3 4 5 <- column indexes
+ *
+ * Data Layer A
+ * 0 1 2 3 4 5 <- column positions
+ * 0 1 2 3 4 5 <- column indexes
+ * </pre>
+ * <p>
+ * In the above example, Hide Layer C is stacked on top of Reorder Layer B, which is in turn stacked on top of Data
+ * Layer A. The positions in Data Layer A are the same as its indexes, because it is the lowest level layer in the
+ * stack. Reorder Layer B reorders column 0 of its underlying layer (Data Layer A) after column 2 of its underlying
+ * layer. Hide Layer C hides the first column of its underlying layer (Reorder Layer B).
+ * </p>
+ * <p>
+ * Layers can also be laterally composed into larger layers. For instance, the standard grid layer is composed of a
+ * body layer, column header layer, row header layer, and corner layer:
+ * </p>
+ * <table border=1>
+ * <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*/ {
+
+ // Dispose
+
+ public void dispose();
+
+ // Persistence
+
+// /**
+// * Persistables registered with a layer will have a chance to write their data out to the
+// * {@link Properties} instance when the layer is persisted.
+// */
+// public void registerPersistable(IPersistable persistable);
+//
+// public void unregisterPersistable(IPersistable persistable);
+//
+// // Configuration
+//
+// /**
+// * Every layer gets this call back, starting at the top of the stack. This is triggered
+// * by the {@link NatTable#configure()} method. This is an opportunity to add
+// * any key/mouse bindings and other general configuration.
+// *
+// * @param configRegistry instance owned by {@link NatTable}
+// * @param uiBindingRegistry instance owned by {@link NatTable}
+// */
+// public void configure(ConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry);
+//
+// // Region
+//
+// /**
+// * Layer can apply its own labels to any cell it wishes.
+// */
+// public LabelStack getRegionLabelsByXY(int x, int y);
+//
+// // Commands
+//
+// /**
+// * Opportunity to respond to a command as it flows down the stack. If the layer
+// * 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)}
+// *
+// * @return true if the command has been handled, false otherwise
+// */
+// public boolean doCommand(ILayerCommand command);
+//
+// // Events
+//
+// /**
+// * Events can be fired to notify other components of the grid.<br/>
+// * Events travel <i>up</i> the layer stack and may cause a repaint.
+// *
+// * Example: When the contents of the grid change {@link IVisualChangeEvent} can be
+// * fired to notify other layers to refresh their caches etc.
+// */
+// public void fireLayerEvent(ILayerEvent event);
+//
+// public void addLayerListener(ILayerListener listener);
+//
+// public void removeLayerListener(ILayerListener listener);
+//
+// public ILayerPainter getLayerPainter();
+//
+// // Client area
+//
+// public IClientAreaProvider getClientAreaProvider();
+//
+// public void setClientAreaProvider(IClientAreaProvider clientAreaProvider);
+//
+// // Horizontal features
+//
+// // Columns
+//
+// /**
+// * Returns the number of columns in this coordinate model.
+// */
+// public int getColumnCount();
+//
+// public int getPreferredColumnCount();
+//
+// /**
+// * Gets the underlying non-transformed column index for the given column position.
+// * @param columnPosition a column position relative to this coordinate model
+// * @return an underlying non-transformed column index, or -1 if the given column position does not exist within this
+// * coordinate system
+// */
+// public int getColumnIndexByPosition(int columnPosition);
+//
+// /**
+// * Convert a column position to the coordinates of the underlying layer.
+// * This is possible since each layer is aware of its underlying layer.
+// * @param localColumnPosition column position in local (the layer's own) coordinates
+// */
+// public int localToUnderlyingColumnPosition(int localColumnPosition);
+//
+// public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition);
+//
+// public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges);
+//
+// // Width
+//
+// /**
+// * Returns the total width in pixels of this layer.
+// *
+// * @return the width of this layer
+// */
+// public int getWidth();
+//
+// public int getPreferredWidth();
+//
+// /**
+// * Returns the width in pixels of the given column.
+// *
+// * The width of invisible and non-existing columns is 0.
+// *
+// * @param columnPosition the column position in this layer
+// *
+// * @return the width of the column
+// */
+// public int getColumnWidthByPosition(int columnPosition);
+//
+// // Column resize
+//
+// public boolean isColumnPositionResizable(int columnPosition);
+//
+// // X
+//
+// /**
+// * Returns the column position that contains the given x coordinate.
+// * @param x a horizontal pixel location relative to the pixel boundary of this layer
+// * @return a column position relative to the associated coordinate system, or -1 if there is no column that contains x
+// */
+// public int getColumnPositionByX(int x);
+//
+// /**
+// * Returns the x offset in pixels of the given column.
+// *
+// * @param rowPosition the column position in this layer
+// *
+// * @return the x offset of the column, or -1
+// */
+// public int getStartXOfColumnPosition(int columnPosition);
+//
+// // Underlying
+//
+// public Collection<ILayer> getUnderlyingLayersByColumnPosition(int columnPosition);
+//
+// // Vertical features
+//
+// // Rows
+//
+// /**
+// * Returns the number of rows in this coordinate model.
+// */
+// public int getRowCount();
+//
+// public int getPreferredRowCount();
+//
+// /**
+// * Gets the underlying non-transformed row index for the given row position.
+// * @param rowPosition a row position relative to this coordinate model
+// * @return an underlying non-transformed row index, or -1 if the given row position does not exist within this
+// * coordinate system
+// */
+// public int getRowIndexByPosition(int rowPosition);
+//
+// public int localToUnderlyingRowPosition(int localRowPosition);
+//
+// public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition);
+//
+// public Collection<Range> underlyingToLocalRowPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingRowPositionRanges);
+//
+// // Height
+//
+// /**
+// * Returns the total height in pixels of this layer.
+// *
+// * @return the height of this layer
+// */
+// public int getHeight();
+//
+// public int getPreferredHeight();
+//
+// /**
+// * Returns the height in pixels of the given row.
+// *
+// * The height of invisible and non-existing rows is 0.
+// *
+// * @param rowPosition the row position in this layer
+// *
+// * @return the height of the row
+// */
+// public int getRowHeightByPosition(int rowPosition);
+//
+// // Row resize
+//
+// public boolean isRowPositionResizable(int rowPosition);
+//
+// // Y
+//
+// /**
+// * Returns the row position that contains the given y coordinate.
+// * @param y a vertical pixel location relative to the pixel boundary of this layer
+// * @return a row position relative to the associated coordinate system, or -1 if there is no row that contains y
+// */
+// public int getRowPositionByY(int y);
+//
+// /**
+// * Returns the y offset in pixels of the given row.
+// *
+// * @param rowPosition the row position in this layer
+// *
+// * @return the y offset of the row, or -1
+// */
+// public int getStartYOfRowPosition(int rowPosition);
+//
+// // Underlying
+//
+// public Collection<ILayer> getUnderlyingLayersByRowPosition(int rowPosition);
+//
+// // Cell features
+//
+// public ILayerCell getCellByPosition(int columnPosition, int rowPosition);
+//
+// /**
+// * Calculates the bounds in pixel for the given cell position.
+// *
+// * @param columnPosition the column position of the cell
+// * @param rowPosition the row position of the cell
+// *
+// * @return the bounds, or <code>null</code> if there are no valid bounds
+// */
+// public Rectangle getBoundsByPosition(int columnPosition, int rowPosition);
+//
+// /**
+// * @return {@link DisplayMode} for the cell at the given position.<br/>
+// * The {@link DisplayMode} affects the settings out of the {@link ConfigRegistry}.
+// * Display mode is <i>NORMAL</i> by default.<br/>
+// *
+// * <b>Example:</b> {@link SelectionLayer} overrides this to return the <i>SELECT</i>
+// * label for cells which are selected.
+// */
+// public String getDisplayModeByPosition(int columnPosition, int rowPosition);
+//
+// public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition);
+//
+// public Object getDataValueByPosition(int columnPosition, int rowPosition);
+//
+// public ILayer getUnderlyingLayerByPosition(int columnPosition, int rowPosition);
+//
+// public ICellPainter getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry);
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayerListener.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayerListener.java
new file mode 100644
index 0000000..800486b
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/ILayerListener.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.core.layer;
+
+import org.eclipse.nebula.widgets.nattable.core.layer.event.ILayerEvent;
+
+/**
+ * Object interested in receiving events related to a {@link ILayer}.
+ */
+public interface ILayerListener {
+
+ /**
+ * Handle an event notification from an {@link ILayer}
+ */
+ void handleLayerEvent(ILayerEvent event);
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEvent.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEvent.java
new file mode 100644
index 0000000..3381104
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEvent.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.core.layer.event;
+
+import org.eclipse.nebula.widgets.nattable.core.layer.ILayer;
+
+
+/**
+ * Event fired by {@link ILayerCommandHandler} implementations (usually to signal the handling of a {@link ILayerCommand}).<br/>
+ * Every layer in the grid is given a chance to respond to an event via {@link ILayer#handleLayerEvent(ILayerEvent)},
+ * as {@link ILayerEvent}s are fired the layer stack upwards without consuming the event.
+ *
+ * @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 <code>true</code> if successfully converted, <code>false</code> otherwise
+ */
+ boolean convertToLocal(ILayer localLayer);
+
+ /**
+ * @return A cloned copy of the event. This cloned copy is provided to each listener.
+ */
+ ILayerEvent cloneEvent();
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEventHandler.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEventHandler.java
new file mode 100644
index 0000000..042cd1a
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/event/ILayerEventHandler.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Original authors and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Original authors and others - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.widgets.nattable.core.layer.event;
+
+/**
+ * Event handler for {@link ILayerEvent}s.
+ *
+ * @param <T> The type of the {@link ILayerEvent} objects this handler can handle.
+ */
+public interface ILayerEventHandler <T extends ILayerEvent> {
+
+ /**
+ * Handles the specified {@link ILayerEvent}.
+ * @param event The event to handle.
+ */
+ public void handleLayerEvent(T event);
+
+ /**
+ * @return The type of the {@link ILayerEvent} objects this handler can handle.
+ */
+ public Class<T> getLayerEventClass();
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.extension.e4/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.extension.e4/META-INF/MANIFEST.MF
index 901ce68..a5c7fd6 100644
--- a/org.eclipse.nebula.widgets.nattable.extension.e4/META-INF/MANIFEST.MF
+++ b/org.eclipse.nebula.widgets.nattable.extension.e4/META-INF/MANIFEST.MF
@@ -7,3 +7,4 @@
Require-Bundle: org.eclipse.e4.core.contexts;bundle-version="1.1.0",
org.eclipse.e4.core.di;bundle-version="1.1.0",
org.eclipse.nebula.widgets.nattable.core;bundle-version="1.0.0"
+Export-Package: org.eclipse.nebula.widgets.nattable.extension.e4
diff --git a/org.eclipse.nebula.widgets.nattable.extension.e4/src/org/eclipse/nebula/widgets/nattable/extension/e4/E4NatTableConfiguration.java b/org.eclipse.nebula.widgets.nattable.extension.e4/src/org/eclipse/nebula/widgets/nattable/extension/e4/E4NatTableConfiguration.java
index c305d1b..fe9c5a3 100644
--- a/org.eclipse.nebula.widgets.nattable.extension.e4/src/org/eclipse/nebula/widgets/nattable/extension/e4/E4NatTableConfiguration.java
+++ b/org.eclipse.nebula.widgets.nattable.extension.e4/src/org/eclipse/nebula/widgets/nattable/extension/e4/E4NatTableConfiguration.java
@@ -59,9 +59,11 @@
@Override
public <T> T create(Class<T> clazz) {
- //Let the ContextInjectionFactory create the instance and put it
- //into the local context. The classes need to be annotated with
- //@Creatable to make this work
- return ContextInjectionFactory.make(clazz, this.localContext);
+ //Let the ContextInjectionFactory create the instance
+ T instance = ContextInjectionFactory.make(clazz, this.localContext);
+ //as make ContextInjectionFactory.make() doesn't put the created instance
+ //into the context itself, we need to do this ourself
+ this.localContext.set(clazz, instance);
+ return instance;
}
}
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.renderer.swt/META-INF/MANIFEST.MF
index acb1036..8b076f1 100644
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt/META-INF/MANIFEST.MF
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt/META-INF/MANIFEST.MF
@@ -8,3 +8,5 @@
org.eclipse.swt.events,
org.eclipse.swt.graphics,
org.eclipse.swt.widgets
+Require-Bundle: org.eclipse.nebula.widgets.nattable.core;bundle-version="1.0.0";visibility:=reexport
+Export-Package: org.eclipse.nebula.widgets.nattable.renderer.swt
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/NatTable.java b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/NatTable.java
new file mode 100644
index 0000000..2f5a97f
--- /dev/null
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/NatTable.java
@@ -0,0 +1,167 @@
+package org.eclipse.nebula.widgets.nattable.renderer.swt;
+
+import org.eclipse.nebula.widgets.nattable.core.MNatTable;
+import org.eclipse.nebula.widgets.nattable.core.NatTableConfiguration;
+import org.eclipse.nebula.widgets.nattable.core.layer.ILayerListener;
+import org.eclipse.nebula.widgets.nattable.core.layer.event.ILayerEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.ScrollBar;
+
+/**
+ * The SWT rendering implementation of the NatTable. Basically a {@link Canvas} on which
+ * the table will be painted.
+ *
+ * TODO some more documentation
+ *
+ * @author Dirk Fauth
+ *
+ */
+public class NatTable extends Canvas implements PaintListener, ILayerListener {
+
+ /**
+ * The presentation model that contains the logic.
+ */
+ private MNatTable model;
+
+ /**
+ * The default style options for rendering the SWT NatTable composite.
+ * @see SWT#NO_BACKGROUND
+ * @see SWT#NO_REDRAW_RESIZE
+ * @see SWT#DOUBLE_BUFFERED
+ * @see SWT#V_SCROLL
+ * @see SWT#H_SCROLL
+ */
+ public static final int DEFAULT_STYLE_OPTIONS = SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL;
+
+ /**
+ * Creates a new NatTable presentation instance for SWT rendering, using the specified configuration and
+ * the defined default style options.
+ * @param parent A composite control which will be the parent of the new instance (cannot be null).
+ * @param configuration The configuration that will be used to build up the new NatTable instance.
+ */
+ public NatTable(Composite parent, NatTableConfiguration configuration) {
+ this(parent, configuration, DEFAULT_STYLE_OPTIONS);
+ }
+
+ /**
+ * Creates a new NatTable presentation instance for SWT rendering for the specified NatTable model,
+ * using the defined default style options.
+ * @param parent A composite control which will be the parent of the new instance (cannot be null).
+ * @param mNatTable The NatTable model instance to build this presentation for.
+ */
+ public NatTable(Composite parent, MNatTable mNatTable) {
+ this(parent, mNatTable, DEFAULT_STYLE_OPTIONS);
+ }
+
+ /**
+ * Creates a new NatTable presentation instance for SWT rendering, using the specified configuration
+ * and style options.
+ * @param parent A composite control which will be the parent of the new instance (cannot be null).
+ * @param configuration The configuration that will be used to build up the NatTable instance.
+ * @param style The style of control to construct.
+ */
+ public NatTable(Composite parent, NatTableConfiguration configuration, int style) {
+ this(parent, new MNatTable(configuration), style);
+ }
+
+ /**
+ * Creates a new NatTable presentation instance for SWT rendering for the specified NatTable model and
+ * style options.
+ * @param parent A composite control which will be the parent of the new instance (cannot be null).
+ * @param mNatTable The NatTable model instance to build this presentation for.
+ * @param style The style of control to construct.
+ */
+ public NatTable(Composite parent, MNatTable mNatTable, int style) {
+ super(parent, style);
+
+ //create a new model based on the given configuration
+ setModel(mNatTable);
+
+ // Disable scroll bars by default; if a Viewport is available, it will enable the scroll bars
+ disableScrollBar(getHorizontalBar());
+ disableScrollBar(getVerticalBar());
+
+ }
+
+ /**
+ * Sets the {@link MNatTable} presentation model instance to this SWT NatTable renderer.
+ * This way it is possible to change the presentation model at runtime by keeping the
+ * renderer within the UI.
+ * @param model The presentation model to set.
+ */
+ public void setModel(MNatTable model) {
+ if (this.model != null) {
+ //if there is already a model set and we are setting an new model
+ //we have to remove ourself as a listener
+ this.model.removeLayerListener(this);
+ }
+ this.model = model;
+ //register myself as listener
+ this.model.addLayerListener(this);
+ }
+
+ @Override
+ public void handleLayerEvent(ILayerEvent event) {
+ // TODO Auto-generated method stub
+// if (event instanceof IVisualChangeEvent) {
+// conflaterChain.addEvent(event);
+// }
+//
+// if (event instanceof CellSelectionEvent) {
+// Event e = new Event();
+// e.widget = this;
+// try {
+// notifyListeners(SWT.Selection, e);
+// } catch (RuntimeException re) {
+// re.printStackTrace();
+// }
+// }
+ }
+
+ @Override
+ public void paintControl(final PaintEvent event) {
+ paintNatTable(event);
+ }
+
+ private void paintNatTable(final PaintEvent event) {
+ }
+
+ //TODO should this be something that is called by the presentation model, firing an event that is catched here?
+ public void updateResize() {
+ updateResize(true);
+ }
+
+ /**
+ * Update the table screen by re-calculating everything again. It should not
+ * be called too frequently.
+ *
+ * @param redraw
+ * true to redraw the table
+ */
+ private void updateResize(final boolean redraw) {
+ if (isDisposed()) {
+ return;
+ }
+// doCommand(new RecalculateScrollBarsCommand());
+ if (redraw) {
+ redraw();
+ }
+ }
+
+ private void disableScrollBar(ScrollBar scrollBar) {
+ scrollBar.setMinimum(0);
+ scrollBar.setMaximum(1);
+ scrollBar.setThumb(1);
+ scrollBar.setEnabled(false);
+ }
+
+ @Override
+ protected void checkSubclass() {
+ //TODO this seems to be the same as in Composite, so why do we put it in here again?
+ }
+
+}
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/SWTNatTableRenderer.java b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/SWTNatTableRenderer.java
deleted file mode 100644
index 398783f..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/SWTNatTableRenderer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.eclipse.nebula.widgets.nattable.renderer.swt;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-
-/**
- * Put all of the rendering related stuff in here.
- * But to connect the rendering to the core, there needs to be some transition I guess.
- * I haven't figured out the big picture on this yet. So this is just the stub for
- * further discussion at the moment.
- *
- * @author Dirk Fauth
- *
- */
-public class SWTNatTableRenderer extends Canvas implements PaintListener {
-
- public static final int DEFAULT_STYLE_OPTIONS = SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL;
-
- public SWTNatTableRenderer(Composite parent) {
- super(parent, DEFAULT_STYLE_OPTIONS);
- }
-
- public SWTNatTableRenderer(Composite parent, int style) {
- super(parent, style);
- }
-
- @Override
- public void paintControl(final PaintEvent event) {
- paintNatTable(event);
- }
-
- private void paintNatTable(final PaintEvent event) {
- }
-}