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.core.exec.ui;
034:
035: import org.libresource.so6.core.WsConnection;
036: import org.libresource.so6.core.interfaces.Closer;
037: import org.libresource.so6.core.ui.MultipleView;
038: import org.libresource.so6.core.ui.TextFieldView;
039: import org.libresource.so6.core.ui.TextView;
040: import org.libresource.so6.core.ui.util.StyledUI;
041: import org.libresource.so6.core.ui.util.Wizard;
042: import org.libresource.so6.core.ui.util.WizardListener;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Color;
046: import java.awt.Toolkit;
047: import java.awt.event.WindowAdapter;
048: import java.awt.event.WindowEvent;
049:
050: import javax.swing.JFrame;
051: import javax.swing.JOptionPane;
052: import javax.swing.JPanel;
053:
054: /**
055: * @author smack
056: */
057: public class Rename extends JPanel implements WizardListener, StyledUI {
058: private TextFieldView oldPath;
059: private TextFieldView newPath;
060: private MultipleView view;
061: private TextView text;
062: private String wscPath;
063:
064: //
065: private boolean jobDone = false;
066:
067: //
068: private Wizard wizard;
069:
070: public Rename(String wscPath, String from, String to)
071: throws Exception {
072: this .wscPath = wscPath;
073:
074: // Make views
075: view = new MultipleView("Rename");
076: oldPath = new TextFieldView("Source file");
077: newPath = new TextFieldView("Destination file");
078:
079: //
080: if (from != null) {
081: oldPath.setContent(from);
082: }
083:
084: if (to != null) {
085: newPath.setContent(to);
086: }
087:
088: //
089: view.addView(oldPath);
090: view.addView(newPath);
091: text = new TextView("Report");
092: text.setContent("Rename currently working");
093: text.setEditable(false);
094:
095: //
096: wizard = new Wizard(this );
097: wizard.addComponent(view);
098: wizard.addComponent(text);
099: wizard.renderView(0);
100: wizard.renderButtons();
101:
102: //
103: setLayout(new BorderLayout());
104: add(wizard, BorderLayout.CENTER);
105: }
106:
107: public void doTheJob() {
108: try {
109: if (!jobDone) {
110: new org.libresource.so6.core.exec.Rename(wscPath,
111: oldPath.getContent(), newPath.getContent());
112: text.setContent("The file " + oldPath.getContent()
113: + " has been renamed to "
114: + newPath.getContent());
115: }
116:
117: jobDone = true;
118: wizard.renderButtons();
119: } catch (Exception e) {
120: e.printStackTrace();
121: text.setContent("Error while trying to rename file "
122: + oldPath.getContent() + " to "
123: + newPath.getContent() + " : " + e.getMessage());
124: JOptionPane.showMessageDialog(this ,
125: "Error while trying to rename file "
126: + oldPath.getContent() + " to "
127: + newPath.getContent() + " : "
128: + e.getMessage());
129: }
130: }
131:
132: public static void main(String[] args) throws Exception {
133: if (args.length != 1) {
134: System.err.println("Usage: wsPath");
135: System.err.println(" (1) wsPath: path of the file "
136: + WsConnection.SO6_WSC_FILE);
137: System.exit(0);
138: }
139:
140: String wscPath = args[0];
141: String src = "";
142: String dst = "";
143: Rename rename = new Rename(wscPath, src, dst);
144: rename.setStyle(Color.white, Color.decode("#eeeeee"));
145:
146: // Make frame
147: JFrame f = new JFrame("Rename a file on " + wscPath);
148: f.getContentPane().add(rename, BorderLayout.CENTER);
149: f.setSize(400, 180);
150: f.addWindowListener(new WindowAdapter() {
151: public void windowClosing(WindowEvent e) {
152: System.exit(0);
153: }
154: });
155: f.setLocation(((int) Toolkit.getDefaultToolkit()
156: .getScreenSize().getWidth() - f.getWidth()) / 2,
157: ((int) Toolkit.getDefaultToolkit().getScreenSize()
158: .getHeight() - f.getHeight()) / 2);
159: f.setVisible(true);
160: }
161:
162: public boolean setCurrentPosition(int currentHistoryPosition) {
163: // ask comment -> commit <-> report
164: if (currentHistoryPosition == 1) {
165: Thread thread = new Thread(new Runnable() {
166: public void run() {
167: doTheJob();
168: }
169: });
170: thread.setPriority(Thread.NORM_PRIORITY);
171: thread.start();
172: } else {
173: wizard.renderButtons();
174: }
175:
176: return false;
177: }
178:
179: public void setStyle(Color back, Color forground) {
180: wizard.setStyle(back, forground);
181: }
182:
183: public void setCloser(Closer closer) {
184: wizard.setCloser(closer);
185: }
186: }
|