-// $Id$
/**
* Copyright (C) 2016 EDIT
* European Distributed Institute of Taxonomy
this.refreshCacheJob.cancel();
this.refreshProgressMessageJob.cancel();
if (showViewHandler != null) {
- IHandlerService service = (IHandlerService) PlatformUI
+ IHandlerService service = PlatformUI
.getWorkbench().getService(IHandlerService.class);
service.deactivateHandler(showViewHandler);
showViewHandler.getHandler().dispose();
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
e.detail = SWT.TRAVERSE_NONE;
- list.getTable().setFocus();
+ getList().getTable().setFocus();
}
}
});
fillViewMenu(menuManager);
- IHandlerService service = (IHandlerService) PlatformUI.getWorkbench()
+ IHandlerService service = PlatformUI.getWorkbench()
.getService(IHandlerService.class);
IHandler handler = new AbstractHandler() {
@Override
* @since 3.5
*/
protected void fillContextMenu(IMenuManager menuManager) {
- List selectedElements= ((StructuredSelection)list.getSelection()).toList();
+ List selectedElements= ((StructuredSelection)getList().getSelection()).toList();
Object item= null;
}
});
- final Table table = list.getTable();
+ final Table table = getList().getTable();
Menu menu= contextMenuManager.createContextMenu(table);
table.setMenu(menu);
}
final Label listLabel = createLabels(content);
- list = new TableViewer(content, (multi ? SWT.MULTI : SWT.SINGLE)
- | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
- list.getTable().getAccessible().addAccessibleListener(
+ setList(new TableViewer(content, (multi ? SWT.MULTI : SWT.SINGLE)
+ | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL));
+ getList().getTable().getAccessible().addAccessibleListener(
new AccessibleAdapter() {
@Override
public void getName(AccessibleEvent e) {
}
}
});
- list.setContentProvider(contentProvider);
- list.setLabelProvider(getItemsListLabelProvider());
- list.setInput(new Object[0]);
- list.setItemCount(contentProvider.getNumberOfElements());
+ getList().setContentProvider(contentProvider);
+ getList().setLabelProvider(getItemsListLabelProvider());
+ getList().setInput(new Object[0]);
+ getList().setItemCount(contentProvider.getNumberOfElements());
gd = new GridData(GridData.FILL_BOTH);
- applyDialogFont(list.getTable());
- gd.heightHint= list.getTable().getItemHeight() * 15;
- list.getTable().setLayoutData(gd);
+ applyDialogFont(getList().getTable());
+ gd.heightHint= getList().getTable().getItemHeight() * 15;
+ getList().getTable().setLayoutData(gd);
createPopupMenu();
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN) {
- if (list.getTable().getItemCount() > 0) {
- list.getTable().setFocus();
+ if (getList().getTable().getItemCount() > 0) {
+ getList().getTable().setFocus();
}
}
}
});
- list.addSelectionChangedListener(new ISelectionChangedListener() {
+ getList().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
StructuredSelection selection = (StructuredSelection) event
}
});
- list.addDoubleClickListener(new IDoubleClickListener() {
+ getList().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
handleDoubleClick();
}
});
- list.getTable().addKeyListener(new KeyAdapter() {
+ getList().getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
- List selectedElements = ((StructuredSelection) list
+ List selectedElements = ((StructuredSelection) getList()
.getSelection()).toList();
Object item = null;
if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0
&& (e.stateMask & SWT.CTRL) != 0) {
- StructuredSelection selection = (StructuredSelection) list
+ StructuredSelection selection = (StructuredSelection) getList()
.getSelection();
if (selection.size() == 1) {
Object element = selection.getFirstElement();
- if (element.equals(list.getElementAt(0))) {
+ if (element.equals(getList().getElementAt(0))) {
pattern.setFocus();
}
- if (list.getElementAt(list.getTable()
+ if (getList().getElementAt(getList().getTable()
.getSelectionIndex() - 1) instanceof ItemsListSeparator) {
- list.getTable().setSelection(
- list.getTable().getSelectionIndex() - 1);
+ getList().getTable().setSelection(
+ getList().getTable().getSelectionIndex() - 1);
}
- list.getTable().notifyListeners(SWT.Selection,
+ getList().getTable().notifyListeners(SWT.Selection,
new Event());
}
&& (e.stateMask & SWT.SHIFT) != 0
&& (e.stateMask & SWT.CTRL) != 0) {
- if (list
- .getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) {
- list.getTable().setSelection(
- list.getTable().getSelectionIndex() + 1);
+ if (getList()
+ .getElementAt(getList().getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) {
+ getList().getTable().setSelection(
+ getList().getTable().getSelectionIndex() + 1);
}
- list.getTable().notifyListeners(SWT.Selection, new Event());
+ getList().getTable().notifyListeners(SWT.Selection, new Event());
}
}
IStatus status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID,
IStatus.OK, EMPTY_STRING, null);
- Object[] lastSelection = currentSelection;
+ Object[] lastSelection = getCurrentSelection();
- currentSelection = selection.toArray();
+ setCurrentSelection(selection.toArray());
if (selection.size() == 0) {
status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
if (lastSelection != null
&& getListSelectionLabelDecorator() != null) {
- list.update(lastSelection, null);
+ getList().update(lastSelection, null);
}
- currentSelection = null;
+ setCurrentSelection(null);
} else {
status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
if (lastSelection != null
&& getListSelectionLabelDecorator() != null) {
- list.update(lastSelection, null);
+ getList().update(lastSelection, null);
}
if (getListSelectionLabelDecorator() != null) {
- list.update(currentSelection, null);
+ getList().update(getCurrentSelection(), null);
}
}
* Refreshes the dialog - has to be called in UI thread.
*/
public void refresh() {
- if (list != null && !list.getTable().isDisposed()) {
+ if (getList() != null && !getList().getTable().isDisposed()) {
- List lastRefreshSelection = ((StructuredSelection) list
+ List lastRefreshSelection = ((StructuredSelection) getList()
.getSelection()).toList();
- list.getTable().deselectAll();
+ getList().getTable().deselectAll();
- list.setItemCount(contentProvider.getNumberOfElements());
- list.refresh();
+ getList().setItemCount(contentProvider.getNumberOfElements());
+ getList().refresh();
- if (list.getTable().getItemCount() > 0) {
+ if (getList().getTable().getItemCount() > 0) {
// preserve previous selection
if (refreshWithLastSelection && lastRefreshSelection != null
&& lastRefreshSelection.size() > 0) {
- list.setSelection(new StructuredSelection(
+ getList().setSelection(new StructuredSelection(
lastRefreshSelection));
} else {
refreshWithLastSelection = true;
- list.getTable().setSelection(0);
- list.getTable().notifyListeners(SWT.Selection, new Event());
+ getList().getTable().setSelection(0);
+ getList().getTable().notifyListeners(SWT.Selection, new Event());
}
} else {
- list.setSelection(StructuredSelection.EMPTY);
+ getList().setSelection(StructuredSelection.EMPTY);
}
}
* available
*/
public void reloadCache(boolean checkDuplicates, IProgressMonitor monitor) {
- if (list != null && !list.getTable().isDisposed()
+ if (getList() != null && !getList().getTable().isDisposed()
&& contentProvider != null) {
contentProvider.reloadCache(checkDuplicates, monitor);
}
@Override
protected void computeResult() {
- List selectedElements = ((StructuredSelection) list.getSelection())
+ List selectedElements = ((StructuredSelection) getList().getSelection())
.toList();
List objectsToReturn = new ArrayList();
*/
protected StructuredSelection getSelectedItems() {
- StructuredSelection selection = (StructuredSelection) list
+ StructuredSelection selection = (StructuredSelection) getList()
.getSelection();
List selectedItems = selection.toList();
*/
@Override
public void run() {
- List selectedElements = ((StructuredSelection) list.getSelection())
+ List selectedElements = ((StructuredSelection) getList().getSelection())
.toList();
removeSelectedItems(selectedElements);
}
}
- private static boolean showColoredLabels() {
+ protected static boolean showColoredLabels() {
return PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS);
}
}
private boolean isSelected(Object element) {
- if (element != null && currentSelection != null) {
- for (int i = 0; i < currentSelection.length; i++) {
- if (element.equals(currentSelection[i])) {
+ if (element != null && getCurrentSelection() != null) {
+ for (int i = 0; i < getCurrentSelection().length; i++) {
+ if (element.equals(getCurrentSelection()[i])) {
return true;
}
}
}
private String getSeparatorLabel(String separatorLabel) {
- Rectangle rect = list.getTable().getBounds();
+ Rectangle rect = getList().getTable().getBounds();
- int borderWidth = list.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 width = rect.width - borderWidth - imageWidth;
- GC gc = new GC(list.getTable());
- gc.setFont(list.getTable().getFont());
+ GC gc = new GC(getList().getTable());
+ gc.setFont(getList().getTable().getFont());
int fSeparatorWidth = gc.getAdvanceWidth('-');
int fMessageLength = gc.textExtent(separatorLabel).x;
* Used in ItemsListContentProvider, separates history and non-history
* items.
*/
- private class ItemsListSeparator {
+ protected class ItemsListSeparator {
private final String name;
@Override
public void updateElement(int index) {
- CdmFilteredItemsSelectionDialog.this.list.replace((lastFilteredItems
+ CdmFilteredItemsSelectionDialog.this.getList().replace((lastFilteredItems
.size() > index) ? lastFilteredItems.get(index) : null,
index);
// the TableViewer's root (the input) is treated as parent
- lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(),
+ lastFilteredItems = Arrays.asList(getFilteredItems(getList().getInput(),
monitor != null ? new SubProgressMonitor(monitor, 100)
: null));
if (filters != null && filteredElements != null) {
for (Iterator iter = filters.iterator(); iter.hasNext();) {
ViewerFilter f = (ViewerFilter) iter.next();
- filteredElements = f.filter(list, parent, filteredElements);
+ filteredElements = f.filter(getList(), parent, filteredElements);
monitor.worked(ticks);
}
}
*/
abstract protected void initModel();
+ public Object[] getCurrentSelection() {
+ return currentSelection;
+ }
+
+ public void setCurrentSelection(Object[] currentSelection) {
+ this.currentSelection = currentSelection;
+ }
+
+ public TableViewer getList() {
+ return list;
+ }
+
+ public void setList(TableViewer list) {
+ this.list = list;
+ }
+
}