Project: JDT
Bug 165646 [build path] BuildPath -> Classpath -> Order and Export -> New functions
Reported: 2006-11-23 05:52:05 | Status: resolved fixed

Hi, I've implemented a new feature: Now it is possible to move the selected item in the classpath to top or bottom. Not step by step only. Here's my patch: ### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui Index: ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java,v retrieving revision 1.154 diff -u -r1.154 BuildPathsBlock.java --- ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java 10 Nov 2006 17:22:19 -0000 1.154 +++ ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java 23 Nov 2006 10:08:38 -0000 @@ -163,9 +163,11 @@ NewWizardMessages.BuildPathsBlock_classpath_up_button, NewWizardMessages.BuildPathsBlock_classpath_down_button, /* 2 */ null, + NewWizardMessages.BuildPathsBlock_classpath_top_button, + NewWizardMessages.BuildPathsBlock_classpath_bottom_button, + /* 5 */ null, NewWizardMessages.BuildPathsBlock_classpath_checkall_button, NewWizardMessages.BuildPathsBlock_classpath_uncheckall_button - }; fClassPathList= new CheckedListDialogField(null, buttonLabels, new CPListLabelProvider()); @@ -173,8 +175,10 @@ fClassPathList.setLabelText(NewWizardMessages.BuildPathsBlock_classpath_label); fClassPathList.setUpButtonIndex(0); fClassPathList.setDownButtonIndex(1); - fClassPathList.setCheckAllButtonIndex(3); - fClassPathList.setUncheckAllButtonIndex(4); + fClassPathList.setTopButtonIndex(3); + fClassPathList.setBottomButtonIndex(4); + fClassPathList.setCheckAllButtonIndex(6); + fClassPathList.setUncheckAllButtonIndex(7); fBuildPathDialogField= new StringButtonDialogField(adapter); fBuildPathDialogField.setButtonLabel(NewWizardMessages.BuildPathsBlock_buildpath_button); Index: ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java,v retrieving revision 1.49 diff -u -r1.49 NewWizardMessages.java --- ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java 17 Aug 2006 10:30:25 -0000 1.49 +++ ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java 23 Nov 2006 10:08:37 -0000 @@ -222,6 +222,8 @@ public static String BuildPathsBlock_classpath_label; public static String BuildPathsBlock_classpath_up_button; public static String BuildPathsBlock_classpath_down_button; + public static String BuildPathsBlock_classpath_top_button; + public static String BuildPathsBlock_classpath_bottom_button; public static String BuildPathsBlock_classpath_checkall_button; public static String BuildPathsBlock_classpath_uncheckall_button; public static String BuildPathsBlock_buildpath_label; Index: ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties,v retrieving revision 1.236 diff -u -r1.236 NewWizardMessages.properties --- ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties 6 Oct 2006 14:26:39 -0000 1.236 +++ ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties 23 Nov 2006 10:08:38 -0000 @@ -256,6 +256,8 @@ BuildPathsBlock_classpath_up_button=&Up BuildPathsBlock_classpath_down_button=&Down +BuildPathsBlock_classpath_top_button=&Top +BuildPathsBlock_classpath_bottom_button=&Bottom BuildPathsBlock_classpath_checkall_button=Select &All BuildPathsBlock_classpath_uncheckall_button=D&eselect All Index: ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/ListDialogField.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/ListDialogField.java,v retrieving revision 1.60 diff -u -r1.60 ListDialogField.java --- ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/ListDialogField.java 25 Sep 2006 08:47:23 -0000 1.60 +++ ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/ListDialogField.java 23 Nov 2006 10:08:38 -0000 @@ -88,6 +88,9 @@ return data; } } + + private static final boolean MOVE_TO_TOP = true; + private static final boolean MOVE_TO_BOTTOM = false; protected TableViewer fTable; protected Control fTableControl; @@ -104,6 +107,8 @@ private int fRemoveButtonIndex; private int fUpButtonIndex; private int fDownButtonIndex; + private int fTopButtonIndex; + private int fBottomButtonIndex; private Label fLastSeparator; @@ -153,6 +158,8 @@ fRemoveButtonIndex= -1; fUpButtonIndex= -1; fDownButtonIndex= -1; + fTopButtonIndex= -1; + fBottomButtonIndex= -1; } /** @@ -185,7 +192,27 @@ fDownButtonIndex= downButtonIndex; } - /** + /** + * Sets the index of the 'top' button in the button label array passed in the constructor. + * The behavior of the button marked as the 'top' button will then be handled internally. + * (enable state, button invocation behavior) + */ + public void setTopButtonIndex(int topButtonIndex) { + Assert.isTrue(topButtonIndex < fButtonLabels.length); + fTopButtonIndex= topButtonIndex; + } + + /** + * Sets the index of the 'bottom' button in the button label array passed in the constructor. + * The behavior of the button marked as the 'bottom' button will then be handled internally. + * (enable state, button invocation behavior) + */ + public void setBottomButtonIndex(int bottomButtonIndex) { + Assert.isTrue(bottomButtonIndex < fButtonLabels.length); + fBottomButtonIndex= bottomButtonIndex; + } + + /** * Sets the viewer comparator. * @param viewerComparator The viewer comparator to set */ @@ -224,6 +251,16 @@ if (!fButtonControls[index].isEnabled() && fUpButtonIndex != -1) { fButtonControls[fUpButtonIndex].setFocus(); } + } else if (index == fTopButtonIndex) { + top(); + if (!fButtonControls[index].isEnabled() && fTopButtonIndex != -1) { + fButtonControls[fTopButtonIndex].setFocus(); + } + } else if (index == fBottomButtonIndex) { + bottom(); + if (!fButtonControls[index].isEnabled() && fBottomButtonIndex != -1) { + fButtonControls[fBottomButtonIndex].setFocus(); + } } else { return false; } @@ -231,7 +268,17 @@ } - // ------ layout helpers + private void bottom() + { + moveBottom(getSelectedElements()); + } + + private void top() + { + moveTop(getSelectedElements()); + } + + // ------ layout helpers /* * @see DialogField#doFillIntoGrid @@ -504,9 +551,9 @@ protected boolean getManagedButtonState(ISelection sel, int index) { if (index == fRemoveButtonIndex) { return !sel.isEmpty(); - } else if (index == fUpButtonIndex) { + } else if (index == fUpButtonIndex || index == fTopButtonIndex) { return !sel.isEmpty() && canMoveUp(); - } else if (index == fDownButtonIndex) { + } else if (index == fDownButtonIndex || index == fBottomButtonIndex) { return !sel.isEmpty() && canMoveDown(); } return true; @@ -800,7 +847,26 @@ return res; } - private void moveUp(List toMoveUp) { + private List moveTopBottom( List elements, List move, boolean topOrBottom ) { + int nElements= elements.size(); + int nElementsMove = move.size(); + List topBottom= new ArrayList(nElementsMove); + List other= new ArrayList(nElements-nElementsMove); + for (int i= 0; i < nElements; i++) { + Object curr= elements.get(i); + if (move.contains(curr)) { + topBottom.add(curr); + } else { + other.add(curr); + } + } + List res= new ArrayList(nElements); + res.addAll( topOrBottom == MOVE_TO_TOP ? topBottom : other ); + res.addAll( topOrBottom == MOVE_TO_BOTTOM ? topBottom : other ); + return res; + } + + private void moveUp(List toMoveUp) { if (toMoveUp.size() > 0) { setElements(moveUp(fElements, toMoveUp)); fTable.reveal(toMoveUp.get(0)); @@ -813,7 +879,23 @@ fTable.reveal(toMoveDown.get(toMoveDown.size() - 1)); } } - + + private void moveTop( List toMoveTop ) + { + if (toMoveTop.size() > 0) { + setElements(moveTopBottom(fElements, toMoveTop, MOVE_TO_TOP)); + fTable.reveal(toMoveTop.get(0)); + } + } + + private void moveBottom( List toMoveBottom ) + { + if (toMoveBottom.size() > 0) { + setElements(moveTopBottom(fElements, toMoveBottom, MOVE_TO_BOTTOM)); + fTable.reveal(toMoveBottom.get(0)); + } + } + private List reverse(List p) { List reverse= new ArrayList(p.size()); for (int i= p.size()-1; i >= 0; i--) {

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/BuildPathsBlock.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/ListDialogField.java