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.core.resources.IProject;
036: import org.eclipse.core.resources.IResource;
037:
038: import org.eclipse.jdt.core.IJavaProject;
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.core.So6Util;
049: import org.libresource.so6.plugin.ui.So6ResourceUILabelDecorator;
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 AddToIgnoreFile 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: So6Util.addToIgnoreFile(resource);
080: So6ResourceUILabelDecorator.update();
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:
106: if (obj instanceof IJavaProject) {
107: obj = ((IJavaProject) obj).getProject();
108: }
109:
110: if (!(obj instanceof IProject)) {
111: if (So6Util.isSo6Project(((IResource) obj)
112: .getProject())
113: && !So6Util.isIgnored((IResource) obj)) {
114: selected.add((IResource) obj);
115: enabled = true;
116: }
117: }
118: }
119:
120: action.setEnabled(enabled);
121: }
122: } catch (Exception e) {
123: e.printStackTrace();
124: }
125: }
126:
127: /**
128: * DOCUMENT ME!
129: *
130: * @param action DOCUMENT ME!
131: * @param targetPart DOCUMENT ME!
132: */
133: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
134: this.targetPart = targetPart;
135: }
136: }
|