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 com.artenum.so6.dataflow;
034:
035: import com.artenum.so6.dataflow.util.CreateWorkspace;
036:
037: import org.libresource.so6.core.exec.ui.Commit;
038: import org.libresource.so6.core.exec.ui.Update;
039:
040: import java.awt.BorderLayout;
041: import java.awt.Color;
042:
043: import java.io.File;
044:
045: import java.net.URL;
046:
047: import javax.swing.JFrame;
048:
049: /**
050: * @author Sebastien
051: */
052: public class ActionManager {
053: private static ActionManager manager;
054: private Dataflow dataflow;
055: private String uri;
056: private String url;
057: private ClientIHttpClient client;
058: private boolean reloadable = false;
059: private boolean working = false;
060:
061: private ActionManager() {
062: }
063:
064: public static ActionManager getInstance() {
065: if (manager == null) {
066: manager = new ActionManager();
067: }
068:
069: return manager;
070: }
071:
072: public void startWorking() {
073: working = true;
074: }
075:
076: public void stopWorking() {
077: working = false;
078: }
079:
080: public void commit(String wscPath) {
081: if (working) {
082: return;
083: }
084:
085: startWorking();
086:
087: try {
088: Commit commit = new Commit(wscPath);
089: commit.setStyle(Color.white, Color.decode("#eeeeee"));
090:
091: JFrame f = new JFrame("Commit on connection: " + wscPath);
092: f.getContentPane().add(commit, BorderLayout.CENTER);
093: f.setSize(400, 215);
094: f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
095: f.setLocationRelativeTo(null);
096: commit.setCloser(new WindowCloser(f));
097: f.setVisible(true);
098: } catch (Exception e) {
099: e.printStackTrace();
100: stopWorking();
101: }
102: }
103:
104: public void update(String wscPath) {
105: if (working) {
106: return;
107: }
108:
109: startWorking();
110:
111: try {
112: Update update = new Update(wscPath);
113: update.setStyle(Color.white, Color.decode("#eeeeee"));
114:
115: JFrame f = new JFrame("Update connection: " + wscPath);
116: f.getContentPane().add(update, BorderLayout.CENTER);
117: f.setSize(400, 215);
118: f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
119: f.setLocationRelativeTo(null);
120: update.setCloser(new WindowCloser(f));
121: f.setVisible(true);
122: } catch (Exception e) {
123: e.printStackTrace();
124: stopWorking();
125: }
126: }
127:
128: public void connectWorkspace(String queueId) {
129: if (working) {
130: return;
131: }
132:
133: startWorking();
134:
135: String basePath = "";
136: String login = "";
137: String password = "";
138: String wsName = "";
139:
140: try {
141: new CreateWorkspace(queueId, ClientIHttpClient.class
142: .getName());
143: reload();
144: } catch (Exception e) {
145: e.printStackTrace();
146: stopWorking();
147: }
148: }
149:
150: public void setDataflow(Dataflow dataflow) {
151: this .dataflow = dataflow;
152: }
153:
154: public void setReloadFromURL(String url) {
155: reloadable = true;
156: this .url = url;
157: }
158:
159: public void setReloadFromClient(ClientIHttpClient client, String uri) {
160: reloadable = true;
161: this .client = client;
162: this .uri = uri;
163: }
164:
165: public void reload() throws Exception {
166: if ((dataflow != null) && reloadable) {
167: if (client != null) {
168: dataflow
169: .load(new File(client.getNetworkFromQueue(uri)));
170: } else {
171: dataflow.load(new URL(url).openStream());
172: }
173: }
174: }
175: }
|