From 9c5420b74eafa160b4dca8cb108a0c6f6b9cfccb Mon Sep 17 00:00:00 2001 From: Oleg Krasilnikov Date: Wed, 7 Nov 2007 14:42:59 +0000 Subject: [PATCH] Make tool selection dialog more intuitive --- .../ui/properties/ToolSelectionDialog.java | 131 +++++++++++++----- 1 file changed, 95 insertions(+), 36 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolSelectionDialog.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolSelectionDialog.java index f80ec0438ec..4f31594e886 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolSelectionDialog.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ToolSelectionDialog.java @@ -65,8 +65,7 @@ public class ToolSelectionDialog extends Dialog { private Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT); private Color red = Display.getDefault().getSystemColor(SWT.COLOR_RED); private Color gray = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); -// private Color white = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - private IToolListModification tmod = null; + private IToolListModification tmod = null; public ToolSelectionDialog(Shell shell, IResourceInfo ri) { super (shell); @@ -98,7 +97,7 @@ public class ToolSelectionDialog extends Dialog { removed = new ArrayList(); left = new ArrayList(); right = new ArrayList(); - + Composite c1 = new Composite(composite, SWT.NONE); c1.setLayoutData(new GridData(GridData.FILL_BOTH)); c1.setLayout(new GridLayout(1, false)); @@ -127,7 +126,7 @@ public class ToolSelectionDialog extends Dialog { TableColumn col = new TableColumn(t1, SWT.NONE); col.setText(Messages.getString("ToolSelectionDialog.1")); //$NON-NLS-1$ col.setWidth(COL_WIDTH); - + l1 = new CLabel(c1, SWT.BORDER); l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -153,7 +152,7 @@ public class ToolSelectionDialog extends Dialog { gd.verticalSpan = 2; gd.minimumHeight = 100; txt2.setLayoutData(gd); - + b_add = new Button(c2, SWT.PUSH); b_add.setText(Messages.getString("ToolSelectionDialog.12")); //$NON-NLS-1$ b_add.addSelectionListener(new SelectionAdapter() { @@ -164,10 +163,8 @@ public class ToolSelectionDialog extends Dialog { ITool tool = (ITool)t1.getItem(x).getData(); left.remove(tool); right.add(tool); - tmod.changeProjectTools(null, tool); - - updateData(true); + updateData(); }}); b_add.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false)); @@ -193,7 +190,7 @@ public class ToolSelectionDialog extends Dialog { tmod.changeProjectTools(tool, null); - updateData(true); + updateData(); }}); b_del.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false)); @@ -226,11 +223,14 @@ public class ToolSelectionDialog extends Dialog { for (int j = 0; j button press or double-click. + */ private void handleReplace() { if (! b_rep.isEnabled()) return; @@ -247,30 +247,39 @@ public class ToolSelectionDialog extends Dialog { tmod.changeProjectTools(tool2, tool1); - updateData(true); + updateData(); } - private int removeArrows(Table t) { + /** + * Removes "triangle" marks from all table's items. + * @param t - affected table. + */ + private void removeArrows(Table t) { for (int j=0; j -1); - b_rep.setEnabled(b_all.getSelection() && x1 > -1 && x2 > -1); - b_del.setEnabled(b_all.getSelection() && x2 > -1); - boolean b1 = markReplace(x1, t1, t2, b_add); - boolean b2 = markReplace(x2, t2, t1, b_del); - if (b1 && b2) b_rep.setEnabled(true); - showErrorMessage(t1, false, x1); - showErrorMessage(t2, true, x2); + removeArrows(t1); + removeArrows(t2); + b_add.setEnabled(b_all.getSelection() && t1.getItemCount() > 0); + b_rep.setEnabled(b_all.getSelection() && t1.getItemCount() > 0 && t2.getItemCount() > 0); + b_del.setEnabled(b_all.getSelection() && t2.getItemCount() > 0); + + if (t1.isFocusControl()) { + markReplace(t1, t2, b_add); + int j = adjustPosition(t2); + markReplace(t2, t1, b_del); + if (j != -1) + b_rep.setEnabled(true); + } else { + markReplace(t2, t1, b_del); + int j = adjustPosition(t1); + markReplace(t1, t2, b_add); + if (j != -1) + b_rep.setEnabled(true); + } + showErrorMessage(t1, false); + showErrorMessage(t2, true); } - private void showErrorMessage(Table t, boolean isPrj, int x) { + /** + * Changes position of inactive table + * to enable replacement, if possible. + * + * returns new position or -1 if there's no tools to replace. + */ + private int adjustPosition(Table t) { + int j = t.getSelectionIndex(); + TableItem ti = t.getItem(j); + if (ToolChainEditTab.IMG_ARROW.equals(ti.getImage())) + return j; + for (j=0; j