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:
044: import org.eclipse.ui.IObjectActionDelegate;
045: import org.eclipse.ui.IWorkbenchPart;
046:
047: import org.libresource.so6.plugin.core.So6Util;
048:
049: /**
050: * @author Guillaume Bort
051: */
052: import java.util.ArrayList;
053: import java.util.Iterator;
054: import java.util.List;
055:
056: /**
057: * DOCUMENT ME!
058: *
059: * @author $author$
060: * @version $Revision: 1.3 $
061: */
062: public class Update implements IObjectActionDelegate {
063: private IWorkbenchPart targetPart;
064: private List selected = new ArrayList();
065:
066: /**
067: * DOCUMENT ME!
068: *
069: * @param action DOCUMENT ME!
070: */
071: public void run(IAction action) {
072: try {
073: Iterator iter = selected.iterator();
074:
075: while (iter.hasNext()) {
076: IProject project = (IProject) iter.next();
077:
078: if (So6Util.isSo6Project(project)) {
079: So6Util.update(project);
080: }
081: }
082: } catch (Exception e) {
083: MessageDialog.openError(this .targetPart.getSite()
084: .getShell(), "Error during update", 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 = true;
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: IProject project = (IProject) obj;
112:
113: try {
114: So6Util.checkIfSo6PropertiesExist(project);
115:
116: if (!project.isOpen()) {
117: enabled = false;
118:
119: break;
120: } else {
121: selected.add(project);
122: }
123: } catch (Exception e) {
124: enabled = false;
125: }
126: } else {
127: enabled = false;
128:
129: break;
130: }
131: }
132:
133: action.setEnabled(enabled);
134: }
135: } catch (Exception e) {
136: e.printStackTrace();
137: }
138: }
139:
140: /**
141: * DOCUMENT ME!
142: *
143: * @param action DOCUMENT ME!
144: * @param targetPart DOCUMENT ME!
145: */
146: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
147: this.targetPart = targetPart;
148: }
149: }
|