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:
037: import org.eclipse.jdt.core.IJavaProject;
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: import org.eclipse.jface.wizard.WizardDialog;
044:
045: import org.eclipse.ui.IObjectActionDelegate;
046: import org.eclipse.ui.IWorkbenchPart;
047: import org.eclipse.ui.internal.Workbench;
048:
049: import org.libresource.so6.plugin.core.So6Util;
050: import org.libresource.so6.plugin.wizards.EditIgnoreFileWizard;
051:
052: /**
053: * @author Guillaume Bort
054: */
055: import java.util.ArrayList;
056: import java.util.Iterator;
057: import java.util.List;
058:
059: /**
060: * DOCUMENT ME!
061: *
062: * @author $author$
063: * @version $Revision: 1.3 $
064: */
065: public class EditIgnoreFile implements IObjectActionDelegate {
066: private IWorkbenchPart targetPart;
067: private List selected = new ArrayList();
068:
069: /**
070: * DOCUMENT ME!
071: *
072: * @param action DOCUMENT ME!
073: */
074: public void run(IAction action) {
075: try {
076: Iterator iter = selected.iterator();
077:
078: while (iter.hasNext()) {
079: IProject project = (IProject) iter.next();
080:
081: if (So6Util.isSo6Project(project)) {
082: EditIgnoreFileWizard wizard = new EditIgnoreFileWizard(
083: project);
084: WizardDialog dialog = new WizardDialog(Workbench
085: .getInstance().getActiveWorkbenchWindow()
086: .getShell(), wizard);
087: dialog.open();
088: }
089: }
090: } catch (Exception e) {
091: MessageDialog.openError(this .targetPart.getSite()
092: .getShell(), "Error during commit", e.getMessage());
093: }
094: }
095:
096: /**
097: * DOCUMENT ME!
098: *
099: * @param action DOCUMENT ME!
100: * @param selection DOCUMENT ME!
101: */
102: public void selectionChanged(IAction action, ISelection selection) {
103: try {
104: selected.clear();
105:
106: if (selection instanceof IStructuredSelection) {
107: boolean enabled = true;
108: Iterator iter = ((IStructuredSelection) selection)
109: .iterator();
110:
111: while (iter.hasNext()) {
112: Object obj = iter.next();
113:
114: if (obj instanceof IJavaProject) {
115: obj = ((IJavaProject) obj).getProject();
116: }
117:
118: if (obj instanceof IProject) {
119: IProject project = (IProject) obj;
120:
121: if (!project.isOpen()) {
122: enabled = false;
123:
124: break;
125: } else {
126: selected.add(project);
127: }
128: } else {
129: enabled = false;
130:
131: break;
132: }
133: }
134:
135: action.setEnabled(enabled);
136: }
137: } catch (Exception e) {
138: e.printStackTrace();
139: }
140: }
141:
142: /**
143: * DOCUMENT ME!
144: *
145: * @param action DOCUMENT ME!
146: * @param targetPart DOCUMENT ME!
147: */
148: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
149: this.targetPart = targetPart;
150: }
151: }
|