Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
AssetRefreshWorker.java
1 
16 package net.squiz.matrix.ui;
17 
18 import net.squiz.matrix.matrixtree.MatrixTreeNode;
19 import net.squiz.matrix.core.*;
20 import net.squiz.matrix.debug.*;
21 import org.w3c.dom.*;
22 import java.io.IOException;
23 
24 
39 public class AssetRefreshWorker extends MatrixSwingWorker {
40 
41  private String[] assetids;
42  private MatrixTreeNode node;
43  private boolean throwVisibleError = false;
44 
49  public AssetRefreshWorker(boolean throwVisibleError) {
50  assetids = AssetManager.getAllRefreshableAssetids();
51  this.throwVisibleError = throwVisibleError;
52  }
53 
59  public AssetRefreshWorker(String[] assetids, boolean throwVisibleError) {
60  this.assetids = assetids;
61  this.throwVisibleError = throwVisibleError;
62  }
63 
69  public AssetRefreshWorker(MatrixTreeNode node, boolean throwVisibleError) {
70  this.node = node;
71  this.assetids = new String[] { node.getAsset().getId() };
72  this.throwVisibleError = throwVisibleError;
73  }
74 
85  public Object construct() {
86  try {
87  return AssetManager.makeRefreshRequest(assetids, "");
88  } catch(IOException ioe) {
89  return ioe;
90  }
91  }
92 
98  public void finished() {
99  Object get = get();
100 
101  // success!
102  if (get instanceof Element) {
103  Element element = (Element) get;
104  AssetManager.refreshAssets(element);
105 
109  );
110  // we have an error
111  } else if (get instanceof IOException) {
112  IOException ioe = (IOException) get;
113  String message = getErrorMessage() +":" + ioe.getMessage();
114  if (throwVisibleError) {
115  GUIUtilities.error(null, message, getErrorTitle());
116  }
120  );
121  Log.log(message, AssetRefreshWorker.class, ioe);
122  }
123  }
124 
129  public void start() {
131  super.start();
132  }
133 
139  protected String getStatusBarFailMessage() { return Matrix.translate("asset_map_status_bar_failed"); }
140 
146  protected String getStatusBarSuccessMessage() { return Matrix.translate("asset_map_status_bar_success"); }
147 
153  protected String getStatusBarWaitMessage() { return Matrix.translate("asset_map_status_bar_requesting"); }
154 
160  protected String getErrorMessage() { return Matrix.translate("asset_map_status_bar_error_requesting"); }
161 
167  protected String getErrorTitle() { return Matrix.translate("asset_map_status_bar_error_refreshing"); }
168 
174  protected String getLogMessage() { return getErrorMessage(); }
175 
181  protected int getStatusClearTime() { return 1000; }
182 }