/** * Ouvre un dialogue de recherche à partir d'un template. * * @param template Template. */ public static void openDialog(OpenDialogTemplate template) { String nature = template.getNature(); /* Charge les éléments à rechercher. */ Object[] items = template.getElements(); /* Cas sans élément à afficher. */ if (items.length == 0) { /* On affiche un message et on sort. */ MessageUtils.showNoElementMessage(nature); return; } /* Construit le dialogue. */ TwoPaneElementSelector dialog = createDialog(nature, items); /* Ouvre le dialogue. */ openDialog(dialog); }
private static <T extends Openable> TwoPaneElementSelector createDialog(String nature, Object[] items) { TwoPaneElementSelector dialog = new TwoPaneElementSelector(UiUtils.getShell(), new ElementLabelProvider<T>(), new QualifierLabelProvider<T>()); dialog.setSize(LIST_WIDTH, LIST_HEIGHT); dialog.setLowerListLabel("Selection"); dialog.setLowerListComparator((o1, o2) -> 0); dialog.setTitle(MessageFormat.format("Open {0}", nature)); dialog.setMessage(MessageFormat.format("Enter {0} prefix or pattern :", nature)); dialog.setElements(items); return dialog; }
@SuppressWarnings("unchecked") private static <T extends Openable> void openDialog(TwoPaneElementSelector dialog) { if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); if (result != null && result.length == 1) { /* Un objet est sélectionné : on navigue dessus. */ Object object = result[0]; T item = (T) object; UiUtils.navigateTo(item); } } }
/** * Opens a dialog which allows to select a key reference. * * @param keyReferences the array of key references * @return the selected key reference or <code>null</code> if canceled by the user */ private KeyReference select(final KeyReference[] keyReferences) { Arrays.sort(keyReferences); final int length= keyReferences.length; ILabelProvider labelProvider= new WorkbenchLabelProvider() { @Override public String decorateText(String input, Object element) { KeyReference keyRef= (KeyReference)element; IStorage storage= keyRef.storage; String name= storage.getName(); if (name == null) return input; int count= 0; for (int i= 0; i < length; i++) { if (keyReferences[i].storage.equals(storage)) count++; } if (count > 1) { Object[] args= new Object[] { BasicElementLabels.getResourceName(name), new Integer(count) }; name= Messages.format(PropertiesFileEditorMessages.OpenAction_SelectionDialog_elementLabelWithMatchCount, args); } return name; } }; TwoPaneElementSelector dialog= new TwoPaneElementSelector(fShell, labelProvider, new WorkbenchLabelProvider()); dialog.setLowerListLabel(PropertiesFileEditorMessages.OpenAction_SelectionDialog_details); dialog.setLowerListComparator(new Comparator<Object>() { public int compare(Object o1, Object o2) { return 0; // don't sort } }); dialog.setTitle(PropertiesFileEditorMessages.OpenAction_SelectionDialog_title); dialog.setMessage(PropertiesFileEditorMessages.OpenAction_SelectionDialog_message); dialog.setElements(keyReferences); if (dialog.open() == Window.OK) { Object[] result= dialog.getResult(); if (result != null && result.length == 1) return (KeyReference)result[0]; } return null; }