use of org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog in project whole by wholeplatform.
the class ReplaceWithClassNameAction method run.
@Override
public void run() {
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
FilteredItemsSelectionDialog dialog = new OpenTypeSelectionDialog(shell, true, PlatformUI.getWorkbench().getProgressService(), null, IJavaSearchConstants.TYPE);
dialog.setTitle("Select a class");
dialog.setMessage("Choose a class or a compilation unit");
dialog.setInitialPattern(StringUtils.toSimpleName(className));
if (dialog.open() != IDialogConstants.OK_ID)
return;
IType primaryType = (IType) dialog.getResult()[0];
if (primaryType == null)
return;
className = primaryType.getFullyQualifiedName();
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
IEntity replacement = GenericEntityFactory.instance.create(ed, className);
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("replace with class name");
mtc.begin();
focusEntity.wGetParent().wSet(focusEntity, replacement);
mtc.commit();
if (mtc.canUndo()) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(mtc);
}
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
}
}
Aggregations