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 Commit 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: if (!So6Util.isUpToDate(project)) {
080: throw new Exception(
081: "You are not up to date. Please update your replica first.");
082: }
083:
084: So6Util.commit(project);
085: }
086: }
087: } catch (Exception e) {
088: MessageDialog.openError(this .targetPart.getSite()
089: .getShell(), "Error during commit", e.getMessage());
090: }
091: }
092:
093: /**
094: * DOCUMENT ME!
095: *
096: * @param action DOCUMENT ME!
097: * @param selection DOCUMENT ME!
098: */
099: public void selectionChanged(IAction action, ISelection selection) {
100: try {
101: selected.clear();
102:
103: if (selection instanceof IStructuredSelection) {
104: boolean enabled = true;
105: Iterator iter = ((IStructuredSelection) selection)
106: .iterator();
107:
108: while (iter.hasNext()) {
109: Object obj = iter.next();
110:
111: if (obj instanceof IJavaProject) {
112: obj = ((IJavaProject) obj).getProject();
113: }
114:
115: if (obj instanceof IProject) {
116: IProject project = (IProject) obj;
117:
118: try {
119: So6Util.checkIfSo6PropertiesExist(project);
120:
121: if (!project.isOpen()) {
122: enabled = false;
123:
124: break;
125: } else {
126: selected.add(project);
127: }
128: } catch (Exception e) {
129: enabled = false;
130: }
131: } else {
132: enabled = false;
133:
134: break;
135: }
136: }
137:
138: action.setEnabled(enabled);
139: }
140: } catch (Exception e) {
141: e.printStackTrace();
142: }
143: }
144:
145: /**
146: * DOCUMENT ME!
147: *
148: * @param action DOCUMENT ME!
149: * @param targetPart DOCUMENT ME!
150: */
151: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
152: this.targetPart = targetPart;
153: }
154: }
|