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.team.core.RepositoryProvider;
045:
046: import org.eclipse.ui.IObjectActionDelegate;
047: import org.eclipse.ui.IWorkbenchPart;
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 Disconnect 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: RepositoryProvider.unmap(project);
078: }
079: } catch (Exception e) {
080: MessageDialog.openError(this .targetPart.getSite()
081: .getShell(), "Error during disconnect", e
082: .getMessage());
083: }
084: }
085:
086: /**
087: * DOCUMENT ME!
088: *
089: * @param action DOCUMENT ME!
090: * @param selection DOCUMENT ME!
091: */
092: public void selectionChanged(IAction action, ISelection selection) {
093: try {
094: selected.clear();
095:
096: if (selection instanceof IStructuredSelection) {
097: boolean enabled = true;
098: Iterator iter = ((IStructuredSelection) selection)
099: .iterator();
100:
101: while (iter.hasNext()) {
102: Object obj = iter.next();
103:
104: if (obj instanceof IJavaProject) {
105: obj = ((IJavaProject) obj).getProject();
106: }
107:
108: if (obj instanceof IProject) {
109: IProject project = (IProject) obj;
110:
111: try {
112: if (!project.isOpen()) {
113: enabled = false;
114:
115: break;
116: } else {
117: selected.add(project);
118: }
119: } catch (Exception e) {
120: enabled = false;
121: }
122: } else {
123: enabled = false;
124:
125: break;
126: }
127: }
128:
129: action.setEnabled(enabled);
130: }
131: } catch (Exception e) {
132: e.printStackTrace();
133: }
134: }
135:
136: /**
137: * DOCUMENT ME!
138: *
139: * @param action DOCUMENT ME!
140: * @param targetPart DOCUMENT ME!
141: */
142: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
143: this.targetPart = targetPart;
144: }
145: }
|