Search in sources :

Example 1 with ISynchronizeModelElement

use of org.eclipse.team.ui.synchronize.ISynchronizeModelElement in project linuxtools by eclipse.

the class PrepareChangeLogAction method extractSynchronizeModelInfo.

private void extractSynchronizeModelInfo(ISynchronizeModelElement d, IPath path, Vector<PatchFile> newList, Vector<PatchFile> removeList, Vector<PatchFile> changeList) {
    // Don't add entries for ChangeLog files though.
    if (d.hasChildren()) {
        IPath newPath = path.append(d.getName());
        for (IDiffElement element : d.getChildren()) {
            if (element instanceof ISynchronizeModelElement)
                extractSynchronizeModelInfo((ISynchronizeModelElement) element, newPath, newList, removeList, changeList);
            else {
                if (!(d.getName().equals("ChangeLog"))) {
                    // $NON-NLS-1$
                    PatchFile p = new PatchFile(d.getResource());
                    int kind = d.getKind() & Differencer.CHANGE_TYPE_MASK;
                    if (kind == Differencer.CHANGE) {
                        changeList.add(p);
                    } else if (kind == Differencer.ADDITION) {
                        p.setNewfile(true);
                        newList.add(p);
                    } else if (kind == Differencer.DELETION) {
                        p.setRemovedFile(true);
                        removeList.add(p);
                    }
                } else {
                    this.changeLogModified = true;
                }
            }
        }
    } else {
        if (!(d.getName().equals("ChangeLog"))) {
            // $NON-NLS-1$
            PatchFile p = new PatchFile(d.getResource());
            int kind = d.getKind() & Differencer.CHANGE_TYPE_MASK;
            if (kind == Differencer.CHANGE) {
                changeList.add(p);
            } else if (kind == Differencer.ADDITION) {
                p.setNewfile(true);
                newList.add(p);
            } else if (kind == Differencer.DELETION) {
                p.setRemovedFile(true);
                removeList.add(p);
            }
        } else {
            this.changeLogModified = true;
        }
    }
}
Also used : IDiffElement(org.eclipse.compare.structuremergeviewer.IDiffElement) IPath(org.eclipse.core.runtime.IPath) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement)

Example 2 with ISynchronizeModelElement

use of org.eclipse.team.ui.synchronize.ISynchronizeModelElement in project linuxtools by eclipse.

the class PrepareChangeLogAction method prepareChangeLog.

private void prepareChangeLog(IProgressMonitor monitor) {
    Object element = selected.getFirstElement();
    IResource resource = null;
    Vector<PatchFile> newList = new Vector<>();
    Vector<PatchFile> removeList = new Vector<>();
    Vector<PatchFile> changeList = new Vector<>();
    int totalChanges = 0;
    if (element instanceof IResource) {
        resource = (IResource) element;
    } else if (element instanceof ISynchronizeModelElement) {
        ISynchronizeModelElement sme = (ISynchronizeModelElement) element;
        resource = sme.getResource();
    } else if (element instanceof IAdaptable) {
        resource = ((IAdaptable) element).getAdapter(IResource.class);
    }
    if (resource == null)
        return;
    IProject project = resource.getProject();
    // Get the repository provider so we can support multiple types of
    // code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
    RepositoryProvider r = RepositoryProvider.getProvider(project);
    if (r == null)
        return;
    SyncInfoSet set = new SyncInfoSet();
    Subscriber s = r.getSubscriber();
    if (s == null)
        return;
    if (element instanceof ISynchronizeModelElement) {
        // We can extract the ChangeLog list from the synchronize view which
        // allows us to skip items removed from the view
        ISynchronizeModelElement d = (ISynchronizeModelElement) element;
        while (d.getParent() != null) d = (ISynchronizeModelElement) d.getParent();
        extractSynchronizeModelInfo(d, new Path(""), newList, removeList, changeList);
        totalChanges = newList.size() + removeList.size() + changeList.size();
    } else {
        // We can then get a list of all out-of-sync resources.
        IResource[] resources = new IResource[] { project };
        try {
            s.refresh(resources, IResource.DEPTH_INFINITE, monitor);
        } catch (TeamException e) {
        // Ignore, continue anyways
        }
        s.collectOutOfSync(resources, IResource.DEPTH_INFINITE, set, monitor);
        SyncInfo[] infos = set.getSyncInfos();
        totalChanges = infos.length;
        // New, Removed, and Changed lists.
        for (SyncInfo info : infos) {
            int kind = SyncInfo.getChange(info.getKind());
            PatchFile p = new PatchFile(info.getLocal());
            // for ChangeLog files.
            if (!(p.getPath().lastSegment().equals("ChangeLog"))) {
                // $NON-NLS-1$
                switch(kind) {
                    case SyncInfo.ADDITION:
                        p.setNewfile(true);
                        newList.add(p);
                        break;
                    case SyncInfo.DELETION:
                        p.setRemovedFile(true);
                        removeList.add(p);
                        break;
                    case SyncInfo.CHANGE:
                        if (info.getLocal().getType() == IResource.FILE) {
                            changeList.add(p);
                        }
                        break;
                }
            } else {
                this.changeLogModified = true;
            }
        }
    }
    if (totalChanges == 0)
        // nothing to parse
        return;
    PatchFile[] patchFileInfoList = new PatchFile[totalChanges];
    // Group like changes together and sort them by path name.
    // We want removed files, then new files, then changed files.
    // To get this, we put them in the array in reverse order.
    int index = 0;
    if (changeList.size() > 0) {
        // Get the repository provider so we can support multiple types of
        // code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
        Collections.sort(changeList, new PatchFileComparator());
        int size = changeList.size();
        for (int i = 0; i < size; ++i) {
            PatchFile p = changeList.get(i);
            getChangedLines(s, p, monitor);
            patchFileInfoList[index + (size - i - 1)] = p;
        }
        index += size;
    }
    if (newList.size() > 0) {
        Collections.sort(newList, new PatchFileComparator());
        int size = newList.size();
        for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = newList.get(i);
        index += size;
    }
    if (removeList.size() > 0) {
        Collections.sort(removeList, new PatchFileComparator());
        int size = removeList.size();
        for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = removeList.get(i);
    }
    // now, find out modified functions/classes.
    // try to use the the extension point. so it can be extended easily
    // for all files in patch file info list, get function guesses of each
    // file.
    // $NON-NLS-1$
    monitor.subTask(Messages.getString("ChangeLog.WritingMessage"));
    int unitwork = 250 / patchFileInfoList.length;
    for (PatchFile pf : patchFileInfoList) {
        // for each file
        if (pf != null) {
            // any ChangeLog changes will have null entries for them
            String[] funcGuessList = guessFunctionNames(pf);
            outputMultipleEntryChangeLog(pf, funcGuessList);
        }
        monitor.worked(unitwork);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IProject(org.eclipse.core.resources.IProject) TeamException(org.eclipse.team.core.TeamException) Subscriber(org.eclipse.team.core.subscribers.Subscriber) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) Vector(java.util.Vector) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IResource(org.eclipse.core.resources.IResource)

Example 3 with ISynchronizeModelElement

use of org.eclipse.team.ui.synchronize.ISynchronizeModelElement in project linuxtools by eclipse.

the class PrepareChangelogKeyHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    IStructuredSelection tempResult = null;
    // try getting currently selected project
    IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part instanceof IEditorPart) {
        // If we are in an editor, check if the file being edited is an IResource
        // that belongs to a project in the workspace
        IEditorPart editorPart = (IEditorPart) part;
        IEditorInput input = editorPart.getEditorInput();
        IResource r = input.getAdapter(IResource.class);
        if (r != null) {
            // We have an IResource to work with, so create a selection we can use
            // in PrepareChangeLogAction
            tempResult = new StructuredSelection(r);
        }
    } else {
        // Otherwise, our view is not an editor, see if we have an IResource or something
        // that will lead us to an IResource
        ISelection selected = ref.getSelection();
        if (selected instanceof IStructuredSelection) {
            IResource r = null;
            IStructuredSelection iss = (IStructuredSelection) selected;
            Object o = ((IStructuredSelection) selected).getFirstElement();
            if (o instanceof ISynchronizeModelElement) {
                r = ((ISynchronizeModelElement) o).getResource();
            } else if (o instanceof IAdaptable) {
                r = ((IAdaptable) o).getAdapter(IResource.class);
            }
            if (r != null)
                tempResult = iss;
        }
    }
    if (tempResult == null) {
        // choice to fall back on.
        for (IViewReference view : ref.getViewReferences()) {
            if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
                // $NON-NLS-1$
                IViewPart v = view.getView(false);
                ISelection s = null;
                ISelectionProvider sp = v.getViewSite().getSelectionProvider();
                if (sp != null) {
                    s = sp.getSelection();
                }
                if (s instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) s;
                    Object element = ss.getFirstElement();
                    IResource r = null;
                    if (element instanceof ISynchronizeModelElement) {
                        r = ((ISynchronizeModelElement) element).getResource();
                    } else if (element instanceof IAdaptable) {
                        r = ((IAdaptable) element).getAdapter(IResource.class);
                    }
                    if (r != null) {
                        tempResult = ss;
                    }
                }
            }
        }
    }
    // If we can't find the project directly, let the user know.
    if (tempResult == null) {
        // $NON-NLS-1$,
        MessageDialog.openInformation(// $NON-NLS-1$,
        getActiveWorkbenchShell(), // $NON-NLS-1$,
        Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
        Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
        return null;
    }
    final IStructuredSelection result = tempResult;
    IAction exampleAction = new PrepareChangeLogAction() {

        @Override
        public void run() {
            setSelection(result);
            doRun();
        }
    };
    exampleAction.run();
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IViewPart(org.eclipse.ui.IViewPart) IAction(org.eclipse.jface.action.IAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IViewReference(org.eclipse.ui.IViewReference) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

ISynchronizeModelElement (org.eclipse.team.ui.synchronize.ISynchronizeModelElement)3 IResource (org.eclipse.core.resources.IResource)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 IPath (org.eclipse.core.runtime.IPath)2 Vector (java.util.Vector)1 IDiffElement (org.eclipse.compare.structuremergeviewer.IDiffElement)1 IProject (org.eclipse.core.resources.IProject)1 Path (org.eclipse.core.runtime.Path)1 IAction (org.eclipse.jface.action.IAction)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)1 TeamException (org.eclipse.team.core.TeamException)1 Subscriber (org.eclipse.team.core.subscribers.Subscriber)1 SyncInfo (org.eclipse.team.core.synchronize.SyncInfo)1 SyncInfoSet (org.eclipse.team.core.synchronize.SyncInfoSet)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1