Search in sources :

Example 51 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project tdi-studio-se by Talend.

the class ExportProjectsAsAction method initializeExternalLibraries.

/**
     * DOC bqian Comment method "test".
     */
private void initializeExternalLibraries() {
    initializeLibPath();
    // final InputStream initialContents = null;
    final Map<Project, List<LinkTargetStore>> map = getProjectAndRelatedLinks();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) {
            Set<Project> projects = map.keySet();
            //$NON-NLS-1$
            monitor.beginTask(Messages.getString("ExportProjectsAsAction.createLiberariesLink"), projects.size());
            for (Project project : projects) {
                //$NON-NLS-1$
                monitor.setTaskName(Messages.getString("ExportProjectsAsAction.processProject") + project.getLabel());
                List<LinkTargetStore> links = map.get(project);
                for (LinkTargetStore store : links) {
                    // CreateFileOperation op = new CreateFileOperation(store.file, store.uri, null,
                    // IDEWorkbenchMessages.WizardNewFileCreationPage_title);
                    CreateFileOperation op = new CreateFileOperation(store.file, store.uri, null, //$NON-NLS-1$
                    Messages.getString("IDEWorkbenchMessages.WizardNewFileCreationPage_title"));
                    try {
                        PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(window.getShell()));
                    } catch (final ExecutionException e) {
                        ExceptionHandler.process(e);
                    }
                }
                monitor.worked(1);
            }
            monitor.done();
        }
    };
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, op);
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateFileOperation(org.eclipse.ui.ide.undo.CreateFileOperation) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 52 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project tdi-studio-se by Talend.

the class ComponentProjectManager method createNewProject.

/**
     * Creates a new project resource with the selected name.
     * <p>
     * In normal usage, this method is invoked after the user has pressed Finish on the wizard; the enablement of the
     * Finish button implies that all controls on the pages currently contain valid values.
     * </p>
     * <p>
     * Note that this wizard caches the new project once it has been successfully created; subsequent invocations of
     * this method will answer the same project resource without attempting to create it again.
     * </p>
     * 
     * @return the created project resource, or <code>null</code> if the project was not created
     */
public IProject createNewProject(String directroy, String projectName, Shell shell) {
    if (projDir.equals(directroy)) {
        return project;
    }
    final Shell currentShell = shell;
    // get a project handle
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (newProjectHandle.getRawLocation() != null) {
        if (newProjectHandle.getRawLocation().equals(directroy)) {
            return newProjectHandle;
        } else {
            try {
                newProjectHandle.delete(false, true, null);
            } catch (CoreException e) {
                // e.printStackTrace();
                org.talend.componentdesigner.exception.ExceptionHandler.process(e);
            }
        }
    }
    // final IJavaProject javaProjHandle = JavaCore.create(newProjectHandle);
    // get a project descriptor
    URI location = null;
    if (directroy == null || directroy.equals(PluginConstant.EMPTY_STRING)) {
        return null;
    } else {
        location = new File(directroy).toURI();
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    description.setLocationURI(location);
    // create the new project operation
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(description, //$NON-NLS-1$
            Messages.getString("ComponentProjectManager.NewProject"));
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(currentShell));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    // run the new project creation o`peration
    try {
        ProgressUI.popProgressDialog(op, shell);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, IStatus.WARNING, Messages.getString("ComponentProjectManager.WarningMsg", //$NON-NLS-1$
                newProjectHandle.getName()), cause));
            } else {
                status = new StatusAdapter(new Status(cause.getStatus().getSeverity(), ComponentDesigenerPlugin.PLUGIN_ID, cause.getStatus().getSeverity(), Messages.getString("ComponentProjectManager.CreationProblems"), //$NON-NLS-1$
                cause));
            }
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(new Status(IStatus.WARNING, ComponentDesigenerPlugin.PLUGIN_ID, 0, Messages.getString("ComponentProjectManager.InternalErrorMsg", t.getMessage()), //$NON-NLS-1$
            t));
            //$NON-NLS-1$
            status.setProperty(StatusAdapter.TITLE_PROPERTY, Messages.getString("ComponentProjectManager.CreationProblems"));
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
        return null;
    }
    project = newProjectHandle;
    return project;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) StatusAdapter(org.eclipse.ui.statushandlers.StatusAdapter) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) CreateProjectOperation(org.eclipse.ui.ide.undo.CreateProjectOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) File(java.io.File)

Example 53 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project tdi-studio-se by Talend.

the class RepositoryFactoryProxyLabelProvider method getColumnText.

@Override
public String getColumnText(Object object, int columnIndex) {
    String columnText = super.getColumnText(object, columnIndex);
    BusinessAssignment assignment = (BusinessAssignment) object;
    IRepositoryViewObject lastVersion = getLastVersion(object);
    try {
        if (columnIndex == 0) {
            if (lastVersion == null) {
                MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(assignment.getTalendItem().getId());
                if (table != null) {
                    if (SubItemHelper.isDeleted(table)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                Query query = MetadataToolHelper.getQueryFromRepository(assignment.getTalendItem().getId());
                if (query != null) {
                    if (SubItemHelper.isDeleted(query)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(assignment.getTalendItem().getId());
                if (function != null) {
                    if (SubItemHelper.isDeleted(function)) {
                        //$NON-NLS-1$
                        columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
                    }
                    return columnText;
                }
                TalendItem item = assignment.getTalendItem();
                if (item instanceof SQLPattern) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SQLPATTERNS);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return columnText;
                        }
                    }
                } else if (item instanceof Routine) {
                    List<IRepositoryViewObject> list = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.ROUTINES);
                    for (IRepositoryViewObject obj : list) {
                        if (item.getLabel().equals(obj.getLabel())) {
                            return columnText;
                        }
                    }
                }
                //$NON-NLS-1$
                columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.NotFound");
            } else if (isDeleted(lastVersion)) {
                //$NON-NLS-1$
                columnText += Messages.getString("RepositoryFactoryProxyLabelProvider.Deleted");
            }
        }
    } catch (PersistenceException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    if (columnIndex == 1) {
        if (lastVersion != null) {
            String label = lastVersion.getProperty().getLabel();
            if (!label.equals(columnText)) {
                ChangeTalendItemLabelCommand command = new ChangeTalendItemLabelCommand(((BusinessAssignment) object).getTalendItem(), label);
                try {
                    command.execute(null, null);
                } catch (ExecutionException e) {
                }
                return label;
            }
        }
    }
    return columnText;
}
Also used : SQLPattern(org.talend.designer.business.model.business.SQLPattern) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.core.model.metadata.builder.connection.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) ChangeTalendItemLabelCommand(org.talend.designer.business.diagram.custom.commands.ChangeTalendItemLabelCommand) Routine(org.talend.designer.business.model.business.Routine) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 54 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project sling by apache.

the class ConvertToContentProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
        ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
        dialog.setMessage("Select content sync root location (containing the jcr root)");
        dialog.setTitle("Content Sync Root");
        IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
        if (initialContainer != null) {
            dialog.setInitialElementSelections(Arrays.asList(initialContainer));
        }
        dialog.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof IProject) {
                    return ((IProject) element).equals(project);
                }
                // display folders only
                return element instanceof IContainer;
            }
        });
        dialog.setInput(new IWorkbenchAdapter() {

            @Override
            public Object getParent(Object o) {
                return null;
            }

            @Override
            public String getLabel(Object o) {
                return null;
            }

            @Override
            public ImageDescriptor getImageDescriptor(Object object) {
                return null;
            }

            @Override
            public Object[] getChildren(Object o) {
                return new Object[] { project };
            }
        });
        // this is the root element
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ISelectionStatusValidator() {

            @Override
            public IStatus validate(Object[] selection) {
                if (selection.length > 0) {
                    final Object item = selection[0];
                    if (item instanceof IContainer) {
                        IContainer selectedContainer = (IContainer) item;
                        String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
                        if (errorMsg != null) {
                            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
                        } else {
                            return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
                        }
                    }
                }
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
            }
        });
        if (dialog.open() == ContainerSelectionDialog.OK) {
            Object[] result = dialog.getResult();
            if (result != null && result.length > 0) {
                final IContainer container = (IContainer) result[0];
                IRunnableWithProgress r = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            IResource jcrRoot = container.findMember("jcr_root");
                            if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
                                MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
                                return;
                            }
                            ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
                        } catch (CoreException e) {
                            Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                            MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                        }
                    }
                };
                try {
                    PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
                } catch (Exception e) {
                    Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
                    MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                }
            }
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) BaseWorkbenchContentProvider(org.eclipse.ui.model.BaseWorkbenchContentProvider) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) ISelection(org.eclipse.jface.viewers.ISelection) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 55 with ExecutionException

use of org.eclipse.core.commands.ExecutionException in project sling by apache.

the class ConvertToBundleProjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        List<IProject> applicableProjects = new LinkedList<>();
        IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
        for (IProject p : allProjects) {
            if (p.isOpen() && ProjectHelper.isPotentialBundleProject(p)) {
                applicableProjects.add(p);
            }
        }
        Object[] elems = ((IStructuredSelection) selection).toArray();
        List<IProject> initialSelection = new ArrayList<>(elems.length);
        for (Object elem : elems) {
            IProject project = null;
            if (elem instanceof IFile) {
                IFile file = (IFile) elem;
                project = file.getProject();
            } else if (elem instanceof IProject) {
                project = (IProject) elem;
            } else if (elem instanceof IJavaProject) {
                project = ((IJavaProject) elem).getProject();
            }
            if (project != null)
                initialSelection.add(project);
        }
        ConvertProjectsWizard wizard = new ConvertProjectsWizard(applicableProjects, initialSelection, "Convert to Bundle Project(s)", "Select project(s) to convert to Bundle project(s)\n" + "List contains open Java projects that are not yet bundle or content projects.");
        final Display display = getDisplay();
        final WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
        BusyIndicator.showWhile(display, new Runnable() {

            public void run() {
                dialog.open();
            }
        });
        if (dialog.getReturnCode() != WizardDialog.OK) {
            // user did not click OK
            return null;
        }
        final List<IProject> selectedProjects = wizard.getSelectedProjects();
        if (selectedProjects == null || selectedProjects.size() == 0) {
            // no project was selected
            return null;
        }
        IRunnableWithProgress r = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (IProject project : selectedProjects) {
                        ConfigurationHelper.convertToBundleProject(project);
                    }
                } catch (CoreException e) {
                    e.printStackTrace();
                    MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
                }
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
        } catch (Exception e) {
            e.printStackTrace();
            MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ISelection(org.eclipse.jface.viewers.ISelection) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Display(org.eclipse.swt.widgets.Display)

Aggregations

ExecutionException (org.eclipse.core.commands.ExecutionException)66 CoreException (org.eclipse.core.runtime.CoreException)20 IFile (org.eclipse.core.resources.IFile)15 ArrayList (java.util.ArrayList)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 IStatus (org.eclipse.core.runtime.IStatus)12 Shell (org.eclipse.swt.widgets.Shell)12 Status (org.eclipse.core.runtime.Status)11 IEditorPart (org.eclipse.ui.IEditorPart)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 File (java.io.File)7 List (java.util.List)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)7 IProject (org.eclipse.core.resources.IProject)7 FileEditorInput (org.eclipse.ui.part.FileEditorInput)7