diff options
author | sgunturi | 2005-10-04 17:59:17 +0000 |
---|---|---|
committer | sgunturi | 2005-10-04 17:59:17 +0000 |
commit | 1d30c6009b83e3e1ca48cb32c66f8ce485968a75 (patch) | |
tree | ae16930a201142a683bf600cf3429e974eecf5aa | |
parent | cf8339634eacfdbf91f2189dfe67170f10cb5150 (diff) | |
download | webtools.javaee-1d30c6009b83e3e1ca48cb32c66f8ce485968a75.tar.gz webtools.javaee-1d30c6009b83e3e1ca48cb32c66f8ce485968a75.tar.xz webtools.javaee-1d30c6009b83e3e1ca48cb32c66f8ce485968a75.zip |
109310 : BeaninfoEntrySearchpathDialog cleaned
2 files changed, 193 insertions, 74 deletions
diff --git a/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfoEntrySearchpathDialog.java b/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfoEntrySearchpathDialog.java index 58358d678..2ccf00d78 100644 --- a/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfoEntrySearchpathDialog.java +++ b/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfoEntrySearchpathDialog.java @@ -11,7 +11,7 @@ package org.eclipse.jem.internal.beaninfo.ui; /* * $RCSfile: BeaninfoEntrySearchpathDialog.java,v $ - * $Revision: 1.8 $ $Date: 2005/08/24 21:07:12 $ + * $Revision: 1.9 $ $Date: 2005/10/04 17:59:17 $ */ import java.text.MessageFormat; @@ -21,15 +21,14 @@ import java.util.List; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.core.*; -import org.eclipse.jdt.internal.ui.util.PixelConverter; -import org.eclipse.jdt.internal.ui.wizards.TypedViewerFilter; -import org.eclipse.jdt.internal.ui.wizards.dialogfields.*; import org.eclipse.jdt.ui.JavaElementLabelProvider; import org.eclipse.jface.dialogs.*; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.*; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.*; +import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; import org.eclipse.ui.dialogs.ISelectionStatusValidator; @@ -44,28 +43,21 @@ import org.eclipse.jem.internal.beaninfo.core.SearchpathEntry; * @author */ public class BeaninfoEntrySearchpathDialog extends Dialog { - - private class DialogAdapter implements IListAdapter { - - // -------- IListAdapter -------- - public void customButtonPressed(ListDialogField field, int index) { - pageCustomButtonPressed(index); - } - - public void selectionChanged(ListDialogField field) { - } - - /** - * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(ListDialogField) - */ - public void doubleClicked(ListDialogField field) { - } - - } - protected BPBeaninfoListElement infoElement; protected IJavaProject jProject; - protected ListDialogField listField; + //protected ListDialogField listField; + + private Composite top; + private Table table; + private TableViewer tableViewer; + private Label label; + private Composite buttonsBar; + private Button upbutton; + private Button downButton; + private Button choosePackagesButton; + private Button removeButton; + private List tableElements; + private boolean enabled = true; public BeaninfoEntrySearchpathDialog( Shell parentShell, @@ -75,24 +67,7 @@ public class BeaninfoEntrySearchpathDialog extends Dialog { this.infoElement = infoElement; this.jProject = jProject; - - DialogAdapter adapter = new DialogAdapter(); - - String[] buttonLabels = new String[] { - BeanInfoUIMessages.BeaninfoPathsBlock_UI__searchpath_up_button, - BeanInfoUIMessages.BeaninfoPathsBlock_UI__searchpath_down_button, - /* 2 */ - null, - BeanInfoUIMessages.SearchPathDialog_ChoosePackages, - /* 4 */ - null, - BeanInfoUIMessages.SearchPathDialog_Remove }; - - listField = new ListDialogField(adapter, buttonLabels, new SearchPathListLabelProvider(jProject)); - listField.setLabelText(BeanInfoUIMessages.SearchPathDialog_Desc_Label); - listField.setUpButtonIndex(0); - listField.setDownButtonIndex(1); - listField.setRemoveButtonIndex(5); + this.tableElements = new ArrayList(); } protected void configureShell(Shell newShell) { @@ -104,58 +79,202 @@ public class BeaninfoEntrySearchpathDialog extends Dialog { } protected Control createDialogArea(Composite parent) { - PixelConverter converter = new PixelConverter(parent); + top = new Composite(parent, SWT.NONE); + top.setLayoutData(new GridData(GridData.FILL_BOTH)); + top.setLayout(new GridLayout(2, false)); + + label = new Label(top, SWT.NONE); + label.setText(BeanInfoUIMessages.SearchPathDialog_Desc_Label); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 2; + label.setLayoutData(gd); + + createTable(); + createButtonsBar(); - Composite composite = new Composite(parent, SWT.NONE); + updatePackagesList(); + + updateButtons(); - LayoutUtil.doDefaultLayout( - composite, - new DialogField[] { listField }, - true, - SWT.DEFAULT, - SWT.DEFAULT); - int buttonBarWidth = converter.convertWidthInCharsToPixels(24); - listField.setButtonsMinWidth(buttonBarWidth); + return top; + } - updatePackagesList(); + /** + * This method initializes table + * + */ + private void createTable() { + GridData gridData1 = new org.eclipse.swt.layout.GridData(); + gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; + gridData1.grabExcessHorizontalSpace = true; + gridData1.grabExcessVerticalSpace = true; + gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.FILL; + table = new Table(top, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + table.setLayoutData(gridData1); + table.addSelectionListener(new SelectionListener(){ + public void widgetSelected(SelectionEvent e) { + updateButtons(); + } + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + tableViewer = new TableViewer(table); + //tableViewer.setSorter(new BIListElementSorter()); + tableViewer.setContentProvider(new ArrayContentProvider()); + tableViewer.setLabelProvider(new SearchPathListLabelProvider(jProject)); + tableViewer.setInput(tableElements); + } - return composite; + /** + * This method initializes buttonsBar + * + */ + private void createButtonsBar() { + RowLayout rowLayout = new RowLayout(); + rowLayout.type = org.eclipse.swt.SWT.VERTICAL; + rowLayout.marginLeft = 3; + rowLayout.fill = true; + GridData gridData2 = new org.eclipse.swt.layout.GridData(); + gridData2.grabExcessVerticalSpace = true; + gridData2.verticalAlignment = org.eclipse.swt.layout.GridData.FILL; + gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.BEGINNING; + buttonsBar = new Composite(top, SWT.NONE); + buttonsBar.setLayoutData(gridData2); + buttonsBar.setLayout(rowLayout); + upbutton = new Button(buttonsBar, SWT.NONE); + upbutton.setText(BeanInfoUIMessages.BeaninfoPathsBlock_UI__searchpath_up_button); + upbutton.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + List selected = BeaninfoPathsBlock.getSelectedList(tableViewer.getSelection()); + Iterator selItr = selected.iterator(); + while (selItr.hasNext()) { + Object element = selItr.next(); + int oldIndex = tableElements.indexOf(element); + if(oldIndex>0){ + tableElements.remove(element); + tableElements.add(--oldIndex, element); + } + } + tableViewer.refresh(); + pageChanged(); + } + }); + downButton = new Button(buttonsBar, SWT.NONE); + downButton.setText(BeanInfoUIMessages.BeaninfoPathsBlock_UI__searchpath_down_button); + downButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { + public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { + List selected = BeaninfoPathsBlock.getSelectedList(tableViewer.getSelection()); + Iterator selItr = selected.iterator(); + while (selItr.hasNext()) { + Object element = selItr.next(); + int oldIndex = tableElements.indexOf(element); + if(oldIndex<(tableElements.size()-1)){ + tableElements.remove(element); + tableElements.add(++oldIndex, element); + } + } + tableViewer.refresh(); + pageChanged(); + } + }); + new Label(buttonsBar, SWT.NONE); + choosePackagesButton = new Button(buttonsBar, SWT.NONE); + choosePackagesButton.setText(BeanInfoUIMessages.SearchPathDialog_ChoosePackages); + choosePackagesButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { + public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { + final List elementsToAdd = choosePackages(); + if (elementsToAdd != null && !elementsToAdd.isEmpty()) { + tableElements.addAll(elementsToAdd); + tableViewer.refresh(); + table.getDisplay().asyncExec(new Runnable(){ + public void run() { + tableViewer.setSelection(new StructuredSelection(elementsToAdd)); + }; + }); + } + } + }); + new Label(buttonsBar, SWT.NONE); + removeButton = new Button(buttonsBar, SWT.NONE); + removeButton.setText(BeanInfoUIMessages.SearchPathDialog_Remove); + removeButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { + public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { + List selected = BeaninfoPathsBlock.getSelectedList(tableViewer.getSelection()); + tableElements.removeAll(selected); + tableViewer.refresh(); + pageChanged(); + } + }); + } + + + protected void pageChanged() { + // TODO Auto-generated method stub + + } + + protected void updateButtons() { + if(top!=null && !top.isDisposed()){ + upbutton.setEnabled(enabled && canMoveUp()); + downButton.setEnabled(enabled && canMoveDown()); + removeButton.setEnabled(enabled && !tableViewer.getSelection().isEmpty()); + choosePackagesButton.setEnabled(enabled); + } + } + + private boolean canMoveDown() { + int[] indc= table.getSelectionIndices(); + int k= tableElements.size() - 1; + for (int i= indc.length - 1; i >= 0 ; i--, k--) { + if (indc[i] != k) { + return true; + } + } + return false; + } + + private boolean canMoveUp() { + int[] indc= table.getSelectionIndices(); + for (int i= 0; i < indc.length; i++) { + if (indc[i] != i) { + return true; + } + } + return false; } private void updatePackagesList() { if (infoElement.getEntry().getKind() == BeaninfoEntry.BIE_PLUGIN) { // We don't allow these to be updated. They should only be used through // registered mechanisms and we won't be showing them here normally. - listField.setLabelText(BeanInfoUIMessages.SearchPathDialog_NotEditable_INFO_); - listField.setEnabled(false); + label.setText(BeanInfoUIMessages.SearchPathDialog_NotEditable_INFO_); + updateEnabledState(false); return; } - - listField.setElements(Arrays.asList(infoElement.getSearchpaths())); + tableElements.clear(); + tableElements.addAll(Arrays.asList(infoElement.getSearchpaths())); + tableViewer.refresh(); } - protected void pageCustomButtonPressed(int index) { - if (index != 3) - return; - - List elementsToAdd = choosePackages(); - - if (elementsToAdd != null && !elementsToAdd.isEmpty()) { - listField.addElements(elementsToAdd); - listField.postSetSelection(new StructuredSelection(elementsToAdd)); + private void updateEnabledState(boolean b) { + enabled = b; + if(top!=null && !top.isDisposed()){ + label.setEnabled(enabled); + table.setEnabled(enabled); + updateButtons(); } } protected void okPressed() { - if (listField.isEnabled()) { + if (table.isEnabled()) { // If the field is not enabled, then there is no update to perform. We don't // want to accidentially wipe out the search paths in this case. // Override to put the list of elements back into the BPBeaninfoListElement // Until then they aren't actually updated. - List paths = listField.getElements(); infoElement.setSearchpaths( - (BPSearchListElement[]) paths.toArray(new BPSearchListElement[paths.size()])); + (BPSearchListElement[]) tableElements.toArray(new BPSearchListElement[tableElements.size()])); } super.okPressed(); } @@ -280,7 +399,7 @@ public class BeaninfoEntrySearchpathDialog extends Dialog { * so that they don't show up in the list. */ protected Object[] getFilteredExistingEntries(IPackageFragmentRoot[] roots) { - List entries = listField.getElements(); + List entries = tableElements; List fragments = new ArrayList(entries.size()); Iterator itr = entries.iterator(); while (itr.hasNext()) { @@ -295,7 +414,7 @@ public class BeaninfoEntrySearchpathDialog extends Dialog { * so that they don't show up in the list. This one is just the package names. */ protected List getFilteredExistingEntries() { - List entries = listField.getElements(); + List entries = tableElements; List names = new ArrayList(entries.size()); Iterator itr = entries.iterator(); while (itr.hasNext()) { diff --git a/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfosWorkbookPage.java b/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfosWorkbookPage.java index 11802e2d7..8ca452845 100644 --- a/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfosWorkbookPage.java +++ b/plugins/org.eclipse.jem.ui/beaninfoui/org/eclipse/jem/internal/beaninfo/ui/BeaninfosWorkbookPage.java @@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: BeaninfosWorkbookPage.java,v $ - * $Revision: 1.10 $ $Date: 2005/10/03 23:06:42 $ + * $Revision: 1.11 $ $Date: 2005/10/04 17:59:17 $ */ package org.eclipse.jem.internal.beaninfo.ui; @@ -556,7 +556,7 @@ public class BeaninfosWorkbookPage implements IBuildSearchPage{ addVariableButton.setEnabled(beaninfoPathsBlock.isBeaninfoEnabled()); removeButton.setEnabled(selected!=null && selected.size()>0 && beaninfoPathsBlock.isBeaninfoEnabled()); - modifyPathsButton.setEnabled(selected!=null && selected.size()>0 && beaninfoPathsBlock.isBeaninfoEnabled()); + modifyPathsButton.setEnabled(selected!=null && selected.size()==1 && beaninfoPathsBlock.isBeaninfoEnabled()); } private List chooseProjects() { |