Example usage for java.lang.reflect InvocationTargetException InvocationTargetException

List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException InvocationTargetException.

Prototype

public InvocationTargetException(Throwable target) 

Source Link

Document

Constructs a InvocationTargetException with a target exception.

Usage

From source file:org.talend.repository.ui.login.LoginComposite.java

protected void populateProjectList() {
    Project[] projects = null;//from w w w  .  j a v a2s.  c  o m
    if (getConnection() != null) {
        String user2 = getConnection().getUser();
        String repositoryId2 = getConnection().getRepositoryId();
        String workSpace = getConnection().getWorkSpace();
        String name = getConnection().getName();
        if (user2 != null && !"".equals(user2) && repositoryId2 != null && !"".equals(repositoryId2) //$NON-NLS-1$//$NON-NLS-2$
                && workSpace != null && !"".equals(workSpace) && name != null && !"".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$
            boolean valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            if (valid && RepositoryConstants.REPOSITORY_REMOTE_ID.equals(repositoryId2)) {
                String url = getConnection().getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                valid = url != null || !"".equals(url); //$NON-NLS-1$
            }

            getConnection().setComplete(valid);
        }
    }

    if (getConnection() == null) {
        return;
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(
            RepositoryFactoryProvider.getRepositoriyById(getConnection().getRepositoryId()));
    if (!getConnection().isComplete()) {
        return;
    }

    boolean initialized = false;

    final String newLine = ":\n"; //$NON-NLS-1$
    try {
        try {
            repositoryFactory.checkAvailability();
        } catch (WarningException e) {
            String warnings = e.getMessage();
            if (warnings != null && !warnings.equals(lastWarnings)) {
                lastWarnings = warnings;
                final Shell shell = new Shell(getDisplay(), SWT.ON_TOP | SWT.TOP);
                MessageDialog.openWarning(shell, Messages.getString("LoginComposite.warningTitle"), warnings); //$NON-NLS-1$
            }
        }

        try {
            IRunnableWithProgress op = new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        ProxyRepositoryFactory.getInstance().initialize();
                    } catch (PersistenceException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            new ProgressMonitorDialog(getShell()).run(true, false, op);
        } catch (InvocationTargetException e) {
            throw (Exception) e.getTargetException();
        } catch (InterruptedException e) {
            //
        }

        initialized = true;
    } catch (Exception e) {
        projects = new Project[0];
        final Shell shell = new Shell(getDisplay(), SWT.ON_TOP | SWT.TOP);
        MessageDialog.openError(shell, Messages.getString("LoginComposite.warningTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage()); //$NON-NLS-1$
    }

    if (initialized) {
        try {
            projects = repositoryFactory.readProject();
            Arrays.sort(projects, new Comparator<Project>() {

                @Override
                public int compare(Project p1, Project p2) {
                    return p1.getLabel().compareTo(p2.getLabel());
                }

            });
        } catch (PersistenceException e) {
            projects = new Project[0];

            MessageDialog.openError(getShell(), Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                    Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage()); //$NON-NLS-1$
        } catch (BusinessException e) {
            projects = new Project[0];

            MessageDialog.openError(getShell(), Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                    Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage()); //$NON-NLS-1$
        }
    }
    if (projectViewer != null) {
        projectViewer.setInput(projects);
    }
    // importDemoProjectAction.setExistingProjects(projects);
    // if (PluginChecker.isTIS()) {
    if (projects.length > 0) {
        // Try to select the last recently used project
        selectLastUsedProject();

        if (projectViewer != null) {
            projectViewer.getControl().setEnabled(true);
        }
        if (branchesViewer != null) {
            branchesViewer.getControl().setEnabled(true);
        }
    } else {
        if (projectViewer != null) {
            projectViewer.getControl().setEnabled(false);
        }
        if (branchesViewer != null) {
            branchesViewer.getControl().setEnabled(false);
        }
    }
    // }
    // updateSandboxButton();

    // if (isTisRemote()) {
    // ManageItem[] manageElements = getManageElements();
    // List<ManageItem> toReturn = Arrays.asList(manageElements);
    // boolean enableSandboxProject = false;
    // try {
    // enableSandboxProject = ProxyRepositoryFactory.getInstance().enableSandboxProject();
    // } catch (PersistenceException e) {
    // e.printStackTrace();
    // }
    // // Sendbox for Tis_Remote
    // if (enableSandboxProject) {
    //                toReturn.add(new ManageItem("Create sandbox project") { //$NON-NLS-1$
    //
    // @Override
    // public void run() {
    // createSendboxProject();
    // }
    //
    // });
    // }
    // manageViewer.setInput(getManageElements());
    // }
}

From source file:org.talend.repository.ui.login.LoginComposite.java

protected void populateTOSProjectList() {
    Project[] projects = null;/*from   w  w  w .j a  v  a 2s. c  o m*/
    if (getConnection() != null) {
        String user2 = getConnection().getUser();
        String repositoryId2 = getConnection().getRepositoryId();
        String workSpace = getConnection().getWorkSpace();
        String name = getConnection().getName();
        if (user2 != null && !"".equals(user2) && repositoryId2 != null && !"".equals(repositoryId2) //$NON-NLS-1$//$NON-NLS-2$
                && workSpace != null && !"".equals(workSpace) && name != null && !"".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$
            boolean valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            if (valid && RepositoryConstants.REPOSITORY_REMOTE_ID.equals(repositoryId2)) {
                String url = getConnection().getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                valid = url != null || !"".equals(url); //$NON-NLS-1$
            }
            getConnection().setComplete(valid);
        }
    }

    if (getConnection() == null) {
        return;
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(
            RepositoryFactoryProvider.getRepositoriyById(getConnection().getRepositoryId()));
    if (!getConnection().isComplete()) {
        return;
    }

    boolean initialized = false;

    final String newLine = ":\n"; //$NON-NLS-1$
    try {
        try {
            repositoryFactory.checkAvailability();
        } catch (WarningException e) {
            String warnings = e.getMessage();
            if (warnings != null && !warnings.equals(lastWarnings)) {
                lastWarnings = warnings;
                MessageDialog.openWarning(getShell(), "Warning", warnings); //$NON-NLS-1$
            }
        }

        try {
            IRunnableWithProgress op = new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        ProxyRepositoryFactory.getInstance().initialize();
                    } catch (PersistenceException e) {
                        throw new InvocationTargetException(e);
                    }
                }
            };
            new ProgressMonitorDialog(getShell()).run(true, false, op);
        } catch (InvocationTargetException e) {
            throw (Exception) e.getTargetException();
        } catch (InterruptedException e) {
            //
        }

        initialized = true;
    } catch (Exception e) {
        projects = new Project[0];

        MessageDialog.openError(getShell(), Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage()); //$NON-NLS-1$
    }
}

From source file:org.talend.updates.runtime.login.InstallLocalNexusComponentsLoginTask.java

@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (!NexusServerManager.getInstance().isRemoteOnlineProject()) {
        return;/*www .ja va  2  s  .c  om*/
    }
    try {
        ComponentsLocalNexusInstallFactory compInstallFactory = new ComponentsLocalNexusInstallFactory();

        Set<ExtraFeature> uninstalledExtraFeatures = new LinkedHashSet<ExtraFeature>();
        InstallComponentMessages messages = new InstallComponentMessages();

        compInstallFactory.retrieveUninstalledExtraFeatures(monitor, uninstalledExtraFeatures);
        for (ExtraFeature feature : uninstalledExtraFeatures) {
            install(monitor, feature, messages);
        }

        if (messages.isOk()) {
            log.info(messages.getInstalledMessage());
            if (!messages.isNeedRestart()) {
                OsgiBundleInstaller.reloadComponents();
            } else {
                System.setProperty("update.restart", Boolean.TRUE.toString()); //$NON-NLS-1$
            }
        }
        if (StringUtils.isNotEmpty(messages.getFailureMessage())) {
            log.error(messages.getFailureMessage());
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    }
}

From source file:org.wso2.developerstudio.eclipse.esb.presentation.ui.XPathSelectorDialog.java

/**
 * Initialize action listeners./* w  ww  .ja  v a  2  s .  c  om*/
 */
private void initializeActions() {
    treeViewWidget.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            TreeItemData treeItemData = (TreeItemData) event.item.getData(TREE_ITEM_DATA_KEY);
            xpathTextField.setText(XSLTXPathHelper.calculateXPathToNode(treeItemData.getDomNode()));
        }
    });

    treeViewWidget.addListener(SWT.Expand, new Listener() {
        public void handleEvent(Event event) {
            TreeItem currentItem = (TreeItem) event.item;
            TreeItemData treeItemData = (TreeItemData) currentItem.getData(TREE_ITEM_DATA_KEY);

            // Explore if not already explored.
            if (!treeItemData.isMarkedAsExplored()) {
                // Make sure to remove the dummy child item.
                currentItem.removeAll();

                Node node = treeItemData.getDomNode();

                // Attributes.
                if (node.hasAttributes()) {
                    NamedNodeMap attributesMap = node.getAttributes();
                    for (int i = 0; i < attributesMap.getLength(); i++) {
                        Node childNode = attributesMap.item(i);
                        addTreeItem(currentItem, childNode);
                    }
                }

                // Children.
                if (node.hasChildNodes()) {
                    NodeList childNodes = node.getChildNodes();
                    for (int i = 0; i < childNodes.getLength(); i++) {
                        Node childNode = childNodes.item(i);
                        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                            addTreeItem(currentItem, childNode);
                        }
                    }
                }

                // Done exploring.
                treeItemData.setMarkedAsExplored();
            }
        }
    });

    treeViewWidget.addMouseListener(new MouseListener() {
        public void mouseUp(MouseEvent e) {
        }

        public void mouseDown(MouseEvent e) {
        }

        public void mouseDoubleClick(MouseEvent e) {
            TreeItem[] selection = treeViewWidget.getSelection();
            if (selection.length > 0) {
                Node selectedNode = ((TreeItemData) selection[0].getData(TREE_ITEM_DATA_KEY)).getDomNode();
                setSelectedXpath(XSLTXPathHelper.calculateXPathToNode(selectedNode));
                dialogShell.dispose();
            }
        }
    });

    okButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            setSelectedXpath(xpathTextField.getText());
            dialogShell.dispose();
        }
    });

    cancelButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) {
            dialogShell.dispose();
        }
    });

    browseButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            // Configure file dialog.
            FileDialog fileBrowserDialog = new FileDialog(dialogShell, SWT.OPEN);
            fileBrowserDialog.setText("Select XML Document");
            fileBrowserDialog.setFilterExtensions(new String[] { "*.xml" });

            // Let the user browse for the input xml file.
            final String filePath = fileBrowserDialog.open();

            // If the user selected a file.
            if (!StringUtils.isBlank(filePath)) {
                // Clear tree view.
                treeViewWidget.removeAll();

                // Update the selected path
                filePathTextField.setText(filePath);

                final File selectedFile = new File(filePath);
                if (selectedFile.exists() && selectedFile.canRead()) {
                    // Create a new runnable that can be executed with a progress bar.
                    IRunnableWithProgress runnable = new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            // We have no clue how long this would take.
                            monitor.beginTask("Parsing xml document...", IProgressMonitor.UNKNOWN);

                            // Parse the xml document into a dom object.
                            try {
                                Document document = EsbUtils.parseDocument(selectedFile);
                                final Node rootNode = document.getDocumentElement();

                                // Adding a tree item is a ui related
                                // operation which must be executed on the
                                // ui thread. Since we are currently
                                // executing inside a background thread, we
                                // need to explicitly invoke the ui thread.
                                new UIJob("add-root-tree-item-job") {
                                    public IStatus runInUIThread(IProgressMonitor monitor) {
                                        addTreeItem(null, rootNode);
                                        addNameSpaces(rootNode);
                                        return Status.OK_STATUS;
                                    }
                                }.schedule();

                                // Done.
                                monitor.done();
                            } catch (Exception ex) {
                                // Stop progress.
                                monitor.done();

                                // Report error.
                                throw new InvocationTargetException(ex);
                            }
                        }
                    };

                    // Run the operation within a progress monitor dialog,
                    // make sure to fork-off from the ui thread so that we
                    // don't cause the ui to hang.
                    try {
                        new ProgressMonitorDialog(dialogShell).run(true, false, runnable);
                    } catch (Exception ex) {
                        MessageDialog.openError(dialogShell, "Parse Error",
                                "Error while parsing specified xml file.");
                    }
                } else {
                    MessageDialog.openError(dialogShell, "I/O Error", "Unable to read specified input file.");
                }
            }
        }
    });
}

From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.custom.configure.ui.XPathSelectorDialog.java

/**
 * Initialize action listeners.//  w  ww.ja  va  2s .  c  o  m
 */
private void initializeActions() {
    treeViewWidget.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            TreeItemData treeItemData = (TreeItemData) event.item.getData(TREE_ITEM_DATA_KEY);
            xpathTextField.setText(XSLTXPathHelper.calculateXPathToNode(treeItemData.getDomNode()));
        }
    });

    treeViewWidget.addListener(SWT.Expand, new Listener() {
        public void handleEvent(Event event) {
            TreeItem currentItem = (TreeItem) event.item;
            TreeItemData treeItemData = (TreeItemData) currentItem.getData(TREE_ITEM_DATA_KEY);

            // Explore if not already explored.
            if (!treeItemData.isMarkedAsExplored()) {
                // Make sure to remove the dummy child item.
                currentItem.removeAll();

                Node node = treeItemData.getDomNode();

                // Attributes.
                if (node.hasAttributes()) {
                    NamedNodeMap attributesMap = node.getAttributes();
                    for (int i = 0; i < attributesMap.getLength(); i++) {
                        Node childNode = attributesMap.item(i);
                        addTreeItem(currentItem, childNode);
                    }
                }

                // Children.
                if (node.hasChildNodes()) {
                    NodeList childNodes = node.getChildNodes();
                    for (int i = 0; i < childNodes.getLength(); i++) {
                        Node childNode = childNodes.item(i);
                        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                            addTreeItem(currentItem, childNode);
                        }
                    }
                }

                // Done exploring.
                treeItemData.setMarkedAsExplored();
            }
        }
    });

    treeViewWidget.addMouseListener(new MouseListener() {
        public void mouseUp(MouseEvent e) {
        }

        public void mouseDown(MouseEvent e) {
        }

        public void mouseDoubleClick(MouseEvent e) {
            TreeItem[] selection = treeViewWidget.getSelection();
            if (selection.length > 0) {
                Node selectedNode = ((TreeItemData) selection[0].getData(TREE_ITEM_DATA_KEY)).getDomNode();
                setSelectedXpath(XSLTXPathHelper.calculateXPathToNode(selectedNode));
                dialogShell.dispose();
            }
        }
    });

    okButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            setSelectedXpath(xpathTextField.getText());
            dialogShell.dispose();
        }
    });

    cancelButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) {
            dialogShell.dispose();
        }
    });

    browseButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            // Configure file dialog.
            FileDialog fileBrowserDialog = new FileDialog(dialogShell, SWT.OPEN);
            fileBrowserDialog.setText("Select XML Document");
            fileBrowserDialog.setFilterExtensions(new String[] { "*.xml" });

            // Let the user browse for the input xml file.
            final String filePath = fileBrowserDialog.open();

            // If the user selected a file.
            if (!StringUtils.isBlank(filePath)) {
                // Clear tree view.
                treeViewWidget.removeAll();

                // Update the selected path
                filePathTextField.setText(filePath);

                final File selectedFile = new File(filePath);
                if (selectedFile.exists() && selectedFile.canRead()) {
                    // Create a new runnable that can be executed with a
                    // progress bar.
                    IRunnableWithProgress runnable = new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor)
                                throws InvocationTargetException, InterruptedException {
                            // We have no clue how long this would take.
                            monitor.beginTask("Parsing xml document...", IProgressMonitor.UNKNOWN);

                            // Parse the xml document into a dom object.
                            try {
                                Document document = parseDocument(selectedFile);
                                final Node rootNode = document.getDocumentElement();

                                // Adding a tree item is a ui related
                                // operation which must be executed on the
                                // ui thread. Since we are currently
                                // executing inside a background thread, we
                                // need to explicitly invoke the ui thread.
                                new UIJob("add-root-tree-item-job") {
                                    public IStatus runInUIThread(IProgressMonitor monitor) {
                                        addTreeItem(null, rootNode);
                                        addNameSpaces(rootNode);
                                        return Status.OK_STATUS;
                                    }
                                }.schedule();

                                // Done.
                                monitor.done();
                            } catch (Exception ex) {
                                // Stop progress.
                                monitor.done();

                                // Report error.
                                throw new InvocationTargetException(ex);
                            }
                        }
                    };

                    // Run the operation within a progress monitor dialog,
                    // make sure to fork-off from the ui thread so that we
                    // don't cause the ui to hang.
                    try {
                        new ProgressMonitorDialog(dialogShell).run(true, false, runnable);
                    } catch (Exception ex) {
                        MessageDialog.openError(dialogShell, "Parse Error",
                                "Error while parsing specified xml file.");
                    }
                } else {
                    MessageDialog.openError(dialogShell, "I/O Error", "Unable to read specified input file.");
                }
            }
        }
    });
}

From source file:org.wso2.developerstudio.eclipse.registry.apim.views.RegistryBrowserAPIMView.java

private void pasteSequence(final RegistryResourceNode copyRegResource,
        final RegistryResourceNode targetRegResource) throws InvocationTargetException, InterruptedException {
    new ProgressMonitorDialog(getSite().getShell()).run(true, true, new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            try {
                monitor.beginTask(PASTE_OPERATION_MONITOR, 100);
                if (copyRegResource != null) {

                    String path = copyRegResource.getRegistryResourcePath();
                    String destinationPath = targetRegResource.getRegistryResourcePath() + path.substring(
                            copyRegResource.getRegistryResourceNodeParent().getRegistryResourcePath().length());

                    ArrayList<RegistryResourceNode> localResourceNodeList = targetRegResource
                            .getLocalResourceNodeList();
                    for (RegistryResourceNode registryResourceNode : localResourceNodeList) {
                        if (copyRegResource.getResourceName().equals(registryResourceNode.getResourceName())) {

                            Display.getDefault().syncExec(new Runnable() {
                                @SuppressWarnings({})
                                @Override
                                public void run() {
                                    MessageDialogUtils.error(Display.getCurrent().getActiveShell(), "",
                                            THIS_OPERATION_CANNOT_BE_PERFORMED_BECAUSE_THE
                                                    + copyRegResource.getResourceName()
                                                    + RESOURCE_ALREADY_EXISTS);

                                }//from ww w .  jav  a  2  s  .  c o m

                            });

                            return;
                        }
                    }
                    monitor.worked(30);
                    final RegistryResourceNode newNode = new RegistryResourceNode(
                            localUrlNode.getUrlInfoList().get(0), destinationPath, targetRegResource);
                    newNode.setRegistryResource(RegistryResourceType.RESOURCE);
                    newNode.setResourceName(copyRegResource.getResourceName());
                    newNode.setNew(true);
                    newNode.setAllowExapand(false);
                    newNode.setIterativeRefresh(false);
                    newNode.setMediaType(RESOURCE_MEDIA_TYPE);
                    monitor.worked(60);
                    Path tempDir = Files.createTempDirectory("tempfiles" + targetRegResource.getResourceName());
                    String filePath = tempDir.toString() + File.separator + copyRegResource.getResourceName();
                    File dest = new File(filePath);
                    File sourceFile = copyRegResource.getFile();
                    copyFileToFile(sourceFile, dest);
                    newNode.setNewFile(dest);
                    targetRegResource.addChildResource(newNode);
                    changedResourceNodes.put(newNode.getRegistryResourcePath(), newNode);
                    updateDirtyState();
                    monitor.worked(80);
                    Display.getDefault().asyncExec(new Runnable() {
                        @SuppressWarnings({})
                        @Override
                        public void run() {
                            refreshTreeviewer(newNode);
                            monitor.done();
                        }

                    });

                }
            } catch (IOException e) {
                log.error("Pasting error", e);
                throw new InvocationTargetException(e);
            }
        }
    });

}

From source file:org.wso2.developerstudio.eclipse.registry.apim.views.RegistryBrowserAPIMView.java

private void renameSequence(final RegistryResourceNode regResourceNode)
        throws IOException, InvocationTargetException, InterruptedException {

    final String currentName = regResourceNode.getLastSegmentInPath().split("\\.")[0];
    InputDialog inputDialog = new InputDialog(Display.getCurrent().getActiveShell(),
            RENAME_RESOURCE_DIALOG_TITLE, NEW_NAME_LABEL, currentName, new IInputValidator() {
                public String isValid(String value) {
                    if (value == null || value.equals("")) {
                        return SPECIFY_A_NEW_NAME_TO_THE_RESOURCE;
                    } else if (value.equals(currentName)) {
                        return SPECIFY_A_NEW_NAME_TO_THE_RESOURCE;
                    } else {
                        return null;
                    }/* w ww . j  a va 2  s .com*/
                }
            });
    if (inputDialog.open() == InputDialog.OK) {
        String inputName = inputDialog.getValue();
        if (!inputName.contains(".xml")) {
            inputName = inputName + ".xml";
        }
        final String newName = inputName;

        new ProgressMonitorDialog(getSite().getShell()).run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                monitor.beginTask("", 100);
                monitor.worked(60);

                String newPath = regResourceNode.getParent()
                        + (regResourceNode.getParent().endsWith(DEFAULT_PATH) ? newName
                                : DEFAULT_PATH + newName);

                ArrayList<RegistryResourceNode> localResourceNodeList = regResourceNode
                        .getRegistryResourceNodeParent().getLocalResourceNodeList();
                for (RegistryResourceNode registryResourceNode : localResourceNodeList) {
                    if (newName.equals(registryResourceNode.getResourceName())) {

                        Runnable runnable = new Runnable() {
                            @Override
                            public void run() {
                                MessageDialogUtils.error(Display.getCurrent().getActiveShell(), "",
                                        THIS_OPERATION_CANNOT_BE_PERFORMED_BECAUSE_THE + " '" + newName + "' "
                                                + " already exists!");

                            }
                        };

                        Display.getDefault().syncExec(runnable);
                        return;
                    }
                }

                File source = regResourceNode.getFile();
                Path tempDir = null;
                try {
                    tempDir = Files.createTempDirectory("tempfiles");
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                }
                String filePath = tempDir.toString() + File.separator + newName;
                File dest = new File(filePath);
                try {
                    copyFileToFile(source, dest);
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                }
                if (regResourceNode.isIsnew()) {
                    regResourceNode.setResourceName(newName);
                    regResourceNode.setNewFile(dest);
                } else if (regResourceNode.isRename()) {
                    regResourceNode.setNewPath(newPath);
                    regResourceNode.setResourceName(newName);
                } else {
                    regResourceNode.setOldPath(regResourceNode.getRegistryResourcePath());
                    regResourceNode.setNewPath(newPath);
                    regResourceNode.setRename(true);
                    regResourceNode.setNewFile(dest);
                    regResourceNode.setResourceName(newName);
                }

                Display.getDefault().syncExec(new Runnable() {
                    @SuppressWarnings({})
                    @Override
                    public void run() {
                        if (regResourceNode.getFileEditor() != null) {
                            if (regResourceNode.getFileEditor().isDirty()) {
                                if (MessageDialogUtils.question(
                                        regResourceNode.getFileEditor().getSite().getShell(),
                                        DO_YOU_WANT_TO_SAVE_CHANGES)) {
                                    regResourceNode.getFileEditor().doSave(new NullProgressMonitor());
                                }
                            }
                            closeEditor(regResourceNode);
                            updateSequenceName(regResourceNode.getNewFile());
                            openResourceInEditor(regResourceNode);
                        } else {
                            updateSequenceName(regResourceNode.getNewFile());
                        }
                    }

                    private void updateSequenceName(File file) {
                        try {
                            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
                            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
                            Document doc = docBuilder.parse(file);
                            Node sequence = doc.getElementsByTagName("sequence").item(0);
                            Node sequenceName = sequence.getAttributes().getNamedItem("name");
                            sequenceName.setNodeValue(newName);
                            TransformerFactory transformerFactory = TransformerFactory.newInstance();
                            Transformer transformer = transformerFactory.newTransformer();
                            DOMSource source = new DOMSource(doc);
                            StreamResult result = new StreamResult(file);
                            transformer.transform(source, result);
                        } catch (SAXException | IOException | ParserConfigurationException
                                | TransformerException e) {
                            log.error("Error while renaming sequence.", e);
                        }
                    }
                });

                monitor.worked(100);
                monitor.done();

            }
        });

    }
}

From source file:org.wso2.developerstudio.humantaskeditor.wizards.HumanTaskExportWizard.java

public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(monitor);/* w  w w  .j  av a 2 s. co m*/
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        if (HumantaskEditorConstants.EMPTY_STRING.equalsIgnoreCase(realException.getMessage().trim())) {
            MessageDialog.openError(getShell(), HumantaskEditorConstants.ERROR_MESSAGE,
                    "Error occured while deploying the data service");
        } else {
            MessageDialog.openError(getShell(), HumantaskEditorConstants.ERROR_MESSAGE,
                    realException.getMessage());
        }
        return false;
    }
    MessageDialog.openInformation(getShell(), HumantaskEditorConstants.MESSAGE_DIALOG_HUMAN_TASK_DISTRIBUTION,
            "Human task archive exported successfully");

    return true;
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java

/**
 * This method is called when 'Finish' button is pressed in the wizard. We
 * will create an operation and run it using wizard as execution context.
 *//*from ww w.j  a  va2  s. c o m*/
public boolean performFinish() {
    // final String containerName = page.getContainerName();
    final String projectName = pageOne.getProjectName();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                boolean res = doFinish(projectName, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}