Search in sources :

Example 41 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project che by eclipse.

the class ProcessorBasedRefactoring method createChange.

/**
	 * {@inheritDoc}
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", fParticipants.size() + 3);
    pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
    Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
    if (pm.isCanceled())
        throw new OperationCanceledException();
    fTextChangeMap = new HashMap();
    addToTextChangeMap(processorChange);
    List /*<Change>*/
    changes = new ArrayList();
    List /*<Change>*/
    preChanges = new ArrayList();
    Map /*<Change, RefactoringParticipant>*/
    participantMap = new HashMap();
    for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
        final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
        try {
            //$NON-NLS-1$
            final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
            stats.startRun();
            Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
            Change change = participant.createChange(new SubProgressMonitor(pm, 1));
            stats.endRun();
            if (preChange != null) {
                if (fPreChangeParticipants == null)
                    fPreChangeParticipants = new ArrayList();
                fPreChangeParticipants.add(participant);
                preChanges.add(preChange);
                participantMap.put(preChange, participant);
                addToTextChangeMap(preChange);
            }
            if (change != null) {
                changes.add(change);
                participantMap.put(change, participant);
                addToTextChangeMap(change);
            }
        } catch (CoreException e) {
            disableParticipant(participant, e);
            throw e;
        } catch (OperationCanceledException e) {
            throw e;
        } catch (RuntimeException e) {
            disableParticipant(participant, e);
            throw e;
        }
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    fTextChangeMap = null;
    Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
    ProcessorChange result = new ProcessorChange(getName());
    result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
    result.add(processorChange);
    result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
    result.setParticipantMap(participantMap);
    result.setPreChangeParticipants(fPreChangeParticipants);
    if (postChange != null)
        result.add(postChange);
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) PerformanceStats(org.eclipse.core.runtime.PerformanceStats) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project tdi-studio-se by Talend.

the class ComponentChooseDialog method chooseOneComponent.

/**
     * Let the user choose which component he would like to create.
     *
     * @param neededComponents
     * @param name
     * @param quickCreateInput
     * @param quickCreateOutput
     */
private IComponent chooseOneComponent(List<IComponent> neededComponents, IComponentName name, boolean quickCreateInput, boolean quickCreateOutput) {
    if (neededComponents.isEmpty()) {
        return null;
    }
    if (neededComponents.size() == 1) {
        return neededComponents.get(0);
    }
    IComponent inputComponent = getComponentByName(name.getInputComponentName(), quickCreateInput, neededComponents);
    if (inputComponent != null) {
        return inputComponent;
    }
    IComponent outputComponent = getComponentByName(name.getOutPutComponentName(), quickCreateOutput, neededComponents);
    if (outputComponent != null) {
        return outputComponent;
    }
    ComponentChooseDialog dialog = new ComponentChooseDialog(editor.getSite().getShell(), neededComponents);
    IComponent defaultComponent = getComponentByName(name.getDefaultComponentName(), true, neededComponents);
    if (defaultComponent != null) {
        dialog.setInitialSelections(new Object[] { defaultComponent });
    } else {
        dialog.setInitialSelections(new Object[] { neededComponents.get(0) });
    }
    if (dialog.open() == IDialogConstants.OK_ID) {
        return dialog.getResultComponent();
    }
    //$NON-NLS-1$
    throw new OperationCanceledException(Messages.getString("TalendEditorDropTargetListener.cancelOperation"));
}
Also used : IComponent(org.talend.core.model.components.IComponent) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 43 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method handleDrop.

@Override
protected void handleDrop() {
    if (!checkSelectionSource()) {
        return;
    }
    updateTargetRequest();
    updateTargetEditPart();
    if (selectSourceList.get(0) instanceof PaletteEditPart && getTargetRequest() instanceof CreateRequest) {
        if (getTargetEditPart() instanceof ProcessPart) {
            Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
            if (newObject != null) {
                Command command = getCommand();
                if (command != null) {
                    execCommandStack(command);
                }
            }
        }
        return;
    }
    if (isContextSource) {
        createContext();
    } else {
        if (!(getTargetEditPart() instanceof NodeContainerPart)) {
            try {
                createNewComponent(getCurrentEvent());
            } catch (OperationCanceledException e) {
                return;
            }
        }
    }
    // in case after drag/drop the editor is dirty but can not get focus
    if (editor.isDirty()) {
        editor.setFocus();
    }
    this.eraseTargetFeedback();
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateRequest(org.eclipse.gef.requests.CreateRequest) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart)

Example 44 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project tdi-studio-se by Talend.

the class JobHierarchyLifeCycle method ensureRefreshedTypeHierarchy.

public void ensureRefreshedTypeHierarchy(final IProcess2 element, IRunnableContext context) throws InvocationTargetException, InterruptedException {
    if (element == null) {
        freeHierarchy();
        return;
    }
    // boolean hierachyCreationNeeded = (fHierarchy == null || !element.equals(inputProcess));
    boolean hierachyCreationNeeded = true;
    if (hierachyCreationNeeded || fHierarchyRefreshNeeded) {
        IRunnableWithProgress op = new IRunnableWithProgress() {

            public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
                try {
                    doHierarchyRefresh(element, pm);
                } catch (JavaModelException e) {
                    throw new InvocationTargetException(e);
                } catch (OperationCanceledException e) {
                    throw new InterruptedException();
                }
            }
        };
        fHierarchyRefreshNeeded = true;
        context.run(true, true, op);
        fHierarchyRefreshNeeded = false;
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 45 with OperationCanceledException

use of org.eclipse.core.runtime.OperationCanceledException in project tdi-studio-se by Talend.

the class HeapDumpSaxEventHandler method startElement.

/*
     * @see DefaultHandler#startElement(String, String, String, Attributes)
     */
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    // memory-profile
    if ("heap-profile".equals(name)) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        String date = attributes.getValue("date");
        //$NON-NLS-1$
        String runtime = attributes.getValue("runtime");
        //$NON-NLS-1$
        String mainClass = attributes.getValue("mainClass");
        //$NON-NLS-1$
        String arguments = attributes.getValue("arguments");
        //$NON-NLS-1$
        String comments = attributes.getValue("comments");
        info = new ProfileInfo(date, runtime, mainClass, arguments, comments);
    }
    // class
    if ("class".equals(name)) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        String className = attributes.getValue("name");
        //$NON-NLS-1$
        String size = attributes.getValue("size");
        //$NON-NLS-1$
        String count = attributes.getValue("count");
        //$NON-NLS-1$
        String baseSize = attributes.getValue("baseSize");
        HeapElement element = new HeapElement(className, Long.parseLong(size), Long.parseLong(count), Long.parseLong(baseSize));
        heapListElements.add((IHeapElement) element);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IHeapElement(org.talend.designer.runtime.visualization.IHeapElement) IProfileInfo(org.talend.designer.runtime.visualization.core.dump.IProfileInfo)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)134 CoreException (org.eclipse.core.runtime.CoreException)38 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)34 ArrayList (java.util.ArrayList)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)21 IStatus (org.eclipse.core.runtime.IStatus)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 Status (org.eclipse.core.runtime.Status)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)16 File (java.io.File)15 SubMonitor (org.eclipse.core.runtime.SubMonitor)10 Job (org.eclipse.core.runtime.jobs.Job)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9 IProject (org.eclipse.core.resources.IProject)8 HashSet (java.util.HashSet)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)7