public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
e.detail = SWT.TRAVERSE_NONE;
- list.getTable().setFocus();
+ getList().getTable().setFocus();
}
}
});
* @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;
+ }
+
}
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
+import org.eclipse.ui.internal.WorkbenchImages;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IAgentService;
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.FilteredCdmResourceLabelProvider;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsListSeparator;
/**
* @author k.luther
throw new IllegalArgumentException("Could not determine the desired wizard.");
}
}
-
+ /**
+ *
+ * @return
+ */
+ @Override
+ protected ILabelProvider createListLabelProvider() {
+ return new FilteredCdmResourceAbbrevLabelProvider();
+ }
/**
* <p>select</p>
" supports cdmObject of type IIdentifiableEntity." +
" Please implement specific method in subclass.");
}
+
+
+
+ public class FilteredCdmResourceAbbrevLabelProvider extends LabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element == null) {
+ return null;
+ }
+ UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
+ String titleCache = uuidAndTitleCache.getTitleCache();
+ String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
+ abbrevTitleCache += " - " + titleCache;
+ if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
+ abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
+ }
+ return abbrevTitleCache;
+ }
+ };
}
package eu.etaxonomy.taxeditor.ui.dialog.selection;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
+import org.eclipse.ui.internal.WorkbenchImages;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IReferenceService;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsFilter;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsListSeparator;
public class NomenclaturalReferenceSelectionDialog extends
ReferenceSelectionDialog {
model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern);
}
+ /**
+ *
+ * @return
+ */
+ @Override
+ protected ILabelProvider createListLabelProvider() {
+ return new FilteredCdmResourceAbbrevLabelProvider();
+ }
+
/**
* <p>select</p>
*
};
}
+
+
+
+ public class FilteredCdmResourceAbbrevLabelProvider extends LabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element == null) {
+ return null;
+ }
+ UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
+ String titleCache = uuidAndTitleCache.getTitleCache();
+ String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
+ abbrevTitleCache += " - " + titleCache;
+ if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
+ abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
+ }
+ return abbrevTitleCache;
+ }
+ };
+
}