Search in sources :

Example 1 with FilteredItemsSelectionDialog

use of org.eclipse.ui.dialogs.FilteredItemsSelectionDialog 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;
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) CommandStack(org.eclipse.gef.commands.CommandStack) Shell(org.eclipse.swt.widgets.Shell) IEntity(org.whole.lang.model.IEntity) OpenTypeSelectionDialog(org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog) FilteredItemsSelectionDialog(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IType(org.eclipse.jdt.core.IType)

Aggregations

ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IType (org.eclipse.jdt.core.IType)1 OpenTypeSelectionDialog (org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 FilteredItemsSelectionDialog (org.eclipse.ui.dialogs.FilteredItemsSelectionDialog)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 IEntity (org.whole.lang.model.IEntity)1 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)1 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)1