cloud work

This commit is contained in:
Branislav Stojkovic
2016-10-22 02:27:12 +02:00
parent 700a09ed86
commit f949fa5087
10 changed files with 102 additions and 57 deletions
@@ -1 +1,2 @@
/bin/
/build/
@@ -0,0 +1,11 @@
package org.diylc.swing.plugins.cloud.presenter;
public class CloudException extends Exception {
private static final long serialVersionUID = 1L;
public CloudException(Exception e) {
super(e);
}
}
@@ -35,16 +35,24 @@ public class CloudPresenter {
this.listener = listener;
}
public boolean logIn(String username, String password) {
public boolean logIn(String username, String password)
throws CloudException {
if (service == null)
return false;
LOG.info("Trying to log in to cloud as " + username);
String res = service.login(username, password, getMachineId());
if (res.equals("Error")) {
LOG.info("Log in failed");
LOG.info("Trying to login to cloud as " + username);
String res;
try {
res = service.login(username, password, getMachineId());
} catch (Exception e) {
throw new CloudException(e);
}
if (res == null || res.equals("Error")) {
LOG.info("Login failed");
return false;
} else {
LOG.info("Log in success");
LOG.info("Login success");
ConfigurationManager.getInstance().writeValue(USERNAME_KEY,
username);
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res);
@@ -54,7 +62,7 @@ public class CloudPresenter {
}
}
public boolean tryLogInWithToken() {
public boolean tryLogInWithToken() throws CloudException {
if (service == null)
return false;
@@ -64,14 +72,18 @@ public class CloudPresenter {
null);
if (username != null && token != null) {
LOG.info("Trying to log in to cloud using a token as " + username);
String res = service
.loginWithToken(username, token, getMachineId());
if (res.equals("Error")) {
LOG.info("Log in failed");
LOG.info("Trying to login to cloud using a token as " + username);
String res;
try {
res = service.loginWithToken(username, token, getMachineId());
} catch (Exception e) {
throw new CloudException(e);
}
if (res == null || res.equals("Error")) {
LOG.info("Login failed");
return false;
} else {
LOG.info("Log in success");
LOG.info("Login success");
listener.loggedIn();
this.loggedIn = true;
return true;
@@ -1,7 +0,0 @@
package org.diylc.swing.plugins.cloud.presenter;
public class DIYLCServiceException extends Exception {
private static final long serialVersionUID = 1L;
}
@@ -1 +1,2 @@
/bin/
/build/
@@ -1,2 +1,6 @@
/bin/
/.apt_generated
/log/
/build/
autoSave.diy
config.xml
@@ -151,8 +151,8 @@ public class DialogFactory {
return dialog;
}
public UploadDialog createUploadDialog(IPlugInPort plugInPort, CloudPresenter presenter) {
UploadDialog dialog = new UploadDialog(mainFrame, plugInPort, presenter);
public UploadDialog createUploadDialog(IPlugInPort plugInPort) {
UploadDialog dialog = new UploadDialog(mainFrame, plugInPort);
return dialog;
}
@@ -50,7 +50,7 @@ import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.editor.PropertyEditorDialog;
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
import org.diylc.swing.plugins.canvas.CanvasPlugin;
import org.diylc.swing.plugins.cloud.OnlineManager;
import org.diylc.swing.plugins.cloud.CloudPlugIn;
import org.diylc.swing.plugins.config.ConfigPlugin;
import org.diylc.swing.plugins.edit.EditMenuPlugin;
import org.diylc.swing.plugins.file.FileFilterEnum;
@@ -99,7 +99,7 @@ public class MainFrame extends JFrame implements ISwingUI {
presenter.installPlugin(new EditMenuPlugin(this));
presenter.installPlugin(new ConfigPlugin(this));
presenter.installPlugin(new LayersMenuPlugin(this));
presenter.installPlugin(new OnlineManager(this));
presenter.installPlugin(new CloudPlugIn(this));
presenter.installPlugin(new HelpMenuPlugin(this));
presenter.installPlugin(new StatusBar(this));
@@ -17,6 +17,7 @@ import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.gui.DummyView;
import org.diylc.swing.plugins.cloud.presenter.CloudException;
import org.diylc.swing.plugins.cloud.presenter.CloudListener;
import org.diylc.swing.plugins.cloud.presenter.CloudPresenter;
import org.diylc.swing.plugins.cloud.view.LoginDialog;
@@ -26,16 +27,16 @@ import org.diylc.swing.plugins.file.FileFilterEnum;
import org.diylc.swingframework.ButtonDialog;
import org.diylc.swingframework.ProgressDialog;
public class OnlineManager implements IPlugIn, CloudListener {
public class CloudPlugIn implements IPlugIn, CloudListener {
private static final String ONLINE_TITLE = "DIY Cloud";
private final static Logger LOG = Logger.getLogger(OnlineManager.class);
private final static Logger LOG = Logger.getLogger(CloudPlugIn.class);
private ISwingUI swingUI;
private IPlugInPort plugInPort;
private IPlugInPort thumbnailPresenter;
private CloudPresenter onlinePresenter;
private CloudPresenter cloudPresenter;
private LibraryAction libraryAction;
@@ -47,12 +48,12 @@ public class OnlineManager implements IPlugIn, CloudListener {
private UploadAction uploadAction;
private ManageProjectsAction manageProjectsAction;
public OnlineManager(ISwingUI swingUI) {
public CloudPlugIn(ISwingUI swingUI) {
super();
this.swingUI = swingUI;
this.thumbnailPresenter = new Presenter(new DummyView());
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getLoginAction(), ONLINE_TITLE);
@@ -62,7 +63,7 @@ public class OnlineManager implements IPlugIn, CloudListener {
swingUI.injectMenuAction(getManageProjectsAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(getManageAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getLogOutAction(), ONLINE_TITLE);
swingUI.injectMenuAction(getLogOutAction(), ONLINE_TITLE);
// default state
getUploadAction().setEnabled(false);
@@ -73,7 +74,7 @@ public class OnlineManager implements IPlugIn, CloudListener {
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
this.onlinePresenter = new CloudPresenter(this);
this.cloudPresenter = new CloudPresenter(this);
initialize();
}
@@ -83,11 +84,12 @@ public class OnlineManager implements IPlugIn, CloudListener {
@Override
public Boolean doInBackground() throws Exception {
return onlinePresenter.tryLogInWithToken();
return cloudPresenter.tryLogInWithToken();
}
@Override
public void failed(Exception e) {
LOG.error("Error while trying to login using token");
}
@Override
@@ -139,8 +141,7 @@ public class OnlineManager implements IPlugIn, CloudListener {
public UploadAction getUploadAction() {
if (uploadAction == null) {
uploadAction = new UploadAction(this.thumbnailPresenter,
this.swingUI, this.onlinePresenter);
uploadAction = new UploadAction();
}
return uploadAction;
}
@@ -193,15 +194,22 @@ public class OnlineManager implements IPlugIn, CloudListener {
do {
dialog.setVisible(true);
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
if (onlinePresenter.logIn(dialog.getUserName(),
dialog.getPassword())) {
try {
if (cloudPresenter.logIn(dialog.getUserName(),
dialog.getPassword())) {
swingUI.showMessage(
"You have successfully logged into the system. You will remain logged in from this machine until logged out.",
"Login Successful",
IView.INFORMATION_MESSAGE);
break;
} else {
swingUI.showMessage(
"Could not login. Possible reasons are wrong credentials or lack of internet connection.",
"Login Error", IView.ERROR_MESSAGE);
}
} catch (CloudException e1) {
swingUI.showMessage(
"You have successfully logged into the system. You will remain logged in on this machine until logged out.",
"Login Successful", IView.INFORMATION_MESSAGE);
break;
} else {
swingUI.showMessage(
"Could not login. Possible reasons are wrong credentials or lack of internet connection.",
"Could not login. Error: " + e1.getMessage(),
"Login Error", IView.ERROR_MESSAGE);
}
} else
@@ -222,7 +230,7 @@ public class OnlineManager implements IPlugIn, CloudListener {
@Override
public void actionPerformed(ActionEvent e) {
onlinePresenter.logOut();
cloudPresenter.logOut();
}
}
@@ -266,15 +274,8 @@ public class OnlineManager implements IPlugIn, CloudListener {
private static final long serialVersionUID = 1L;
private IPlugInPort plugInPort;
private ISwingUI swingUI;
private CloudPresenter onlinePresenter;
public UploadAction(IPlugInPort plugInPort, ISwingUI swingUI, CloudPresenter onlinePresenter) {
public UploadAction() {
super();
this.plugInPort = plugInPort;
this.swingUI = swingUI;
this.onlinePresenter = onlinePresenter;
putValue(AbstractAction.NAME, "Upload A Project");
putValue(AbstractAction.SMALL_ICON, IconLoader.CloudUp.getIcon());
}
@@ -292,14 +293,15 @@ public class OnlineManager implements IPlugIn, CloudListener {
@Override
public Void doInBackground() throws Exception {
LOG.debug("Uploading from " + file.getAbsolutePath());
plugInPort.loadProjectFromFile(file.getAbsolutePath());
thumbnailPresenter.loadProjectFromFile(file
.getAbsolutePath());
return null;
}
@Override
public void complete(Void result) {
UploadDialog dialog = DialogFactory.getInstance()
.createUploadDialog(UploadAction.this.plugInPort, UploadAction.this.onlinePresenter);
.createUploadDialog(thumbnailPresenter);
dialog.setVisible(true);
}
@@ -12,10 +12,13 @@ import java.util.EnumSet;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -30,7 +33,7 @@ public class UploadDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
private static final String BULLET = "   • ";
private static final String TERMS_HTML = "<html><b>Terms of Service</b><br><br>"
private static final String TERMS_HTML = "<html>"
+ BULLET
+ "All content uploaded to DIY Cloud is shared under Creative Commons 3.0 Licence.<br>"
+ BULLET
@@ -43,14 +46,16 @@ public class UploadDialog extends ButtonDialog {
private JLabel termsLabel;
private JCheckBox agreeBox;
private JPanel thumbnailPanel;
private JTextField nameField;
private JComboBox categoryBox;
private JTextArea descriptionArea;
private JTextField keywordsField;
private IPlugInPort plugInPort;
private CloudPresenter presenter;
public UploadDialog(JFrame owner, IPlugInPort plugInPort, CloudPresenter presenter) {
public UploadDialog(JFrame owner, IPlugInPort plugInPort) {
super(owner, "Upload A Project", new String[] { OK, CANCEL });
this.plugInPort = plugInPort;
this.presenter = presenter;
layoutGui();
refreshState();
}
@@ -171,4 +176,20 @@ public class UploadDialog extends ButtonDialog {
}
return thumbnailPanel;
}
public JTextField getNameField() {
return nameField;
}
public JComboBox getCategoryBox() {
return categoryBox;
}
public JTextArea getDescriptionArea() {
return descriptionArea;
}
public JTextField getKeywordsField() {
return keywordsField;
}
}