do not block the UI at startup

This commit is contained in:
bancika
2017-04-27 11:40:18 +02:00
parent b2501ccba1
commit ddfb64f1a4
8 changed files with 31 additions and 27 deletions
@@ -8,7 +8,6 @@ import java.util.Properties;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.ConfigurationManager;
@@ -35,8 +34,6 @@ public class DIYLCStarter {
* @param args
*/
public static void main(String[] args) {
// System.setProperty("app.root", System.getProperty("user.home") + File.separator + ".diylc" + File.separator);
URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
try {
@@ -271,7 +271,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -348,7 +348,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -394,7 +394,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
} else {
swingUI.executeBackgroundTask(new ITask<Void>() {
@@ -413,7 +413,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -460,7 +460,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -526,7 +526,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not export to PDF. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -569,7 +569,7 @@ public class ActionFactory {
public void failed(Exception e) {
swingUI.showMessage("Could not export to PNG. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
}
@@ -70,11 +70,12 @@ public interface ISwingUI extends IView {
void injectDynamicSubmenu(String name, Icon icon, String parentMenuName, IDynamicSubmenuHandler handler);
/**
* Runs a task in background while showing busy cursor and a glass pane.
* Runs a task in background while showing busy cursor and a glass pane if needed.
*
* @param task
* @param blockUI
*/
<T extends Object> void executeBackgroundTask(ITask<T> task);
<T extends Object> void executeBackgroundTask(ITask<T> task, boolean blockUI);
/**
* @return {@link JFrame} that can be used to reference secondary dialogs and frames
@@ -221,7 +221,8 @@ public class MainFrame extends JFrame implements ISwingUI {
@Override
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Selection", true);
PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(properties, "Edit Selection", true);
editor.setVisible(true);
defaultedProperties.addAll(editor.getDefaultedProperties());
return ButtonDialog.OK.equals(editor.getSelectedButtonCaption());
@@ -350,8 +351,9 @@ public class MainFrame extends JFrame implements ISwingUI {
}
@Override
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
getGlassPane().setVisible(true);
public <T extends Object> void executeBackgroundTask(final ITask<T> task, boolean blockUI) {
if (blockUI)
getGlassPane().setVisible(true);
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
@Override
@@ -108,7 +108,7 @@ public class CloudPlugIn implements IPlugIn {
LOG.error("Error while trying to login with token", e);
}
}
});
}, false);
}
public CloudBrowserFrame getCloudBrowser() {
@@ -292,7 +292,7 @@ public class CloudPlugIn implements IPlugIn {
public void complete(Void result) {
swingUI.showMessage("Cloud account created successfully.", "Cloud", IView.INFORMATION_MESSAGE);
}
});
}, true);
}
}
}
@@ -332,7 +332,7 @@ public class CloudPlugIn implements IPlugIn {
public void complete(Void result) {
swingUI.showMessage("Cloud account updated successfully.", "Cloud", IView.INFORMATION_MESSAGE);
}
});
}, true);
}
} catch (CloudException e1) {
swingUI.showMessage("Failed to retreive user details from the server. Error: " + e1.getMessage(),
@@ -374,7 +374,7 @@ public class CloudPlugIn implements IPlugIn {
public void complete(Void result) {
swingUI.showMessage("Password updated.", "Cloud", IView.INFORMATION_MESSAGE);
}
});
}, true);
}
}
}
@@ -444,10 +444,10 @@ public class CloudPlugIn implements IPlugIn {
synchronized (taskIterator) {
if (taskIterator.hasPrevious())
swingUI.executeBackgroundTask(taskIterator.previous());
swingUI.executeBackgroundTask(taskIterator.previous(), true);
}
}
});
}, true);
} else {
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.",
"Upload Error", IView.ERROR_MESSAGE);
@@ -467,7 +467,7 @@ public class CloudPlugIn implements IPlugIn {
synchronized (taskIterator) {
if (taskIterator.hasPrevious())
swingUI.executeBackgroundTask(taskIterator.previous());
swingUI.executeBackgroundTask(taskIterator.previous(), true);
}
}
}
@@ -176,7 +176,7 @@ public class ResultsScrollPanel extends JScrollPane {
LOG.info("Paging mechanism is armed");
armed = true;
}
});
});
if (searchSession != null && searchSession.hasMoreData()) {
getLoadMoreLabel().setText("Querying the cloud for more results...");
@@ -298,7 +298,7 @@ public class ResultsScrollPanel extends JScrollPane {
mainUI.showMessage("Could not open file. Detailed message is in the logs.", "Error",
ISwingUI.ERROR_MESSAGE);
}
});
}, true);
}
}
@@ -127,7 +127,7 @@ public class StatusBar extends JPanel implements IPlugIn {
}
}
});
}, false);
}
private JComboBox getZoomBox() {
@@ -206,7 +206,7 @@ public class StatusBar extends JPanel implements IPlugIn {
IView.INFORMATION_MESSAGE);
}
});
}, true);
}
});
}
+5 -1
View File
@@ -1765,7 +1765,11 @@
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>'Tilde' key repeats the last added component</description>
</org.diylc.appframework.update.Change>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Do not block the UI while checking for new version at startup (can be problematic when there's connectivity issues)</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>