Example usage for com.intellij.openapi.ui Messages showDialog

List of usage examples for com.intellij.openapi.ui Messages showDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showDialog.

Prototype

public static int showDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title,
        String @NotNull [] options, int defaultOptionIndex, @Nullable Icon icon) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.mediaworx.intellij.opencmsplugin.actions.importmodule.OpenCmsImportAction.java

License:Open Source License

/**
 * Triggers the import of modules depending on the menu entry the user chose. Which modules are to
 * be imported is determined by calling the abstract method
 * {@link #getModuleFileList(AnActionEvent)} that's implemented by subclasses.
 * For the moduel import the IDEConnectorClient is used that is provided as a separate library.
 * @param event the action event, provided by IntelliJ
 *//*from   w w w.ja v  a  2s. c  o m*/
@Override
public void actionPerformed(AnActionEvent event) {
    LOG.info("actionPerformed - event: " + event);
    super.actionPerformed(event);

    if (config.isPluginConnectorServiceEnabled() && StringUtils.isNotBlank(config.getConnectorServiceUrl())) {
        final List<File> moduleFiles = getModuleFileList(event);

        final OpenCmsToolWindowConsole console = plugin.getConsole();

        final List<ModuleImportInfo> moduleImportInfos = new ArrayList<>();
        for (File moduleFile : moduleFiles) {
            OpenCmsModule ocmsModule = plugin.getOpenCmsModules().getModuleForFile(moduleFile);
            if (ocmsModule == null || !ocmsModule.isFileModuleRoot(moduleFile)) {
                continue;
            }
            String moduleZipPath = ocmsModule.findNewestModuleZipPath();
            if (StringUtils.isNotBlank(moduleZipPath)) {
                ModuleImportInfo importInfo = new ModuleImportInfo();
                importInfo.setModuleZipPath(moduleZipPath);
                importInfo.setImportSiteRoot(ocmsModule.getExportImportSiteRoot());
                moduleImportInfos.add(importInfo);
            } else {
                console.error("No module zip for module " + ocmsModule.getModuleName()
                        + " found in target folder " + config.getModuleZipTargetFolderPath());
            }
        }
        if (moduleImportInfos.size() > 0) {

            plugin.showConsole();
            clearConsole();

            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    try {
                        connectorClient.login(config.getUsername(), config.getPassword());
                        connectorClient.importModules(moduleImportInfos, new ConsolePrinter(console));
                        connectorClient.logout();
                    } catch (Exception e) {
                        UIUtil.invokeLaterIfNeeded(new Runnable() {
                            @Override
                            public void run() {
                                Messages.showDialog(
                                        "This function is only available if the IDE Connector module 1.5 is installed and configured in OpenCms and if OpenCms is running. Consult the Plugin Wiki for mor information.",
                                        "Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
                            }
                        });
                    }
                }
            };
            Thread thread = new Thread(runnable);
            thread.start();
        }
    } else {
        Messages.showDialog(
                "This function is only available if the IDE Connector Service URL is provided and the Connector Service is activated (IDE connector module 1.5 required).",
                "Error - Please Check Your OpenCms Plugin Configuration.", new String[] { "Ok" }, 0,
                Messages.getErrorIcon());
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.listeners.OpenCmsModuleFileChangeListener.java

License:Open Source License

/**
 * Handler method that is called after the file change has been executed by IntelliJ, handles file deletes, moves
 * and renames: Is used to present a dialog asking the user if the file change should be reflected in the OpenCms
 * VFS as well.// www  .ja va2 s . co  m
 * @param vFileEvents   List of file events, provided by IntelliJ
 */
public void after(@NotNull List<? extends VFileEvent> vFileEvents) {

    if (config == null || !config.isOpenCmsPluginEnabled()) {
        return;
    }

    ToolWindow toolWindow = plugin.getToolWindow();
    if (toolWindow == null) {
        return;
    }

    console = plugin.getConsole();

    try {
        for (VFileEvent event : vFileEvents) {
            handleFileEvent(event);
        }
        if (getNumAffected() > 0) {
            boolean wasExecuted = handleAffectedFiles();

            // Publish the affected VFS resources (if publish is enabled)
            if (wasExecuted && config.isPluginConnectorEnabled()
                    && config.getAutoPublishMode() != AutoPublishMode.OFF) {
                publishAffectedVfsResources();
            }
        }
    } catch (CmsConnectionException e) {
        Messages.showDialog("Error syncing file deletion/move/rename to OpenCms:\n" + e.getMessage(), "Error",
                new String[] { "Ok" }, 0, Messages.getErrorIcon());
    } finally {
        vfsFilesToBeDeleted.clear();
        vfsFilesToBeMoved.clear();
        vfsFilesToBeRenamed.clear();
        deletedFileModuleLookup.clear();
        refreshFiles.clear();
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.listeners.OpenCmsModuleFileChangeListener.java

License:Open Source License

/**
 * Presents a dialog asking the user if files are to be moved in the VFS and handles the moves if the user
 * chooses to do so//from   w w w .  jav  a 2  s.  c  o  m
 * @return  <code>true</code> if the user elected to move files, <code>false</code> if the user cancelled the
 *          move
 * @throws CmsConnectionException if the connection to OpenCms failed
 */
private boolean moveFiles() throws CmsConnectionException {
    StringBuilder msg = new StringBuilder(
            "Do you want to move the following files/folders in the OpenCms VFS as well?");
    for (VfsFileMoveInfo vfsFileToBeMoved : vfsFilesToBeMoved) {
        msg.append("\n").append(vfsFileToBeMoved.oldVfsPath);
    }

    int dlgStatus = Messages.showOkCancelDialog(msg.toString(), "Move Files/Folders?",
            Messages.getQuestionIcon());

    if (dlgStatus == 0) {
        console.clear();
        plugin.showConsole();
        for (VfsFileMoveInfo moveInfo : vfsFilesToBeMoved) {
            try {
                console.info("MOVE: " + moveInfo.oldVfsPath + " to " + moveInfo.newParentPath);
                Folder oldParent = (Folder) getVfsAdapter().getVfsObject(moveInfo.oldParentPath);
                Folder newParent = (Folder) getVfsAdapter().getVfsObject(moveInfo.newParentPath);
                if (newParent == null) {
                    newParent = getVfsAdapter().createFolder(moveInfo.newParentPath);
                }
                FileableCmisObject resource = (FileableCmisObject) getVfsAdapter()
                        .getVfsObject(moveInfo.oldVfsPath);
                resource.move(oldParent, newParent);

                // handle export points
                handleExportPointsForMovedResources(moveInfo.oldVfsPath, moveInfo.newVfsPath,
                        moveInfo.newIdeaVFile.getPath());

                // handle meta data files
                handleMetaDataForMovedResources(moveInfo.oldOcmsModule, moveInfo.newOcmsModule,
                        moveInfo.oldVfsPath, moveInfo.newVfsPath, moveInfo.newIdeaVFile.isDirectory());
            } catch (CmsPermissionDeniedException e) {
                Messages.showDialog("Error moving files/folders." + e.getMessage(), "Error",
                        new String[] { "Ok" }, 0, Messages.getErrorIcon());
            }
        }
        return true;
    }
    return false;
}

From source file:com.mediaworx.intellij.opencmsplugin.listeners.OpenCmsModuleFileChangeListener.java

License:Open Source License

/**
 * Presents a dialog asking the user if files are to be renamed in the VFS and handles the renames if the user
 * chooses to do so/*  w w w .j  a v  a2  s. co m*/
 * @return  <code>true</code> if the user elected to rename files, <code>false</code> if the user cancelled the
 *          rename
 * @throws CmsConnectionException if the connection to OpenCms failed
 */
private boolean renameFiles() throws CmsConnectionException {
    StringBuilder msg = new StringBuilder(
            "Do you want to rename the following files/folders in the OpenCms VFS as well?");
    for (VfsFileRenameInfo vfsFileToBeRenamed : vfsFilesToBeRenamed) {
        msg.append("\n").append(vfsFileToBeRenamed.oldVfsPath).append(" -> ")
                .append(vfsFileToBeRenamed.newName);
    }

    int dlgStatus = Messages.showOkCancelDialog(msg.toString(), "Move Files/Folders?",
            Messages.getQuestionIcon());

    if (dlgStatus == 0) {
        console.clear();
        plugin.showConsole();
        for (VfsFileRenameInfo renameInfo : vfsFilesToBeRenamed) {
            console.info("RENAME: " + renameInfo.oldVfsPath + " to " + renameInfo.newName);
            try {
                CmisObject file = getVfsAdapter().getVfsObject(renameInfo.oldVfsPath);
                if (file == null) {
                    LOG.warn("Error renaming " + renameInfo.oldVfsPath
                            + ": the resource could not be loaded through CMIS");
                    continue;
                }
                HashMap<String, Object> properties = new HashMap<String, Object>();
                properties.put(PropertyIds.NAME, renameInfo.newName);
                file.updateProperties(properties);

                // handle export points
                handleExportPointsForMovedResources(renameInfo.oldVfsPath, renameInfo.newVfsPath,
                        renameInfo.newIdeaVFile.getPath());

                // handle meta data files
                handleMetaDataForMovedResources(renameInfo.ocmsModule, renameInfo.ocmsModule,
                        renameInfo.oldVfsPath, renameInfo.newVfsPath, renameInfo.newIdeaVFile.isDirectory());
            } catch (CmsPermissionDeniedException e) {
                LOG.warn("Exception moving files - permission denied", e);
                Messages.showDialog("Error moving files/folders. " + e.getMessage(), "Error",
                        new String[] { "Ok" }, 0, Messages.getErrorIcon());
            }
        }
        return true;
    }
    return false;
}

From source file:com.mediaworx.intellij.opencmsplugin.listeners.OpenCmsModuleFileChangeListener.java

License:Open Source License

/**
 * Starts an OpenCms direct publish session for resources that were affected by the deletes/moves/renames
 *//*w  ww.  j  a va 2  s. c  om*/
private void publishAffectedVfsResources() {
    ArrayList<String> affectedResourcePaths = new ArrayList<String>(getNumAffected());
    for (VfsFileDeleteInfo deletedInfo : vfsFilesToBeDeleted) {
        affectedResourcePaths.add(deletedInfo.vfsPath);
    }
    for (VfsFileMoveInfo moveInfo : vfsFilesToBeMoved) {
        affectedResourcePaths.add(moveInfo.newVfsPath);
    }
    for (VfsFileRenameInfo renameInfo : vfsFilesToBeRenamed) {
        affectedResourcePaths.add(renameInfo.newVfsPath);
    }
    if (affectedResourcePaths.size() > 0) {
        try {
            plugin.getPluginConnector().publishResources(affectedResourcePaths, false);
            console.info("PUBLISH: A direct publish session was started successfully");
        } catch (OpenCmsConnectorException e) {
            console.error(e.getMessage());
        } catch (IOException e) {
            LOG.warn("There was an exception while publishing resources after a file change event", e);
            Messages.showDialog("There was an Error during publish.\nIs OpenCms running?\n\n" + e.getMessage(),
                    "OpenCms Publish Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
        }
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.OpenCmsPlugin.java

License:Open Source License

public boolean checkWebappRootConfiguration(boolean showDialog) {
    boolean configOK = true;
    OpenCmsPluginConfigurationData config = getPluginConfiguration();
    if (config != null && config.isOpenCmsPluginEnabled()) {
        File file = new File(config.getWebappRoot());
        // show an error message if the webapp root folder was not found
        if (!file.exists()) {
            configOK = false;/* ww w  .ja v a2 s . com*/
            if (showDialog) {
                Messages.showDialog(
                        "The Webapp Root was not found.\nPlease check the OpenCms Webapp Root in the OpenCms Plugin settings.",
                        "OpenCms Plugin - Configuration Error", new String[] { "Ok" }, 0,
                        Messages.getErrorIcon());
            }
        } else {
            // check if the OpenCms configuration path exists
            file = new File(config.getWebappRoot() + OpenCmsConfiguration.CONFIGPATH);
            if (!file.exists()) {
                configOK = false;
                if (showDialog) {
                    Messages.showDialog(
                            "The OpenCms configuration was not found.\nPlease check the OpenCms Webapp Root in the OpenCms Plugin settings.",
                            "Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
                }
            }
        }
    }
    return configOK;
}

From source file:com.mediaworx.intellij.opencmsplugin.sync.OpenCmsSyncer.java

License:Open Source License

/**
 * Analyzes the given file list using the {@link SyncFileAnalyzer} and triggers the sync to/from OpenCms using
 * the {@link SyncJob}//  ww  w . j  ava2s .c om
 * @param syncFiles list of local files (and folders) that are used as starting point for the sync
 */
public void syncFiles(List<File> syncFiles) {

    SyncFileAnalyzer analyzer;

    try {
        analyzer = new SyncFileAnalyzer(plugin, syncFiles, pullMetaDataOnly);
    } catch (CmsConnectionException e) {
        Messages.showDialog(e.getMessage(), "Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
        return;
    }

    ProgressManager.getInstance().runProcessWithProgressSynchronously(analyzer,
            "Analyzing local and VFS syncFiles and folders ...", true, plugin.getProject());

    if (!analyzer.isExecuteSync()) {
        return;
    }

    int numSyncEntities = analyzer.getSyncList().size();

    boolean proceed = numSyncEntities > 0;
    LOG.info("proceed? " + proceed);

    StringBuilder message = new StringBuilder();
    if (analyzer.hasWarnings()) {
        message.append("Infos/Warnings during file analysis:\n").append(analyzer.getWarnings().append("\n"));
    }
    if (proceed) {
        SyncJob syncJob = new SyncJob(plugin, analyzer.getSyncList());
        if (showConfirmDialog && !pullMetaDataOnly
                && ((numSyncEntities == 1 && message.length() > 0) || numSyncEntities > 1)) {
            assembleConfirmMessage(message, syncJob.getSyncList());
            int dlgStatus = Messages.showOkCancelDialog(plugin.getProject(), message.toString(),
                    "Start OpenCms VFS Sync?", Messages.getQuestionIcon());
            proceed = dlgStatus == 0;
        }
        if (proceed) {
            plugin.showConsole();
            new Thread(syncJob).start();
        }
    } else {
        message.append("Nothing to sync");
        Messages.showMessageDialog(message.toString(), "OpenCms VFS Sync", Messages.getInformationIcon());
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.sync.SyncJob.java

License:Open Source License

private void pullModuleResourcePathAncestorMetaInfos() {
    List<OpenCmsModuleResource> resourcePathParents = new ArrayList<OpenCmsModuleResource>();
    for (OpenCmsModule ocmsModule : syncList.getOcmsModules()) {
        Set<String> handledParents = new HashSet<String>();
        for (String resourcePath : ocmsModule.getModuleResources()) {
            addParentFolderToResourcePaths(resourcePath, ocmsModule, resourcePathParents, handledParents);
        }//from  w  w  w  . ja  v  a  2s.  c o  m
    }

    if (resourcePathParents.size() > 0) {
        try {
            Map<String, String> resourceInfos = plugin.getPluginConnector()
                    .getModuleResourceInfos(resourcePathParents);

            for (OpenCmsModuleResource resourceParent : resourcePathParents) {
                SyncFolder syncFolder = new SyncFolder(resourceParent.getOpenCmsModule(),
                        resourceParent.getResourcePath(), null, null, SyncAction.PULL, false);
                doMetaInfoHandling(console, resourceInfos, syncFolder);
            }
        } catch (OpenCmsConnectorException e) {
            console.error(e.getMessage());
        } catch (IOException e) {
            Messages.showDialog(
                    "There was an error pulling the meta information for module resource ancestor folders from OpenCms.\nIs the connector module installed?",
                    "Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
            LOG.warn("There was an Exception pulling the meta information for module resource ancestor folders",
                    e);
        }
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.sync.SyncJob.java

License:Open Source License

private void pullModuleManifests() {

    // collect the module names in a List
    List<String> moduleNames = new ArrayList<String>(syncList.getOcmsModules().size());
    for (OpenCmsModule ocmsModule : syncList.getOcmsModules()) {
        moduleNames.add(ocmsModule.getModuleName());
    }/*from ww  w . jav  a 2  s .c o  m*/

    if (moduleNames.size() > 0) {
        try {
            // pull the module manifests
            Map<String, String> manifestInfos = plugin.getPluginConnector().getModuleManifests(moduleNames);

            for (OpenCmsModule ocmsModule : syncList.getOcmsModules()) {
                if (manifestInfos.containsKey(ocmsModule.getModuleName())) {
                    // put the manifest to a file
                    String manifestPath = ocmsModule.getManifestRoot() + "/manifest_stub.xml";
                    String manifest = manifestInfos.get(ocmsModule.getModuleName());
                    if (ocmsModule.isSetSpecificModuleVersionEnabled()
                            && StringUtils.isNotEmpty(ocmsModule.getModuleVersion())) {
                        manifest = manifest.replaceFirst("<version>[^<]*</version>", "<version>"
                                + Matcher.quoteReplacement(ocmsModule.getModuleVersion()) + " </version>");
                    }
                    manifest = PluginTools.ensureUnixNewline(manifest) + "\n";
                    FileUtils.writeStringToFile(new File(manifestPath), manifest, Charset.forName("UTF-8"));
                    console.info("PULL: " + manifestPath + " pulled from OpenCms");
                } else {
                    LOG.warn("No manifest found for module " + ocmsModule.getModuleName());
                }
            }
        } catch (OpenCmsConnectorException e) {
            console.error(e.getMessage());
        } catch (IOException e) {
            Messages.showDialog(
                    "There was an error pulling the module manifest files from OpenCms.\nIs the connector module installed?",
                    "Error", new String[] { "Ok" }, 0, Messages.getErrorIcon());
            LOG.warn("There was an Exception pulling the module manifests", e);
        }
    }
}

From source file:com.mediaworx.intellij.opencmsplugin.sync.VfsAdapter.java

License:Open Source License

/**
 * retrieves (pulls) the VFS resource at the given path
 * @param path  path of the resource to be pulled
 * @return  the VFS resource//  w w  w.ja va  2 s .c  o m
 * @throws CmsPermissionDeniedException
 */
public CmisObject getVfsObject(String path) throws CmsPermissionDeniedException {
    if (!connected) {
        LOG.warn("not connected");
        return null;
    }
    path = PluginTools.ensureUnixPath(path);
    try {
        return session.getObjectByPath(path);
    } catch (CmisObjectNotFoundException e) {
        return null;
    } catch (CmisPermissionDeniedException e) {
        LOG.warn("Permission denied, can't access " + path, e);
        throw new CmsPermissionDeniedException("Permission denied, can't access " + path, e);
    } catch (CmisConnectionException e) {
        Messages.showDialog("Error connecting to the VFS" + e.getMessage() + "\nIs OpenCms running?", "Error",
                new String[] { "Ok" }, 0, Messages.getErrorIcon());
        LOG.warn("Error connecting to the VFS", e);
        connected = false;
        return null;
    }
}