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.IResource;
038:
039: import org.eclipse.jface.action.IAction;
040: import org.eclipse.jface.dialogs.MessageDialog;
041: import org.eclipse.jface.viewers.ISelection;
042: import org.eclipse.jface.viewers.IStructuredSelection;
043:
044: import org.eclipse.ui.IObjectActionDelegate;
045: import org.eclipse.ui.IWorkbenchPart;
046:
047: import org.libresource.so6.plugin.compare.So6RefCopyCompareInput;
048: import org.libresource.so6.plugin.core.So6Util;
049:
050: /**
051: * @author Guillaume Bort
052: */
053: import java.util.ArrayList;
054: import java.util.Iterator;
055: import java.util.List;
056:
057: /**
058: * DOCUMENT ME!
059: *
060: * @author $author$
061: * @version $Revision: 1.3 $
062: */
063: public class CompareWithRefCopy implements IObjectActionDelegate {
064: private IWorkbenchPart targetPart;
065: private List selected = new ArrayList();
066:
067: /**
068: * DOCUMENT ME!
069: *
070: * @param action DOCUMENT ME!
071: */
072: public void run(IAction action) {
073: try {
074: Iterator iter = selected.iterator();
075:
076: while (iter.hasNext()) {
077: IResource resource = (IResource) iter.next();
078: So6RefCopyCompareInput input = new So6RefCopyCompareInput(
079: resource);
080: CompareUI.openCompareEditor(input);
081: }
082: } catch (Exception e) {
083: MessageDialog.openError(this .targetPart.getSite()
084: .getShell(), "Error", e.getMessage());
085: }
086: }
087:
088: /**
089: * DOCUMENT ME!
090: *
091: * @param action DOCUMENT ME!
092: * @param selection DOCUMENT ME!
093: */
094: public void selectionChanged(IAction action, ISelection selection) {
095: try {
096: selected.clear();
097:
098: if (selection instanceof IStructuredSelection) {
099: boolean enabled = false;
100: Iterator iter = ((IStructuredSelection) selection)
101: .iterator();
102:
103: while (iter.hasNext()) {
104: Object obj = iter.next();
105: IResource resource = (IResource) obj;
106:
107: if (So6Util.isSo6Project(resource.getProject())
108: && So6Util.existRefCopy(resource)) {
109: selected.add(resource);
110: enabled = true;
111: }
112: }
113:
114: action.setEnabled(enabled);
115: }
116: } catch (Exception e) {
117: e.printStackTrace();
118: }
119: }
120:
121: /**
122: * DOCUMENT ME!
123: *
124: * @param action DOCUMENT ME!
125: * @param targetPart DOCUMENT ME!
126: */
127: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
128: this.targetPart = targetPart;
129: }
130: }
|