001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.plugin.actions;
034:
035: import org.eclipse.compare.CompareUI;
036:
037: import org.eclipse.core.resources.IFile;
038: import org.eclipse.core.resources.IResource;
039:
040: import org.eclipse.jface.action.IAction;
041: import org.eclipse.jface.dialogs.MessageDialog;
042: import org.eclipse.jface.viewers.ISelection;
043: import org.eclipse.jface.viewers.IStructuredSelection;
044:
045: import org.eclipse.ui.IObjectActionDelegate;
046: import org.eclipse.ui.IWorkbenchPart;
047:
048: import org.libresource.so6.plugin.compare.So6HistoryCompareInput;
049: import org.libresource.so6.plugin.core.So6Util;
050:
051: /**
052: * @author Guillaume Bort
053: */
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import java.util.List;
057:
058: /**
059: * DOCUMENT ME!
060: *
061: * @author $author$
062: * @version $Revision: 1.3 $
063: */
064: public class CompareWithHistory implements IObjectActionDelegate {
065: private IWorkbenchPart targetPart;
066: private List selected = new ArrayList();
067:
068: /**
069: * DOCUMENT ME!
070: *
071: * @param action DOCUMENT ME!
072: */
073: public void run(IAction action) {
074: try {
075: Iterator iter = selected.iterator();
076:
077: while (iter.hasNext()) {
078: IResource resource = (IResource) iter.next();
079: So6HistoryCompareInput input = new So6HistoryCompareInput(
080: resource);
081: CompareUI.openCompareEditor(input);
082: }
083: } catch (Exception e) {
084: MessageDialog.openError(this .targetPart.getSite()
085: .getShell(), "Error", e.getMessage());
086: }
087: }
088:
089: /**
090: * DOCUMENT ME!
091: *
092: * @param action DOCUMENT ME!
093: * @param selection DOCUMENT ME!
094: */
095: public void selectionChanged(IAction action, ISelection selection) {
096: try {
097: selected.clear();
098:
099: if (selection instanceof IStructuredSelection) {
100: boolean enabled = false;
101: Iterator iter = ((IStructuredSelection) selection)
102: .iterator();
103:
104: while (iter.hasNext()) {
105: Object obj = iter.next();
106: IResource resource = (IResource) obj;
107:
108: if (So6Util.isSo6Project(resource.getProject())
109: && resource instanceof IFile
110: && So6Util.existRefCopy(resource)) {
111: selected.add(resource);
112: enabled = true;
113: }
114: }
115:
116: action.setEnabled(enabled);
117: }
118: } catch (Exception e) {
119: e.printStackTrace();
120: }
121: }
122:
123: /**
124: * DOCUMENT ME!
125: *
126: * @param action DOCUMENT ME!
127: * @param targetPart DOCUMENT ME!
128: */
129: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
130: this.targetPart = targetPart;
131: }
132: }
|