18 package org.turro.wd.desktop;
20 import java.net.URLDecoder;
21 import java.text.ParseException;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.apache.pivot.collections.Map;
25 import org.apache.pivot.util.Resources;
26 import org.apache.pivot.util.concurrent.Task;
27 import org.apache.pivot.util.concurrent.TaskExecutionException;
28 import org.apache.pivot.util.concurrent.TaskListener;
29 import org.apache.pivot.wtk.Application;
30 import org.apache.pivot.wtk.Button;
31 import org.apache.pivot.wtk.ButtonGroup;
32 import org.apache.pivot.wtk.ButtonPressListener;
33 import org.apache.pivot.wtk.DesktopApplicationContext;
34 import org.apache.pivot.wtk.Dialog;
35 import org.apache.pivot.wtk.Display;
36 import org.apache.pivot.wtk.PushButton;
37 import org.apache.pivot.wtk.TaskAdapter;
38 import org.apache.pivot.wtk.TextInput;
39 import org.apache.pivot.wtk.TreeView;
40 import org.apache.pivot.wtk.Window;
41 import org.apache.pivot.wtk.content.TreeNode;
42 import org.apache.pivot.wtkx.WTKX;
43 import org.apache.pivot.wtkx.WTKXSerializer;
44 import org.turro.pivot.dialog.ProgressSheet;
45 import org.turro.wd.entities.WdRuntime;
46 import org.turro.wd.files.WorkingDirectory;
47 import org.turro.wd.tree.DelTask;
48 import org.turro.wd.tree.RefreshTask;
49 import org.turro.wd.tree.SyncTask;
50 import org.turro.wd.tree.TreeDirectory;
51 import org.turro.wd.tree.TreeUtil;
52 import org.turro.wd.tree.TreeWorkFile;
53 import org.turro.wd.tree.WorkingTreeModel;
57 private Window window =
null;
58 private Dialog commit =
null;
59 @WTKX
private TreeView workingTreeView;
60 @WTKX
private PushButton syncButton, openButton, refreshButton,
61 deleteButton, doSyncButton;
62 @WTKX
private TextInput commentUpdateInput, commentCommitInput;
63 @WTKX
private ButtonGroup updateAction, commitAction;
67 public void startup(Display display, Map<String, String> properties)
70 final String bbUser = properties.get(
"bbUser");
71 final String bbHost = properties.get(
"bbHost");
72 final String bbPort = properties.get(
"bbPort");
73 final String bbContext = properties.get(
"bbContext");
74 final String bbCreateDir = URLDecoder.decode(properties.get(
"bbCreateDir"),
"UTF-8");
75 final String bbCreatePath = URLDecoder.decode(properties.get(
"bbCreatePath"),
"UTF-8");
84 final Resources resources =
new Resources(getClass().getName());
86 WTKXSerializer wtkxSerializer =
new WTKXSerializer(resources);
87 window = (Window) wtkxSerializer.readObject(
this,
"working_desktop.wtkx");
90 commit = (Dialog) wtkxSerializer.readObject(
this,
"commit_dialog.wtkx");
95 syncButton.getButtonPressListeners().add(
new ButtonPressListener() {
97 public void buttonPressed(Button button) {
98 commit.setModal(
true);
103 doSyncButton.getButtonPressListeners().add(
new ButtonPressListener() {
104 public void buttonPressed(Button button) {
107 SyncTask syncTask =
new SyncTask(workingTreeView, resources.getString(
"synchronize"),
108 commentCommitInput.getText(),
getSelection(commitAction),
109 commentUpdateInput.getText(),
getSelection(updateAction));
110 TaskListener<String> taskListener =
new TaskListener<String>() {
113 public void taskExecuted(Task<String> task) {
115 workingDirectory.
reload();
118 System.out.println(
"Synchronous task execution complete: \"" + task.getResult() +
"\"");
119 }
catch (ParseException ex) {
120 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
125 public void executeFailed(Task<String> task) {
127 workingDirectory.
reload();
130 System.err.println(task.getFault());
131 }
catch (ParseException ex) {
132 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
137 syncTask.
execute(
new TaskAdapter<String>(taskListener));
141 openButton.getButtonPressListeners().add(
new ButtonPressListener() {
143 public void buttonPressed(Button button) {
144 TreeNode tn = (TreeNode) workingTreeView.getSelectedNode();
146 WdRuntime.launch(((
TreeDirectory) tn).getDirectory().getSystemFile().getAbsolutePath());
148 WdRuntime.launch(((
TreeWorkFile) tn).getWorkFile().getSystemFile().getAbsolutePath());
153 refreshButton.getButtonPressListeners().add(
new ButtonPressListener() {
155 public void buttonPressed(Button button) {
159 public Object execute()
throws TaskExecutionException {
161 workingDirectory.
reload();
164 }
catch (Exception ex) {
165 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
175 deleteButton.getButtonPressListeners().add(
new ButtonPressListener() {
177 public void buttonPressed(Button button) {
178 DelTask delTask =
new DelTask(workingTreeView, resources.getString(
"deleteLocally"));
179 TaskListener<String> taskListener =
new TaskListener<String>() {
182 public void taskExecuted(Task<String> task) {
184 workingDirectory.
reload();
187 System.out.println(
"Deletion task execution complete: \"" + task.getResult() +
"\"");
188 }
catch (ParseException ex) {
189 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
194 public void executeFailed(Task<String> task) {
196 workingDirectory.
reload();
199 System.err.println(task.getFault());
200 }
catch (ParseException ex) {
201 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
206 delTask.
execute(
new TaskAdapter<String>(taskListener));
210 window.open(display);
215 public Object execute()
throws TaskExecutionException {
218 workingDirectory.
initialize(bbCreateDir, bbCreatePath);
219 workingTreeView.setCheckmarksEnabled(
true);
220 workingTreeView.setSelectMode(TreeView.SelectMode.SINGLE);
221 workingTreeView.setShowMixedCheckmarkState(
true);
224 }
catch (ParseException ex) {
225 Logger.getLogger(
WorkingDesktop.class.getName()).log(Level.SEVERE,
null, ex);
234 public boolean shutdown(
boolean optional)
throws Exception {
235 if (window !=
null) {
249 public static void main(String[] args) {
254 Button b = group.getSelection();
256 return new Integer((String) b.getUserData().get(
"value"));
static ProgressSheet getInstance()
int getSelection(ButtonGroup group)
boolean shutdown(boolean optional)
static void main(String[] args)
void startup(Display display, Map< String, String > properties)
void initialize(String bbCreateDir, String bbCreatePath)
static void expandRootBranches(TreeView tree)