From: Andreas Müller
ContentProvider
.
+ */
+ public ContentProvider() {
+ this.items = Collections.synchronizedList(new ArrayList(2048));
}
/**
- * Sets a new label provider for items in the list. If the label provider
- * also implements {@link
- * org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider
- * .IStyledLabelProvider}, the style text labels provided by it will be used
- * provided that the corresponding preference is set.
- *
- * @see IWorkbenchPreferenceConstants#USE_COLORED_LABELS
- *
- * @param listLabelProvider
- * the label provider for items in the list
+ * Removes all content items and resets progress message.
*/
- public void setListLabelProvider(ILabelProvider listLabelProvider) {
- getItemsListLabelProvider().setProvider(listLabelProvider);
+ public void reset() {
+ this.items.clear();
}
- protected Comparator getItemsComparator() {
- return new ComparatorContentProvider
.
- */
- public ContentProvider() {
- this.items = Collections.synchronizedList(new ArrayList(2048));
- }
-
- /**
- * Removes all content items and resets progress message.
- */
- public void reset() {
- this.items.clear();
-
- }
-
- public void add(Object item) {
- this.items.add(item);
- }
+ public void add(Object item) {
+ this.items.add(item);
+ }
-// /**
-// * Refresh dialog.
-// */
-// public void refresh() {
-// scheduleRefresh();
-// }
+// /**
+// * Refresh dialog.
+// */
+// public void refresh() {
+// scheduleRefresh();
+// }
//
-// /**
-// * Schedule refresh job.
-// */
-// public void scheduleRefresh() {
-// refreshCacheJob.cancelAll();
-// refreshCacheJob.schedule();
-// }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- @Override
- public Object[] getElements(Object inputElement) {
- return items.toArray();
- }
-
- public int getNumberOfElements() {
- return items.size();
- }
+// /**
+// * Schedule refresh job.
+// */
+// public void scheduleRefresh() {
+// refreshCacheJob.cancelAll();
+// refreshCacheJob.schedule();
+// }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- @Override
- public void dispose() {
- }
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return items.toArray();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
+ public int getNumberOfElements() {
+ return items.size();
+ }
+ @Override
+ public void dispose() {
+ }
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
+ }
+ public boolean isUseIdentifier() {
+ return useIdentifier;
+ }
- public boolean isUseIdentifier() {
- return useIdentifier;
- }
+ public StructuredSelection getCurrentSelection() {
+ return currentSelection;
+ }
+ /**
+ * Fills the content provider with matching items.
+ *
+ * @param progressMonitor
+ * must be used to report search progress. The state of this
+ * progress monitor reflects the state of the filtering process.
+ * @throws CoreException
+ */
+ protected abstract void fillContentProvider(IProgressMonitor progressMonitor) ;
- public StructuredSelection getCurrentSelection() {
- return currentSelection;
- }
- /**
- * Fills the content provider with matching items.
- *
- * @param progressMonitor
- * must be used to report search progress. The state of this
- * progress monitor reflects the state of the filtering process.
- * @throws CoreException
- */
- protected abstract void fillContentProvider(IProgressMonitor progressMonitor) ;
+ /**
+ * Refreshes the dialog - has to be called in UI thread.
+ */
+ public void refresh() {
+ if (getList() != null && !getList().getTable().isDisposed()) {
+ List> lastRefreshSelection = ((StructuredSelection) getList()
+ .getSelection()).toList();
+ getList().getTable().deselectAll();
- /**
- * Refreshes the dialog - has to be called in UI thread.
- */
- public void refresh() {
- if (getList() != null && !getList().getTable().isDisposed()) {
-
- List lastRefreshSelection = ((StructuredSelection) getList()
- .getSelection()).toList();
- getList().getTable().deselectAll();
-
- getList().setItemCount(contentProvider.getNumberOfElements());
- getList().refresh();
-
- if (getList().getTable().getItemCount() > 0) {
- // preserve previous selection
- if ( lastRefreshSelection != null
- && lastRefreshSelection.size() > 0) {
- getList().setSelection(new StructuredSelection(
- lastRefreshSelection));
- } else {
-
- getList().getTable().setSelection(0);
- getList().getTable().notifyListeners(SWT.Selection, new Event());
- }
- if ( super.getButton(IDialogConstants.OK_ID) != null){
- super.getButton(IDialogConstants.OK_ID).setEnabled(true);
- }
+ getList().setItemCount(contentProvider.getNumberOfElements());
+ getList().refresh();
+
+ if (getList().getTable().getItemCount() > 0) {
+ // preserve previous selection
+ if ( lastRefreshSelection != null
+ && lastRefreshSelection.size() > 0) {
+ getList().setSelection(new StructuredSelection(
+ lastRefreshSelection));
} else {
- getList().setSelection(StructuredSelection.EMPTY);
- }
+ getList().getTable().setSelection(0);
+ getList().getTable().notifyListeners(SWT.Selection, new Event());
+ }
+ if ( super.getButton(IDialogConstants.OK_ID) != null){
+ super.getButton(IDialogConstants.OK_ID).setEnabled(true);
+ }
+ } else {
+ getList().setSelection(StructuredSelection.EMPTY);
}
}
+ }
+
+ /**
+ * A job responsible for computing filtered items list presented using
+ * RefreshJob
.
+ *
+ * @see FilteredItemsSelectionDialog.RefreshJob
+ */
+ private class RefreshCacheJob extends Job {
+
+ public RefreshCacheJob() {
+ super(WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob);
+ setSystem(true);
+ }
/**
- * A job responsible for computing filtered items list presented using
- * RefreshJob
.
- *
- * @see FilteredItemsSelectionDialog.RefreshJob
- *
+ * Stops the job and all sub-jobs.
*/
- private class RefreshCacheJob extends Job {
+ public void cancelAll() {
+ cancel();
+ }
- public RefreshCacheJob() {
- super(
- WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob);
- setSystem(true);
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return new Status(IStatus.CANCEL, WorkbenchPlugin.PI_WORKBENCH,
+ IStatus.CANCEL, EMPTY_STRING, null);
}
- /**
- * Stops the job and all sub-jobs.
- */
- public void cancelAll() {
- cancel();
+ if (SearchDialog.this != null) {
+ SearchDialog.this.fillContentProvider(monitor);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return new Status(IStatus.CANCEL, WorkbenchPlugin.PI_WORKBENCH,
- IStatus.CANCEL, EMPTY_STRING, null);
- }
-
- if (SearchDialog.this != null) {
- SearchDialog.this.fillContentProvider(monitor);
- }
-
- return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,
- EMPTY_STRING, null);
-
- }
+ return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK,
+ EMPTY_STRING, null);
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.jobs.Job#canceling()
- */
- @Override
- protected void canceling() {
- super.canceling();
- }
+ }
+ @Override
+ protected void canceling() {
+ super.canceling();
}
- private class ItemsListLabelProvider extends StyledCellLabelProvider
+ }
+
+ private class ItemsListLabelProvider extends StyledCellLabelProvider
implements ILabelProviderListener {
private ILabelProvider provider;
- /**
- * Creates a new instance of the class.
- *
- * @param provider
- * the label provider for all items, not null
- * @param selectionDecorator
- * the decorator for selected items, can be null
- */
- public ItemsListLabelProvider(ILabelProvider provider) {
- Assert.isNotNull(provider);
- this.provider = provider;
- this.provider.addListener(this);
- }
-
- /**
- * Sets new label provider.
- *
- * @param newProvider
- * new label provider for items in the list, not
- * null
- */
- public void setProvider(ILabelProvider newProvider) {
- Assert.isNotNull(newProvider);
- provider.removeListener(this);
- provider.dispose();
- provider = newProvider;
-
- if (provider != null) {
- provider.addListener(this);
+ /**
+ * Creates a new instance of the class.
+ *
+ * @param provider
+ * the label provider for all items, not null
+ * @param selectionDecorator
+ * the decorator for selected items, can be null
+ */
+ public ItemsListLabelProvider(ILabelProvider provider) {
+ Assert.isNotNull(provider);
+ this.provider = provider;
+ this.provider.addListener(this);
}
- }
-
+ /**
+ * Sets new label provider.
+ *
+ * @param newProvider
+ * new label provider for items in the list, not
+ * null
+ */
+ public void setProvider(ILabelProvider newProvider) {
+ Assert.isNotNull(newProvider);
+ provider.removeListener(this);
+ provider.dispose();
+ provider = newProvider;
+
+ if (provider != null) {
+ provider.addListener(this);
+ }
+ }
- private boolean isSelected(Object element) {
- if (element != null && getCurrentSelection() != null) {
- if (element.equals(getCurrentSelection())) {
- return true;
+ private boolean isSelected(Object element) {
+ if (element != null && getCurrentSelection() != null) {
+ if (element.equals(getCurrentSelection())) {
+ return true;
+ }
}
+ return false;
}
- return false;
- }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- */
- private String getText(Object element) {
- if (element instanceof ItemsListSeparator) {
- return getSeparatorLabel(((ItemsListSeparator) element)
- .getName());
+ private String getText(Object element) {
+ if (element instanceof ItemsListSeparator) {
+ return getSeparatorLabel(((ItemsListSeparator) element)
+ .getName());
+ }
+ String str = provider.getText(element);
+ return str;
}
- String str = provider.getText(element);
- return str;
- }
- private StyledString getStyledText(Object element,
- IStyledLabelProvider provider) {
- StyledString string = provider.getStyledText(element);
+ private StyledString getStyledText(Object element,
+ IStyledLabelProvider provider) {
+ StyledString string = provider.getStyledText(element);
- return string;
- }
+ return string;
+ }
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
+ @Override
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
- if (!(element instanceof ItemsListSeparator)
- && provider instanceof IStyledLabelProvider) {
- IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) provider;
- StyledString styledString = getStyledText(element,
- styledLabelProvider);
+ if (!(element instanceof ItemsListSeparator)
+ && provider instanceof IStyledLabelProvider) {
+ IStyledLabelProvider styledLabelProvider = (IStyledLabelProvider) provider;
+ StyledString styledString = getStyledText(element,
+ styledLabelProvider);
- cell.setText(styledString.getString());
- cell.setStyleRanges(styledString.getStyleRanges());
- cell.setImage(styledLabelProvider.getImage(element));
- } else {
- cell.setText(getText(element));
+ cell.setText(styledString.getString());
+ cell.setStyleRanges(styledString.getStyleRanges());
+ cell.setImage(styledLabelProvider.getImage(element));
+ } else {
+ cell.setText(getText(element));
+
+ }
+ cell.setFont(getFont(element));
+ cell.setForeground(getForeground(element));
+ cell.setBackground(getBackground(element));
+ super.update(cell);
}
- cell.setFont(getFont(element));
- cell.setForeground(getForeground(element));
- cell.setBackground(getBackground(element));
- super.update(cell);
- }
+ private String getSeparatorLabel(String separatorLabel) {
+ Rectangle rect = getList().getTable().getBounds();
- private String getSeparatorLabel(String separatorLabel) {
- Rectangle rect = getList().getTable().getBounds();
+ int borderWidth = getList().getTable().computeTrim(0, 0, 0, 0).width;
- int borderWidth = getList().getTable().computeTrim(0, 0, 0, 0).width;
+ int imageWidth = WorkbenchImages.getImage(
+ IWorkbenchGraphicConstants.IMG_OBJ_SEPARATOR).getBounds().width;
- int imageWidth = WorkbenchImages.getImage(
- IWorkbenchGraphicConstants.IMG_OBJ_SEPARATOR).getBounds().width;
+ int width = rect.width - borderWidth - imageWidth;
- int width = rect.width - borderWidth - imageWidth;
+ GC gc = new GC(getList().getTable());
+ gc.setFont(getList().getTable().getFont());
- GC gc = new GC(getList().getTable());
- gc.setFont(getList().getTable().getFont());
+ int fSeparatorWidth = gc.getAdvanceWidth('-');
+ int fMessageLength = gc.textExtent(separatorLabel).x;
- int fSeparatorWidth = gc.getAdvanceWidth('-');
- int fMessageLength = gc.textExtent(separatorLabel).x;
+ gc.dispose();
- gc.dispose();
+ StringBuffer dashes = new StringBuffer();
+ int chars = (((width - fMessageLength) / fSeparatorWidth) / 2) - 2;
+ for (int i = 0; i < chars; i++) {
+ dashes.append('-');
+ }
- StringBuffer dashes = new StringBuffer();
- int chars = (((width - fMessageLength) / fSeparatorWidth) / 2) - 2;
- for (int i = 0; i < chars; i++) {
- dashes.append('-');
+ StringBuffer result = new StringBuffer();
+ result.append(dashes);
+ result.append(" " + separatorLabel + " "); //$NON-NLS-1$//$NON-NLS-2$
+ result.append(dashes);
+ return result.toString().trim();
}
- StringBuffer result = new StringBuffer();
- result.append(dashes);
- result.append(" " + separatorLabel + " "); //$NON-NLS-1$//$NON-NLS-2$
- result.append(dashes);
- return result.toString().trim();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
- */
- @Override
- public void addListener(ILabelProviderListener listener) {
- listeners.add(listener);
- }
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ listeners.add(listener);
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
- */
- @Override
- public void dispose() {
- provider.removeListener(this);
- provider.dispose();
- super.dispose();
- }
+ @Override
+ public void dispose() {
+ provider.removeListener(this);
+ provider.dispose();
+ super.dispose();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
- * java.lang.String)
- */
- @Override
- public boolean isLabelProperty(Object element, String property) {
- if (provider.isLabelProperty(element, property)) {
- return true;
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ if (provider.isLabelProperty(element, property)) {
+ return true;
+ }
+ return false;
}
- return false;
- }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
- */
- @Override
- public void removeListener(ILabelProviderListener listener) {
- listeners.remove(listener);
- }
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ listeners.remove(listener);
+ }
- private Color getBackground(Object element) {
- if (element instanceof ItemsListSeparator) {
+ private Color getBackground(Object element) {
+ if (element instanceof ItemsListSeparator) {
+ return null;
+ }
+ if (provider instanceof IColorProvider) {
+ return ((IColorProvider) provider).getBackground(element);
+ }
return null;
}
- if (provider instanceof IColorProvider) {
- return ((IColorProvider) provider).getBackground(element);
- }
- return null;
- }
- private Color getForeground(Object element) {
- if (element instanceof ItemsListSeparator) {
- return Display.getCurrent().getSystemColor(
- SWT.COLOR_WIDGET_NORMAL_SHADOW);
- }
- if (provider instanceof IColorProvider) {
- return ((IColorProvider) provider).getForeground(element);
+ private Color getForeground(Object element) {
+ if (element instanceof ItemsListSeparator) {
+ return Display.getCurrent().getSystemColor(
+ SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ }
+ if (provider instanceof IColorProvider) {
+ return ((IColorProvider) provider).getForeground(element);
+ }
+ return null;
}
- return null;
- }
- private Font getFont(Object element) {
- if (element instanceof ItemsListSeparator) {
+ private Font getFont(Object element) {
+ if (element instanceof ItemsListSeparator) {
+ return null;
+ }
+ if (provider instanceof IFontProvider) {
+ return ((IFontProvider) provider).getFont(element);
+ }
return null;
}
- if (provider instanceof IFontProvider) {
- return ((IFontProvider) provider).getFont(element);
- }
- return null;
- }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ILabelProviderListener#labelProviderChanged(org.eclipse.jface.viewers.LabelProviderChangedEvent)
- */
- @Override
- public void labelProviderChanged(LabelProviderChangedEvent event) {
- Object[] l = listeners.getListeners();
- for (int i = 0; i < listeners.size(); i++) {
- ((ILabelProviderListener) l[i]).labelProviderChanged(event);
+ @Override
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ Object[] l = listeners.getListeners();
+ for (int i = 0; i < listeners.size(); i++) {
+ ((ILabelProviderListener) l[i]).labelProviderChanged(event);
+ }
}
}
-}
@Override
protected Point getInitialSize() {
return new Point(593, 399);
}
-
-
-
-}
-
-
+}
\ No newline at end of file