aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Reichl2014-01-07 04:12:33 (EST)
committerddunne2014-01-23 15:02:46 (EST)
commitc4e82b690ef6ae0e67b43b8693ab1171445a306d (patch)
tree9e406539163bd60bb9f13ff8e9e9d8bde8c40b64
parenteb6269b8cd0475e43a30fc116aa5cbf7d1adaa1e (diff)
downloadorg.eclipse.nebula-c4e82b690ef6ae0e67b43b8693ab1171445a306d.zip
org.eclipse.nebula-c4e82b690ef6ae0e67b43b8693ab1171445a306d.tar.gz
org.eclipse.nebula-c4e82b690ef6ae0e67b43b8693ab1171445a306d.tar.bz2
Bug 424836 XViewerEditAdapter extensionsrefs/changes/19/20319/4
the CellEditDescriptor has a new constructor with the additional boolean "fitInCell" - default is ture. if this boolean is false the created control doesn't fit in the klicked cell. it will just start at the top left corner of the cell. the XViewerConverter getInput method returns object for object changes with new references (null allowed). it also have the new methode isValid which decides if the selected object is allowed to edit at the clicked cell (same as ICellModifier.canModify). the XViewerEditAdapter is prepared to extend from it. the XViewerMultiEditAdapter (which is extended from the XViewerEditAdapter) can handle multi select and edit. XViewer.dispose updated (menuManager disposed; display filter removed) Change-Id: I5670e0fb996d30f02abf36119b4ca494a5466afc Signed-off-by: Juergen Reichl <reichljuergen@googlemail.com>
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerConverter.java37
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java4
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java28
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/CellEditDescriptor.java51
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerConverter.java22
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerEditAdapter.java290
-rw-r--r--widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerMultiEditAdapter.java102
7 files changed, 379 insertions, 155 deletions
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerConverter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerConverter.java
index 357274e..c7dbef1 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerConverter.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerConverter.java
@@ -1,5 +1,6 @@
package org.eclipse.nebula.widgets.xviewer.example;
+import java.util.List;
import org.eclipse.nebula.widgets.xviewer.edit.CellEditDescriptor;
import org.eclipse.nebula.widgets.xviewer.edit.XViewerConverter;
import org.eclipse.nebula.widgets.xviewer.example.model.SomeTask;
@@ -24,18 +25,40 @@ public class MyXViewerConverter implements XViewerConverter {
}
@Override
- public void getInput(Control c, CellEditDescriptor ced, Object selObject) {
+ public Object getInput(Control c, CellEditDescriptor ced, Object selObject) {
- if (c instanceof Text) {
- Text text = (Text) c;
- if (selObject instanceof SomeTask) {
- SomeTask someTask = (SomeTask) selObject;
- if (ced.getInputField().equals("completed")) { //$NON-NLS-1$
- someTask.setPercentComplete(Integer.valueOf(text.getText()));
+ if (ced.getInputField().equals("completed")) { //$NON-NLS-1$
+ if (c instanceof Text) {
+ Text text = (Text) c;
+ Integer intValue = Integer.valueOf(text.getText());
+ if (selObject instanceof SomeTask) {
+ SomeTask someTask = (SomeTask) selObject;
+ someTask.setPercentComplete(intValue);
+ } else if (selObject instanceof List<?>) {
+ List<?> list = (List<?>) selObject;
+ if (list.isEmpty()) {
+ return null;
+ }
+ if (((SomeTask) list.get(0)).getPercentComplete() == intValue) {
+ return null;
+ }
+ for (Object o : list) {
+ if (o instanceof SomeTask) {
+ SomeTask someTask = (SomeTask) o;
+ someTask.setPercentComplete(intValue);
+ }
+ }
+ return selObject;
}
}
}
+ return null;
+ }
+
+ @Override
+ public boolean isValid(CellEditDescriptor ced, Object selObject) {
+ return true;
}
}
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java
index 2d3c52d..e1d577e 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer.example/src/org/eclipse/nebula/widgets/xviewer/example/MyXViewerTest.java
@@ -19,7 +19,7 @@ import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.nebula.widgets.xviewer.edit.DefaultXViewerControlFactory;
import org.eclipse.nebula.widgets.xviewer.edit.XViewerControlFactory;
import org.eclipse.nebula.widgets.xviewer.edit.XViewerConverter;
-import org.eclipse.nebula.widgets.xviewer.edit.XViewerEditAdapter;
+import org.eclipse.nebula.widgets.xviewer.edit.XViewerMultiEditAdapter;
import org.eclipse.nebula.widgets.xviewer.example.images.MyImageCache;
import org.eclipse.nebula.widgets.xviewer.example.model.ISomeTask;
import org.eclipse.nebula.widgets.xviewer.example.model.ISomeTask.RunDb;
@@ -81,7 +81,7 @@ public class MyXViewerTest {
// XViewerEditAdapter
XViewerControlFactory cFactory = new DefaultXViewerControlFactory();
XViewerConverter converter = new MyXViewerConverter();
- myXviewer.setXViewerEditAdapter(new XViewerEditAdapter(cFactory, converter));
+ myXviewer.setXViewerEditAdapter(new XViewerMultiEditAdapter(cFactory, converter));
createTaskActionBar(toolBarComposite);
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java
index 7818c6f..a08a7d1 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/XViewer.java
@@ -172,6 +172,17 @@ public class XViewer extends TreeViewer {
if (searchComp != null && !searchComp.isDisposed()) {
searchComp.dispose();
}
+
+ //Remote Display filter
+ Display.getCurrent().removeFilter(SWT.KeyDown, displayKeysListener);
+ Display.getCurrent().removeFilter(SWT.KeyUp, displayKeysListener);
+ Display.getCurrent().removeFilter(SWT.FocusOut, displayFocusListener);
+
+ //Dispose Menu
+ if (menuManager != null) {
+ menuManager.removeAll();
+ menuManager.dispose();
+ }
}
@Override
@@ -337,14 +348,7 @@ public class XViewer extends TreeViewer {
ctrlKeyListenersSet = true;
Display.getCurrent().addFilter(SWT.KeyDown, displayKeysListener);
Display.getCurrent().addFilter(SWT.KeyUp, displayKeysListener);
- Display.getCurrent().addFilter(SWT.FocusOut, new Listener() {
- @Override
- public void handleEvent(Event event) {
- // Clear when focus is lost
- ctrlKeyDown = false;
- altKeyDown = false;
- }
- });
+ Display.getCurrent().addFilter(SWT.FocusOut, displayFocusListener);
}
}
Listener displayKeysListener = new Listener() {
@@ -366,6 +370,14 @@ public class XViewer extends TreeViewer {
}
}
};
+ Listener displayFocusListener = new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ // Clear when focus is lost
+ ctrlKeyDown = false;
+ altKeyDown = false;
+ }
+ };
private Composite searchComp;
public void resetDefaultSorter() {
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/CellEditDescriptor.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/CellEditDescriptor.java
index bfccb88..712e029 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/CellEditDescriptor.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/CellEditDescriptor.java
@@ -13,21 +13,56 @@ public class CellEditDescriptor {
private Class<?> inputType;
private Class<?> control;
private Integer swtStyle;
+ private boolean fitInCell = true;
private IAction action = null;
+ /**
+ * @param control - the control to create
+ * @param swtStyle - style of the control
+ * @param inputField - the input field (identifier)
+ * @param inputType - type of the input
+ */
public CellEditDescriptor(Class<?> control, Integer swtStyle, String inputField, Class<?> inputType) {
- setControl(control);
- setSwtStyle(swtStyle);
- setInputField(inputField);
- setInputType(inputType);
+ this(control, swtStyle, inputField, inputType, null);
}
+ /**
+ * @param control - the control to create
+ * @param swtStyle - style of the control
+ * @param inputField - the input field (identifier)
+ * @param inputType - type of the input
+ * @param action - action for automatic isEnabled check
+ */
public CellEditDescriptor(Class<?> control, Integer swtStyle, String inputField, Class<?> inputType, IAction action) {
+ this(control, swtStyle, inputField, inputType, action, true);
+ }
+
+ /**
+ * @param control - the control to create
+ * @param swtStyle - style of the control
+ * @param inputField - the input field (identifier)
+ * @param inputType - type of the input
+ * @param fitInCell - fit control in cell
+ */
+ public CellEditDescriptor(Class<?> control, Integer swtStyle, String inputField, Class<?> inputType, boolean fitInCell) {
+ this(control, swtStyle, inputField, inputType, null, fitInCell);
+ }
+
+ /**
+ * @param control - the control to create
+ * @param swtStyle - style of the control
+ * @param inputField - the input field (identifier)
+ * @param inputType - type of the input
+ * @param action - action for automatic isEnabled check
+ * @param fitInCell - fit control in cell
+ */
+ public CellEditDescriptor(Class<?> control, Integer swtStyle, String inputField, Class<?> inputType, IAction action, boolean fitInCell) {
setControl(control);
setSwtStyle(swtStyle);
setInputField(inputField);
setInputType(inputType);
setAction(action);
+ setFitInCell(fitInCell);
}
public String getInputField() {
@@ -70,4 +105,12 @@ public class CellEditDescriptor {
return action;
}
+ public boolean isFitInCell() {
+ return fitInCell;
+ }
+
+ public void setFitInCell(boolean fitInCell) {
+ this.fitInCell = fitInCell;
+ }
+
}
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerConverter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerConverter.java
index 49ec418..955e316 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerConverter.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerConverter.java
@@ -11,14 +11,34 @@ public interface XViewerConverter {
/**
* Method to fill the Controls <br>
+ * <br>
* - check with the CellEditDescriptor(getInputField) what to put into the Control
+ *
+ * @param c - current control
+ * @param ced - the cell edit descriptor
+ * @param selObject - the selected object
*/
public abstract void setInput(Control c, CellEditDescriptor ced, Object selObject);
/**
* Method to put the new Input(from the Control c) into the selObject <br>
+ * <br>
* - check with the CellEditDescriptor(getInputField) where to save the new Input
+ *
+ * @param c - current control
+ * @param ced - the cell edit descriptor
+ * @param selObject - the selected object
+ * @return the object if it has a new reference otherwise null -> next step is the automatic xviewer.refresh(object).
+ * if return null it will refresh the old reference.
*/
- public abstract void getInput(Control c, CellEditDescriptor ced, Object selObject);
+ public abstract Object getInput(Control c, CellEditDescriptor ced, Object selObject);
+ /**
+ * is this object valid for this cell?
+ *
+ * @param ced - the cell edit descriptor
+ * @param selObject - the selected object
+ * @return true if you want to allow to modify this object
+ */
+ public abstract boolean isValid(CellEditDescriptor ced, Object selObject);
}
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerEditAdapter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerEditAdapter.java
index b9e4bc1..6a80df2 100644
--- a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerEditAdapter.java
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerEditAdapter.java
@@ -7,6 +7,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -23,12 +24,12 @@ import org.eclipse.swt.widgets.TreeItem;
*/
public class XViewerEditAdapter {
- private XViewer xv;
- private ViewerCell klickedCell;
- private TreeColumn klickedColumn;
+ XViewer xv;
+ ViewerCell klickedCell;
+ TreeColumn klickedColumn;
- private final XViewerControlFactory factory;
- private final XViewerConverter converter;
+ final XViewerControlFactory factory;
+ final XViewerConverter converter;
/**
* TODO MouseDoubleClick and MouseUp not implemented yet swtEvent - SWT.MouseDoubleClick or SWT.MouseDown or
@@ -36,7 +37,6 @@ public class XViewerEditAdapter {
*/
private int swtEvent = 0;
private MyMouseListener mouseListener = null;
- private Listener selListener = null;
public XViewerEditAdapter(XViewerControlFactory factory, XViewerConverter converter) {
this.factory = factory;
@@ -51,8 +51,12 @@ public class XViewerEditAdapter {
mouseListener = new MyMouseListener(swtEvent);
xv.getTree().addMouseListener(mouseListener);
- selListener = new MyListener();
- xv.getTree().addListener(SWT.Selection, selListener);
+ xv.getTree().addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ handleEditEvent(event);
+ }
+ });
}
private class MyMouseListener implements MouseListener {
@@ -90,147 +94,143 @@ public class XViewerEditAdapter {
}
- private class MyListener implements Listener {
+ private void doHandleEvent(Event event) {
+ handleEditEvent(event);
+ }
- private void doHandleEvent(Event event) {
- handleEvent(event);
+ boolean handleEditEvent(Event event) {
+ if (klickedColumn == null || klickedCell == null) {
+ return false;
}
- @Override
- public void handleEvent(Event event) {
- if (klickedColumn == null || klickedCell == null) {
- return;
- }
-
- final Control c;
- try {
- XViewerColumn xColumn =
- xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
- if (xColumn instanceof ExtendedViewerColumn) {
- ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
- CellEditDescriptor ced =
- extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
- if (ced != null) {
- if (ced.getControl() == null) {
- return;
- }
- if (ced.getAction() != null) {
- if (!ced.getAction().isEnabled()) {
- return;
- }
- }
- c = factory.createControl(ced, xv);
- if (c == null) {
- return;
- }
- } else {
- return;
+ final Control c;
+ try {
+ XViewerColumn xColumn =
+ xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
+ if (xColumn instanceof ExtendedViewerColumn) {
+ ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
+ CellEditDescriptor ced = extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
+ if (ced != null) {
+ if (ced.getControl() == null) {
+ return false;
+ }
+ if (ced.getAction() != null && !ced.getAction().isEnabled()) {
+ return false;
+ }
+ if (!converter.isValid(ced, klickedCell.getElement())) {
+ return false;
+ }
+ c = factory.createControl(ced, xv);
+ if (c == null) {
+ return false;
}
} else {
- return;
+ return false;
}
+ } else {
+ return false;
+ }
- if (((TreeItem) event.item) != null) {
- Listener myListener = new Listener() {
- @Override
- public void handleEvent(final Event e) {
- switch (e.type) {
- case SWT.FocusOut:
- // set new value
- getInput(c);
- c.dispose();
- break;
- case SWT.Verify:
- c.setBounds(klickedCell.getBounds());
- break;
- case SWT.Traverse:
- boolean neighbor = false;
- switch (e.detail) {
- case SWT.TRAVERSE_RETURN:
- // set new value
- getInput(c);
- //$FALL-THROUGH$
- case SWT.TRAVERSE_ESCAPE:
- c.dispose();
- e.doit = false;
- break;
- case SWT.TRAVERSE_TAB_NEXT:
- getInput(c);
- neighbor = getNeighbor(ViewerCell.RIGHT, true);
- e.doit = false;
- c.dispose();
- Event eN = new Event();
- eN.type = SWT.Selection;
- eN.widget = xv.getTree();
- if (neighbor) {
- eN.item = klickedCell.getItem();
- }
- doHandleEvent(eN);
- break;
- case SWT.TRAVERSE_TAB_PREVIOUS:
- getInput(c);
- neighbor = getNeighbor(ViewerCell.LEFT, true);
- e.doit = false;
- c.dispose();
- Event eP = new Event();
- eP.type = SWT.Selection;
- eP.widget = xv.getTree();
- if (neighbor) {
- eP.item = klickedCell.getItem();
- }
- doHandleEvent(eP);
- break;
- }
- }
+ if (((TreeItem) event.item) != null) {
+ Listener myListener = new Listener() {
+ @Override
+ public void handleEvent(final Event e) {
+ switch (e.type) {
+ case SWT.FocusOut:
+ // set new value
+ getInput(c);
+ c.dispose();
+ break;
+ case SWT.Verify:
+ c.setBounds(klickedCell.getBounds());
+ break;
+ case SWT.Traverse:
+ boolean neighbor = false;
+ switch (e.detail) {
+ case SWT.TRAVERSE_RETURN:
+ // set new value
+ getInput(c);
+ //$FALL-THROUGH$
+ case SWT.TRAVERSE_ESCAPE:
+ c.dispose();
+ e.doit = false;
+ break;
+ case SWT.TRAVERSE_TAB_NEXT:
+ getInput(c);
+ neighbor = getNeighbor(ViewerCell.RIGHT, true);
+ e.doit = false;
+ c.dispose();
+ Event eN = new Event();
+ eN.type = SWT.Selection;
+ eN.widget = xv.getTree();
+ if (neighbor) {
+ eN.item = klickedCell.getItem();
+ }
+ doHandleEvent(eN);
+ break;
+ case SWT.TRAVERSE_TAB_PREVIOUS:
+ getInput(c);
+ neighbor = getNeighbor(ViewerCell.LEFT, true);
+ e.doit = false;
+ c.dispose();
+ Event eP = new Event();
+ eP.type = SWT.Selection;
+ eP.widget = xv.getTree();
+ if (neighbor) {
+ eP.item = klickedCell.getItem();
+ }
+ doHandleEvent(eP);
+ break;
+ }
}
+ }
- };
- c.addListener(SWT.FocusOut, myListener);
- c.addListener(SWT.Traverse, myListener);
- c.addListener(SWT.Verify, myListener);
- // set old value
- setInput(c);
- c.setFocus();
- }
- } catch (Exception ex) {
- return;
+ };
+ c.addListener(SWT.FocusOut, myListener);
+ c.addListener(SWT.Traverse, myListener);
+ c.addListener(SWT.Verify, myListener);
+ // set old value
+ setInput(c);
+ c.setFocus();
+ return true;
}
+ } catch (Exception ex) {
+ return false;
}
+ return false;
+ }
- private boolean getNeighbor(int directionMask, boolean sameLevel) {
- try {
- if (klickedCell == null) {
- return false;
+ private boolean getNeighbor(int directionMask, boolean sameLevel) {
+ try {
+ if (klickedCell == null) {
+ return false;
+ }
+ Point cellPosition = new Point(klickedCell.getBounds().x, klickedCell.getBounds().y);
+ klickedCell = xv.getCell(cellPosition).getNeighbor(directionMask, sameLevel);
+ klickedColumn = xv.getColumnUnderMouseClick(new Point(klickedCell.getBounds().x, klickedCell.getBounds().y));
+ XViewerColumn xColumn =
+ xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
+ if (xColumn instanceof ExtendedViewerColumn) {
+ ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
+ CellEditDescriptor ced = extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
+ if (ced == null) {
+ return getNeighbor(directionMask, sameLevel);
}
- Point cellPosition = new Point(klickedCell.getBounds().x, klickedCell.getBounds().y);
- klickedCell = xv.getCell(cellPosition).getNeighbor(directionMask, sameLevel);
- klickedColumn =
- xv.getColumnUnderMouseClick(new Point(klickedCell.getBounds().x, klickedCell.getBounds().y));
- XViewerColumn xColumn =
- xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
- if (xColumn instanceof ExtendedViewerColumn) {
- ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
- CellEditDescriptor ced =
- extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
- if (ced == null) {
- return getNeighbor(directionMask, sameLevel);
- }
- if (ced.getControl() == null) {
- return getNeighbor(directionMask, sameLevel);
- }
- } else {
+ if (ced.getControl() == null) {
return getNeighbor(directionMask, sameLevel);
}
- return true;
- } catch (Exception ex) {
- return false;
+ } else {
+ return getNeighbor(directionMask, sameLevel);
}
+ return true;
+ } catch (Exception ex) {
+ return false;
}
}
private static boolean InInput = false;
- private void getInput(Control c) {
+ void getInput(Control c) {
if (InInput) {
return;
}
@@ -247,19 +247,34 @@ public class XViewerEditAdapter {
}
InInput = true;
try {
- converter.getInput(c, ced, klickedCell.getElement());
- xv.refresh(klickedCell.getElement());
+ Object toModify = getInputToModify();
+ Object obj = converter.getInput(c, ced, toModify);
+ if (obj == null) {
+ refreshElement(toModify);
+ } else {
+ refreshElement(obj);
+ }
} catch (Exception ex) {
+ // do nothing
+ } finally {
InInput = false;
}
- InInput = false;
}
}
- private void setInput(Control c) {
+ void refreshElement(Object toRefresh) {
+ xv.refresh(toRefresh);
+ }
+
+ Object getInputToModify() {
+ return klickedCell.getElement();
+ }
+
+ void setInput(Control c) {
if (klickedCell == null) {
return;
}
+ boolean fitInCell = true;
XViewerColumn xCol =
xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
if (xCol instanceof ExtendedViewerColumn) {
@@ -269,7 +284,16 @@ public class XViewerEditAdapter {
return;
}
converter.setInput(c, ced, klickedCell.getElement());
+ fitInCell = ced.isFitInCell();
+ }
+ if (fitInCell) {
+ c.setBounds(klickedCell.getBounds());
+ } else {
+ Rectangle bounds = klickedCell.getBounds();
+ Point point = c.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ bounds.width = point.x;
+ bounds.height = point.y;
+ c.setBounds(bounds);
}
- c.setBounds(klickedCell.getBounds());
}
}
diff --git a/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerMultiEditAdapter.java b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerMultiEditAdapter.java
new file mode 100644
index 0000000..bb1a377
--- /dev/null
+++ b/widgets/xviewer/org.eclipse.nebula.widgets.xviewer/src/org/eclipse/nebula/widgets/xviewer/edit/XViewerMultiEditAdapter.java
@@ -0,0 +1,102 @@
+package org.eclipse.nebula.widgets.xviewer.edit;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * simple multi edit adapter <br>
+ * - Converter.getInput() gives you the current selection in the selObject (first object is the clicked one)
+ *
+ * @author Juergen Reichl
+ */
+public class XViewerMultiEditAdapter extends XViewerEditAdapter {
+
+ private IStructuredSelection currentSelection;
+ private IStructuredSelection oldSelection;
+
+ /**
+ * @param xv
+ */
+ public XViewerMultiEditAdapter(XViewerControlFactory factory, XViewerConverter converter) {
+ super(factory, converter);
+ }
+
+ @Override
+ boolean handleEditEvent(Event event) {
+ IStructuredSelection temp = (IStructuredSelection) xv.getSelection();
+ oldSelection = currentSelection;
+ currentSelection = temp;
+
+ if (oldSelection == null || oldSelection.toList().size() == 1 || !oldSelection.toList().contains(
+ currentSelection.getFirstElement())) {
+ oldSelection = null;
+ }
+
+ if ((event.stateMask & SWT.CTRL) == SWT.CTRL || (event.stateMask & SWT.SHIFT) == SWT.SHIFT) {
+ return false;
+ }
+ boolean handled = super.handleEditEvent(event);
+
+ if (handled && oldSelection != null) {
+ xv.setSelection(oldSelection);
+ currentSelection = oldSelection;
+ }
+ return handled;
+ }
+
+ /**
+ * @param c
+ */
+ @Override
+ void getInput(Control c) {
+ super.getInput(c);
+ if (oldSelection != null) {
+ xv.setSelection(oldSelection);
+ }
+ oldSelection = null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ Object getInputToModify() {
+ List<Object> selection;
+ if (oldSelection != null) {
+ selection = oldSelection.toList();
+ Collections.sort(selection, new Comparator<Object>() {
+ @Override
+ public int compare(Object o1, Object o2) {
+ if (klickedCell.getElement().equals(o1)) {
+ return -1;
+ }
+ if (klickedCell.getElement().equals(o2)) {
+ return 1;
+ }
+ return 0;
+ }
+ });
+ } else {
+ selection = new ArrayList<Object>();
+ selection.add(super.getInputToModify());
+ }
+
+ return selection;
+ }
+
+ @Override
+ void refreshElement(Object toRefresh) {
+ if (toRefresh instanceof List<?>) {
+ for (Object o : (List<?>) toRefresh) {
+ super.refreshElement(o);
+ }
+ } else {
+ super.refreshElement(toRefresh);
+ }
+ }
+
+}