Example usage for com.intellij.openapi.ui DialogBuilder addAction

List of usage examples for com.intellij.openapi.ui DialogBuilder addAction

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogBuilder addAction.

Prototype

public void addAction(Action action) 

Source Link

Usage

From source file:com.machak.idea.plugins.actions.CopyHippoSharedFiles.java

License:Apache License

private void showProjectRootPopup(final String basePath, final File tomcatDirectory) {

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create project file:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("Following path will be used as project base:\n" + basePath));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*  ww  w .ja va2s.  c o m*/
        public void actionPerformed(final ActionEvent e) {
            // check if file exists and overwrite:
            final String filePath = tomcatDirectory.getAbsolutePath() + File.separator + "bin" + File.separator
                    + PROJECT_FILE;
            createAndWriteFile(filePath, basePath);

            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}

From source file:com.machak.idea.plugins.actions.CopyHippoSharedFiles.java

License:Apache License

private void processJars(final ApplicationComponent component, final String tomcatSharedDirectory,
        final File sharedDirectory, final Map<String, String> depMap) {

    final FilenameFilter fileFilter = createJarsFilter(component, depMap);
    final File[] jars = sharedDirectory.listFiles(fileFilter);
    if (!component.isShowDialog()) {
        for (File jar : jars) {
            deleteFile(jar);//from  w w  w .j a  va  2 s. com
        }
        copyJars(tomcatSharedDirectory, depMap);
        return;
    }
    final int length = jars.length;
    myFiles = new String[length];
    myCheckedMarks = new boolean[length];
    for (int i = 0; i < length; i++) {
        final File file = jars[i];
        myFiles[i] = file.getAbsolutePath();
        myCheckedMarks[i] = true;
    }

    final TableModel model = new MyTableModel();
    final JBTable myTable = new JBTable();
    myTable.setPreferredSize(new Dimension(700, 400));
    myTable.setModel(model);
    final TableColumnModel columnModel = myTable.getColumnModel();
    columnModel.getColumn(CHECKED_COLUMN).setCellRenderer(new BooleanTableCellRenderer());
    columnModel.getColumn(CHECKED_COLUMN).setPreferredWidth(40);
    columnModel.getColumn(FILE_COLUMN).setPreferredWidth(660);

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Files to delete");
    dialogBuilder.setCenterPanel(myTable);

    final Action deleteAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(final ActionEvent e) {
            final int length = model.getRowCount();
            for (int i = 0; i < length; i++) {
                final Boolean checked = (Boolean) model.getValueAt(i, CHECKED_COLUMN);
                if (checked) {
                    final File jar = jars[i];
                    deleteFile(jar);
                }
            }
            // do copy:
            copyJars(tomcatSharedDirectory, depMap);
            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
        }
    };
    deleteAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(deleteAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);

}

From source file:com.machak.idea.plugins.tomcat.actions.DeleteTomcatWebapps.java

License:Apache License

private void showDeletePopup(final String webappsDirectory, final File webappDir) {

    final String absolutePath = webappDir.getAbsolutePath();
    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create project file:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("All directories within: " + absolutePath + " will be deleted"));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*  ww w.  ja  v  a2s  .c om*/
        public void actionPerformed(final ActionEvent e) {
            deleteFiles(webappsDirectory, webappDir);
            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);

        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}

From source file:org.onehippo.intellij.freemarker.FreemarkerEditor.java

License:Apache License

private void showCreatePopup(final String fileName, final String templateRoot, final String content,
        final Session session) {

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create new  template node:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("Node doesn't exist, should we create one? (" + templateRoot + fileName + ')'));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*w  w  w .j a  v  a 2  s . c o m*/
        public void actionPerformed(final ActionEvent e) {

            try {
                final String root = templateRoot.endsWith("/")
                        ? templateRoot.substring(0, templateRoot.length() - 1)
                        : templateRoot;
                // check if site node exists:
                if (!session.nodeExists(root)) {
                    final String configRoot = "/hst:hst/hst:configurations/";
                    final String newSiteName = (root.substring(configRoot.length()))
                            .replaceAll("/hst:templates/|/hst:templates", "");
                    final Node configRootNode = session.getNode(configRoot);
                    final Node siteNode = configRootNode.addNode(newSiteName, "hst:configuration");
                    siteNode.addMixin("mix:referenceable");
                    siteNode.addMixin("mix:simpleVersionable");
                    siteNode.addMixin("mix:versionable");
                    final Node templateNode = siteNode.addNode("hst:templates", "hst:templates");
                    templateNode.addMixin("mix:referenceable");
                }

                final Node node = session.getNode(root);
                final String nodeName = fileName.startsWith(File.separator)
                        ? fileName.substring(1, fileName.length())
                        : fileName;
                final Node templateNode = node.addNode(nodeName, "hst:template");
                templateNode.setProperty("hst:script", content);
                session.save();
            } catch (RepositoryException e1) {
                FreemarkerEditor.error("Error writing template, " + e1.getMessage(), project);
                try {
                    if (session != null) {
                        session.refresh(false);
                    }
                } catch (RepositoryException e2) {
                    //
                }
            }

            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);

        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}

From source file:org.onehippo.intellij.groovy.GroovyEditor.java

License:Apache License

private void showCreatePopup(final String fileName, final String templateRoot, final String content,
        final Session session) {

    final DialogBuilder dialogBuilder = new DialogBuilder(project);
    dialogBuilder.setTitle("Create new  template node:");
    final JPanel simplePanel = new JPanel();
    simplePanel.add(new JLabel("Node doesn't exist, should we create one? (" + templateRoot + fileName + ')'));
    dialogBuilder.setCenterPanel(simplePanel);

    final Action acceptAction = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*from   w w  w.j a v  a 2 s  .com*/
        public void actionPerformed(final ActionEvent e) {

            try {
                final String root = templateRoot.endsWith("/")
                        ? templateRoot.substring(0, templateRoot.length() - 1)
                        : templateRoot;
                // check if site node exists:
                if (!session.nodeExists(root)) {
                    final String configRoot = "/hst:hst/hst:configurations/";
                    final String newSiteName = (root.substring(configRoot.length()))
                            .replaceAll("/hst:templates/|/hst:templates", "");
                    final Node configRootNode = session.getNode(configRoot);
                    final Node siteNode = configRootNode.addNode(newSiteName, "hst:configuration");
                    siteNode.addMixin("mix:referenceable");
                    siteNode.addMixin("mix:simpleVersionable");
                    siteNode.addMixin("mix:versionable");
                    final Node templateNode = siteNode.addNode("hst:templates", "hst:templates");
                    templateNode.addMixin("mix:referenceable");
                }

                final Node node = session.getNode(root);
                final String nodeName = fileName.startsWith(File.separator)
                        ? fileName.substring(1, fileName.length())
                        : fileName;
                final Node templateNode = node.addNode(nodeName, "hst:template");
                templateNode.setProperty("hst:script", content);
                session.save();
            } catch (RepositoryException e1) {
                GroovyEditor.error("Error writing template, " + e1.getMessage(), project);
                try {
                    session.refresh(false);
                } catch (RepositoryException e2) {
                    //
                }
            }

            dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);

        }
    };
    acceptAction.putValue(Action.NAME, "OK");
    dialogBuilder.addAction(acceptAction);

    dialogBuilder.addCancelAction();
    dialogBuilder.showModal(true);
}