diff options
| author | Martin Karpisek | 2016-10-01 10:13:45 +0000 |
|---|---|---|
| committer | Lars Vogel | 2016-11-24 23:44:15 +0000 |
| commit | 4c1edad836207649d0dd9fbeee29de301c7d2a86 (patch) | |
| tree | 24724a08388a25837a2d0d831600d62256f73872 | |
| parent | bc9af913938a0c283d91b737c748e6bcafc0fa50 (diff) | |
| download | eclipse.pde.ui-4c1edad836207649d0dd9fbeee29de301c7d2a86.tar.gz eclipse.pde.ui-4c1edad836207649d0dd9fbeee29de301c7d2a86.tar.xz eclipse.pde.ui-4c1edad836207649d0dd9fbeee29de301c7d2a86.zip | |
Bug 247265: Use FilteredTree in new feature project wizard I20161124-2000
- patch using FilteredCheckboxTree (suggested in bugzilla coment #5)
- contains new CheckboxTreePart as tree variant of existing
CheckboxTablePart, this tree part uses internally FilteredCheckboxTree
and PluginListPage of feature project wizard uses it
- small page corrections of grid layout data and indents needed to fit
together Wizard Page with FilteredCheckboxTree for correct alyout
- counter label is always delegating to checked leaf items in
FilteredCheckboxTree (removed separate counter int in the part)
- filtered checkbox tree by default use wildcard at the beginning of
filter string (if user do not insert himself)
- copyrights should be updated
Change-Id: Id18a0c414dfcbb639dc6aceb4184f8bad188764c
Signed-off-by: Martin Karpisek <martin.karpisek@gmail.com>
5 files changed, 316 insertions, 29 deletions
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/CheckboxTreePart.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/CheckboxTreePart.java new file mode 100644 index 0000000000..5174636d6a --- /dev/null +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/CheckboxTreePart.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2016 Martin Karpisek. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.parts; + +import org.eclipse.jface.viewers.*; +import org.eclipse.pde.internal.ui.shared.CachedCheckboxTreeViewer; +import org.eclipse.pde.internal.ui.shared.FilteredCheckboxTree; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class CheckboxTreePart extends StructuredViewerPart { + private FilteredCheckboxTree filteredTree; + + public CheckboxTreePart(String[] buttonLabels) { + super(buttonLabels); + } + + @Override + protected StructuredViewer createStructuredViewer(Composite parent, int style, FormToolkit toolkit) { + style |= SWT.H_SCROLL | SWT.V_SCROLL; + if (toolkit == null) { + style |= SWT.BORDER; + } else { + style |= toolkit.getBorderStyle(); + } + filteredTree = new FilteredCheckboxTree(parent, toolkit, style); + CheckboxTreeViewer treeViewer = filteredTree.getCheckboxTreeViewer(); + treeViewer.addSelectionChangedListener(event -> { + CheckboxTreePart.this.selectionChanged((IStructuredSelection) event.getSelection()); + }); + treeViewer.addCheckStateListener(event -> { + elementChecked(event.getElement(), event.getChecked()); + }); + return treeViewer; + } + + public CachedCheckboxTreeViewer getTreeViewer() { + return (CachedCheckboxTreeViewer) getViewer(); + } + + @Override + protected void buttonSelected(Button button, int index) { + } + + protected void elementChecked(Object element, boolean checked) { + } + + protected void selectionChanged(IStructuredSelection selection) { + } +} diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/WizardCheckboxTreePart.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/WizardCheckboxTreePart.java new file mode 100644 index 0000000000..aed848a57d --- /dev/null +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/WizardCheckboxTreePart.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2016 Martin Karpisek. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Karpisek <martin.karpisek@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.parts; + +import org.eclipse.jface.viewers.*; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.pde.internal.ui.shared.CachedCheckboxTreeViewer; +import org.eclipse.pde.internal.ui.util.SWTUtil; +import org.eclipse.pde.internal.ui.wizards.ListUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class WizardCheckboxTreePart extends CheckboxTreePart { + private int selectAllIndex = -1; + private int deselectAllIndex = -1; + private int selectIndex = -1; + private int deselectIndex = -1; + private String tableName; + private Label counterLabel; + + /** + * Constructor for WizardCheckboxTablePart. + * @param buttonLabels + */ + public WizardCheckboxTreePart(String tableName, String[] buttonLabels) { + super(buttonLabels); + this.tableName = tableName; + } + + public WizardCheckboxTreePart(String mainLabel) { + this(mainLabel, new String[] {PDEUIMessages.WizardCheckboxTablePart_selectAll, PDEUIMessages.WizardCheckboxTablePart_deselectAll, PDEUIMessages.WizardCheckboxTablePart_select, PDEUIMessages.WizardCheckboxTablePart_deselect}); + setSelectAllIndex(0); + setDeselectAllIndex(1); + setSelectIndex(2); + setDeselectIndex(3); + } + + public void setSelectAllIndex(int index) { + this.selectAllIndex = index; + } + + public void setDeselectAllIndex(int index) { + this.deselectAllIndex = index; + } + + public void setSelectIndex(int index) { + this.selectIndex = index; + } + + public void setDeselectIndex(int index) { + this.deselectIndex = index; + } + + @Override + protected void buttonSelected(Button button, int index) { + if (index == selectAllIndex) { + handleSelectAll(true); + } + if (index == deselectAllIndex) { + handleSelectAll(false); + } + if (index == selectIndex) { + handleSelect(true); + } + if (index == deselectIndex) { + handleSelect(false); + } + } + + public Object[] getSelection() { + CheckboxTreeViewer viewer = getTreeViewer(); + return viewer.getCheckedElements(); + } + + public void setSelection(Object[] selected) { + CachedCheckboxTreeViewer viewer = getTreeViewer(); + viewer.setCheckedElements(selected); + updateCounterLabel(); + } + + public void createControl(Composite parent) { + createControl(parent, 2); + } + + public void createControl(Composite parent, int span) { + createControl(parent, SWT.NULL, span, null); + counterLabel = new Label(parent, SWT.NULL); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan = span; + counterLabel.setLayoutData(gd); + updateCounterLabel(); + } + + public void createControl(Composite parent, int span, boolean multiselect) { + if (multiselect) { + createControl(parent, SWT.MULTI, span, null); + } else { + createControl(parent, SWT.NULL, span, null); + } + counterLabel = new Label(parent, SWT.NULL); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan = span; + counterLabel.setLayoutData(gd); + updateCounterLabel(); + } + + @Override + protected Button createButton(Composite parent, String label, int index, FormToolkit toolkit) { + Button button = super.createButton(parent, label, index, toolkit); + SWTUtil.setButtonDimensionHint(button); + return button; + } + + @Override + protected StructuredViewer createStructuredViewer(Composite parent, int style, FormToolkit toolkit) { + StructuredViewer viewer = super.createStructuredViewer(parent, style, toolkit); + viewer.setComparator(ListUtil.NAME_COMPARATOR); + return viewer; + } + + @Override + protected void createMainLabel(Composite parent, int span, FormToolkit toolkit) { + if (tableName == null) + return; + Label label = new Label(parent, SWT.NULL); + label.setText(tableName); + GridData gd = new GridData(); + gd.horizontalSpan = span; + label.setLayoutData(gd); + } + + public void updateCounterLabel() { + String number = "" + getSelectionCount(); //$NON-NLS-1$ + String totalNumber = "" + getTotalCount(); //$NON-NLS-1$ + String message = NLS.bind(PDEUIMessages.WizardCheckboxTablePart_counter, (new String[] {number, totalNumber})); + counterLabel.setText(message); + } + + public int getSelectionCount() { + CachedCheckboxTreeViewer viewer = getTreeViewer(); + if (viewer == null) { + return 0; + } + return viewer.getCheckedLeafCount(); + } + + public void selectAll(boolean select) { + handleSelectAll(select); + } + + private int getTotalCount() { + CachedCheckboxTreeViewer viewer = getTreeViewer(); + if (viewer == null) { + return 0; + } + + ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider(); + if (contentProvider == null) { + return 0; + } + return contentProvider.getElements(viewer.getInput()).length; + } + + protected void handleSelectAll(boolean select) { + CachedCheckboxTreeViewer viewer = getTreeViewer(); + viewer.setAllChecked(select); + updateCounterLabel(); + } + + protected void handleSelect(boolean select) { + CachedCheckboxTreeViewer viewer = getTreeViewer(); + if (viewer.getTree().getSelection().length > 0) { + TreeItem[] selected = viewer.getTree().getSelection(); + for (int i = 0; i < selected.length; i++) { + TreeItem item = selected[i]; + // item.setChecked(select); + viewer.setChecked(item.getData(), select); + } + updateCounterLabel(); + } + } + + @Override + protected void elementChecked(Object element, boolean checked) { + updateCounterLabel(); + } + + public Label getCounterLabel() { + return counterLabel; + } +} diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/FilteredCheckboxTree.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/FilteredCheckboxTree.java index b96728c9be..d6761ed43d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/FilteredCheckboxTree.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/FilteredCheckboxTree.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 IBM Corporation and others. + * Copyright (c) 2010, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Martin Karpisek <martin.karpisek@gmail.com> - Bug 247265 *******************************************************************************/ package org.eclipse.pde.internal.ui.shared; @@ -127,4 +128,18 @@ public class FilteredCheckboxTree extends FilteredTree { protected long getRefreshJobDelay() { return FILTER_DELAY; } + + /** + * Add wildcard at the beginning of filter string if user did not added + * wildcard himself. + */ + @Override + protected String getFilterString() { + String original = super.getFilterString(); + String asterisk = "*"; //$NON-NLS-1$ + if (original != null && !original.equals(getInitialText()) && !original.startsWith(asterisk)) { + return asterisk + original; + } + return original; + } }
\ No newline at end of file diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/BasePluginListPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/BasePluginListPage.java index 4d2697aa04..ca952eb4f7 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/BasePluginListPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/BasePluginListPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Martin Karpisek <martin.karpisek@gmail.com> - Bug 247265 *******************************************************************************/ package org.eclipse.pde.internal.ui.wizards.feature; @@ -14,18 +15,18 @@ package org.eclipse.pde.internal.ui.wizards.feature; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.pde.internal.ui.PDEPlugin; -import org.eclipse.pde.internal.ui.parts.WizardCheckboxTablePart; +import org.eclipse.pde.internal.ui.parts.WizardCheckboxTreePart; import org.eclipse.swt.widgets.Composite; public class BasePluginListPage extends WizardPage { - protected WizardCheckboxTablePart tablePart; + protected WizardCheckboxTreePart treePart; /** * @param pageName */ public BasePluginListPage(String pageName) { super(pageName); - tablePart = new WizardCheckboxTablePart(null); + treePart = new WizardCheckboxTreePart(null); PDEPlugin.getDefault().getLabelProvider().connect(this); } @@ -36,7 +37,7 @@ public class BasePluginListPage extends WizardPage { */ public BasePluginListPage(String pageName, String title, ImageDescriptor titleImage) { super(pageName, title, titleImage); - tablePart = new WizardCheckboxTablePart(null); + treePart = new WizardCheckboxTreePart(null); PDEPlugin.getDefault().getLabelProvider().connect(this); } @@ -55,7 +56,7 @@ public class BasePluginListPage extends WizardPage { public void setVisible(boolean visible) { super.setVisible(visible); if (visible) { - tablePart.getControl().setFocus(); + treePart.getControl().setFocus(); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/PluginListPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/PluginListPage.java index fb561f7e1c..b352eabd03 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/PluginListPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/feature/PluginListPage.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel <Lars.Vogel@vogella.com> - Bug 487943 + * Martin Karpisek <martin.karpisek@gmail.com> - Bug 247265 *******************************************************************************/ package org.eclipse.pde.internal.ui.wizards.feature; @@ -37,7 +38,7 @@ import org.eclipse.swt.widgets.*; import org.eclipse.ui.PlatformUI; public class PluginListPage extends BasePluginListPage { - class PluginContentProvider implements IStructuredContentProvider { + class PluginContentProvider implements ITreeContentProvider { @Override public Object[] getElements(Object parent) { return PluginRegistry.getActiveModels(); @@ -63,11 +64,26 @@ public class PluginListPage extends BasePluginListPage { } } } + + @Override + public Object[] getChildren(Object parentElement) { + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + return false; + } } private Combo fLaunchConfigsCombo; private Button fInitLaunchConfigButton; - private CheckboxTableViewer pluginViewer; + private CheckboxTreeViewer pluginViewer; private static final String S_INIT_LAUNCH = "initLaunch"; //$NON-NLS-1$ public PluginListPage() { @@ -99,14 +115,14 @@ public class PluginListPage extends BasePluginListPage { public void widgetSelected(SelectionEvent e) { boolean initLaunchConfigs = fInitLaunchConfigButton.getSelection(); fLaunchConfigsCombo.setEnabled(initLaunchConfigs); - tablePart.setEnabled(!initLaunchConfigs); + treePart.setEnabled(!initLaunchConfigs); } }); fLaunchConfigsCombo = new Combo(container, SWT.READ_ONLY); fLaunchConfigsCombo.setItems(launchConfigs); gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); - gd.horizontalSpan = 2; + gd.horizontalSpan = 3; fLaunchConfigsCombo.setLayoutData(gd); fLaunchConfigsCombo.select(0); fLaunchConfigsCombo.setEnabled(initLaunch); @@ -114,46 +130,39 @@ public class PluginListPage extends BasePluginListPage { Button initPluginsButton = new Button(container, SWT.RADIO); initPluginsButton.setText(PDEUIMessages.PluginListPage_initializeFromPlugins); gd = new GridData(); - gd.horizontalSpan = 3; + gd.horizontalSpan = 4; initPluginsButton.setLayoutData(gd); initPluginsButton.setSelection(!initLaunch); } - tablePart.createControl(container, 3, true); - pluginViewer = tablePart.getTableViewer(); + treePart.createControl(container, 4, true); + pluginViewer = treePart.getTreeViewer(); pluginViewer.setContentProvider(new PluginContentProvider()); pluginViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); pluginViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); - gd = (GridData) tablePart.getControl().getLayoutData(); - if (launchConfigs.length > 0) { - gd.horizontalIndent = 30; - ((GridData) tablePart.getCounterLabel().getLayoutData()).horizontalIndent = 30; - } + gd = (GridData) treePart.getControl().getLayoutData(); + gd.horizontalIndent = 0; gd.heightHint = 250; gd.widthHint = 300; pluginViewer.setInput(PDECore.getDefault().getModelManager()); - tablePart.setSelection(new Object[0]); - tablePart.setEnabled(!initLaunch); + treePart.setSelection(new Object[0]); + treePart.setEnabled(!initLaunch); setControl(container); Dialog.applyDialogFont(container); PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.NEW_FEATURE_REFERENCED_PLUGINS); pluginViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { - TableItem firstTI = pluginViewer.getTable().getSelection()[0]; - if (firstTI.getChecked()) { - firstTI.setChecked(false); - } else { - firstTI.setChecked(true); - } - tablePart.updateCount(pluginViewer.getCheckedElements().length); + TreeItem firstTI = pluginViewer.getTree().getSelection()[0]; + treePart.getTreeViewer().setChecked(firstTI.getData(), !firstTI.getChecked()); + treePart.updateCounterLabel(); } }); } public IPluginBase[] getSelectedPlugins() { if (fInitLaunchConfigButton == null || !fInitLaunchConfigButton.getSelection()) { - Object[] result = tablePart.getSelection(); + Object[] result = treePart.getTreeViewer().getCheckedLeafElements(); IPluginBase[] plugins = new IPluginBase[result.length]; for (int i = 0; i < result.length; i++) { IPluginModelBase model = (IPluginModelBase) result[i]; |
