Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristof Joswig2018-09-13 13:47:01 +0000
committerMatthias Becker2018-09-14 14:48:01 +0000
commit557d45334ede529d39e25e0e1aecb757175647ed (patch)
tree5e590221772aa09f26ac0e35e37e309105af24ab
parentfdd029ad124929776b4cb68140814f8ac355242e (diff)
downloadeclipse.platform.ui.tools-557d45334ede529d39e25e0e1aecb757175647ed.tar.gz
eclipse.platform.ui.tools-557d45334ede529d39e25e0e1aecb757175647ed.tar.xz
eclipse.platform.ui.tools-557d45334ede529d39e25e0e1aecb757175647ed.zip
Fix selection in table when Up/Down button is pressed
- Disable down/up bottons for multip selections - Disable down/up button when last/first element is selected Fixed issue on windows: - Keep focus when pressing up/down buttons Change-Id: Ic4b899a51df19c018abfdfd5df0dd883ad32aab2 Signed-off-by: Christof Joswig <christof.joswig@sap.com>
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java59
1 files changed, 44 insertions, 15 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
index da250fe2..4644796e 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
@@ -38,11 +38,12 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
/**
* <p>
- * A composite widget containing a combo for picking items, a list with selectable items, and action buttons for
- * modifying the list.
+ * A composite widget containing a combo for picking items, a list with
+ * selectable items, and action buttons for modifying the list.
* </p>
*
* @author Steven Spungin
@@ -59,10 +60,10 @@ public abstract class AbstractPickList extends Composite {
private final Group group;
private final Composite toolBar;
+ protected final Button tiAdd;
protected final Button tiRemove;
protected final Button tiUp;
protected final Button tiDown;
- protected final Button tiAdd;
// private final AutoCompleteField autoCompleteField;
public AbstractPickList(Composite parent, int style, List<PickListFeatures> listFeatures, Messages messages,
@@ -151,6 +152,14 @@ public abstract class AbstractPickList extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
moveDownPressed();
+ boolean enable = viewer.getTable().getSelectionIndex() + 1 < getItemCount();
+ if (tiDown.isEnabled() != enable) {
+ tiDown.setEnabled(enable);
+ }
+ if (enable == false && !tiUp.isEnabled()) {
+ tiUp.setEnabled(true);
+ }
+ tiDown.setFocus();
}
});
@@ -163,15 +172,20 @@ public abstract class AbstractPickList extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
moveUpPressed();
+ boolean enable = viewer.getTable().getSelectionIndex() > 0;
+ if (tiUp.isEnabled() != enable) {
+ tiUp.setEnabled(enable);
+ }
+ if (enable == false && !tiDown.isEnabled()) {
+ tiDown.setEnabled(true);
+ }
+ tiUp.setFocus();
}
});
viewer = new TableViewer(group);
- final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
- viewer.getControl().setLayoutData(gd);
-
+ viewer.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1));
viewer.addSelectionChangedListener(event -> updateUiState());
-
updateUiState();
if (listFeatures != null) {
@@ -251,14 +265,29 @@ public abstract class AbstractPickList extends Composite {
}
public void updateUiState() {
- final IStructuredSelection selection = (IStructuredSelection) getList().getSelection();
- final boolean selected = selection.size() > 0;
- final int count = getItemCount();
- final boolean tableIsFocused = getList().getTable().isFocusControl();
- if (tiDown.isDisposed() == false) {
- tiDown.setEnabled(selected && count > 1 && tableIsFocused);
- tiUp.setEnabled(selected && count > 1 && tableIsFocused);
+ TableViewer tableViewer = getList();
+ Table table = tableViewer.getTable();
+ int itemCount = getItemCount();
+ int selectionCount = table.getSelectionCount();
+ int selectionIndex = table.getSelectionIndex();
+
+ if (tiRemove.isEnabled() != selectionCount > 0) {
+ tiRemove.setEnabled(selectionCount > 0);
+ }
+
+ // supports only single selection
+ boolean enableButtons = selectionCount > 0 && itemCount > 1 && selectionCount == 1;
+
+ // disable if last entry is selected
+ boolean enableDown = (enableButtons) ? selectionIndex + 1 < itemCount : false;
+ if (!tiDown.isDisposed() && tiDown.isEnabled() != enableDown) {
+ tiDown.setEnabled(enableDown);
+ }
+
+ // disable if first entry is selected
+ boolean enableUp = (enableButtons) ? selectionIndex > 0 : false;
+ if (!tiUp.isDisposed() && tiUp.isEnabled() != enableUp) {
+ tiUp.setEnabled(enableUp);
}
- tiRemove.setEnabled(selected && tableIsFocused);
}
}

Back to the top