Search in sources :

Example 66 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method createUIComponents.

private void createUIComponents() {
    DefaultTableModel tableModel = new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tableModel.addColumn("Name");
    tableModel.addColumn("JDK");
    tableModel.addColumn("Web container");
    tableModel.addColumn("Resource group");
    table = new JBTable(tableModel);
    table.setRowSelectionAllowed(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting())
                return;
            //System.out.println("row : " + table.getValueAt(table.getSelectedRow(), 0).toString());
            fillAppServiceDetails();
        }
    });
    AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            refreshAppServices();
        }
    };
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(table).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            createAppService();
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            deleteAppService();
        }
    }).setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return table.getSelectedRow() != -1;
        }
    }).disableUpDownActions().addExtraActions(refreshAction);
    panelTable = tableToolbarDecorator.createPanel();
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) AnActionButtonUpdater(com.intellij.ui.AnActionButtonUpdater) DefaultTableModel(javax.swing.table.DefaultTableModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 67 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project Intellij-Plugin by getgauge.

the class Spectacle method notifyToInstall.

void notifyToInstall() {
    Notification notification = STANDARD_NOTIFICATION.createNotification("Error: Specification Preview", "Missing plugin: Spectacle. To install, run `gauge install spectacle` or click below", NotificationType.ERROR, null);
    notification.addAction(new NotificationAction("Install Spectacle") {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) {
            install();
            notification.expire();
        }
    });
    Notifications.Bus.notify(notification);
}
Also used : NotificationAction(com.intellij.notification.NotificationAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Notification(com.intellij.notification.Notification)

Example 68 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-plugins by JetBrains.

the class ResolveAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
    Project project = event.getProject();
    if (virtualFile == null || project == null)
        return;
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    if (document == null)
        return;
    FileDocumentManager.getInstance().saveAllDocuments();
    new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {

        private Map<Resource, List<Wire>> resolveResult;

        private String updatedText;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            File file = new File(virtualFile.getPath());
            try (Workspace workspace = Workspace.findWorkspace(file);
                Run run = Run.createRun(workspace, file);
                ProjectResolver projectResolver = new ProjectResolver(run)) {
                resolveResult = projectResolver.resolve();
                List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
                    Attrs attrs = new Attrs();
                    attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
                    return new VersionedClause(c.getBundleSymbolicName(), attrs);
                }).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
                BndEditModel editModel = new BndEditModel();
                IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
                editModel.loadFrom(bndDocument);
                editModel.setRunBundles(versionedClauses);
                editModel.saveChangesTo(bndDocument);
                updatedText = bndDocument.get();
            } catch (ProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                throw new WrappingException(e);
            }
            indicator.checkCanceled();
        }

        @Override
        public void onSuccess() {
            if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
                writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
            }
        }

        @Override
        public void onThrowable(@NotNull Throwable t) {
            Throwable cause = t instanceof WrappingException ? t.getCause() : t;
            LOG.warn("Resolution failed", cause);
            if (cause instanceof ResolutionException) {
                new ResolutionFailedDialog(project, (ResolutionException) cause).show();
            } else {
                OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction.writeCommandAction(com.intellij.openapi.command.WriteCommandAction.writeCommandAction) Constants(aQute.bnd.osgi.Constants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) Workspace(aQute.bnd.build.Workspace) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) BndEditModel(aQute.bnd.build.model.BndEditModel) OsmorcBundle(org.osmorc.i18n.OsmorcBundle) ProjectResolver(biz.aQute.resolve.ProjectResolver) FileModificationService(com.intellij.codeInsight.FileModificationService) Resource(org.osgi.resource.Resource) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Run(aQute.bnd.build.Run) Collectors(java.util.stream.Collectors) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) BndFileType(org.jetbrains.osgi.bnd.BndFileType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IDocument(aQute.bnd.properties.IDocument) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) Attrs(aQute.bnd.header.Attrs) Wire(org.osgi.resource.Wire) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ResolutionException(org.osgi.service.resolver.ResolutionException) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ProjectResolver(biz.aQute.resolve.ProjectResolver) Attrs(aQute.bnd.header.Attrs) Document(com.intellij.openapi.editor.Document) IDocument(aQute.bnd.properties.IDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ResolutionException(org.osgi.service.resolver.ResolutionException) ResolutionException(org.osgi.service.resolver.ResolutionException) Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IDocument(aQute.bnd.properties.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 69 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-leiningen-plugin by derkork.

the class LeiningenNode method executeAction.

public static void executeAction(final String actionId, final InputEvent e) {
    final ActionManager actionManager = ActionManager.getInstance();
    final AnAction action = actionManager.getAction(actionId);
    if (action != null) {
        final Presentation presentation = new Presentation();
        final AnActionEvent event = new AnActionEvent(e, DataManager.getInstance().getDataContext(e.getComponent()), "", presentation, actionManager, 0);
        action.update(event);
        if (presentation.isEnabled()) {
            action.actionPerformed(event);
        }
    }
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) Presentation(com.intellij.openapi.actionSystem.Presentation) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 70 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project ideavim by JetBrains.

the class KeyHandler method executeAction.

/**
   * Execute an action
   *
   * @param action  The action to execute
   * @param context The context to run it in
   */
public static boolean executeAction(@NotNull AnAction action, @NotNull DataContext context) {
    // Hopefully all the arguments are sufficient. So far they all seem to work OK.
    // We don't have a specific InputEvent so that is null
    // What is "place"? Leave it the empty string for now.
    // Is the template presentation sufficient?
    // What are the modifiers? Is zero OK?
    final AnActionEvent event = new AnActionEvent(null, context, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
    action.update(event);
    if (event.getPresentation().isEnabled()) {
        action.actionPerformed(event);
        return true;
    }
    return false;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6