mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
cloud improvements
This commit is contained in:
@@ -52,6 +52,7 @@ import org.diylc.swing.plugins.cloud.view.UserEditDialog;
|
|||||||
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
|
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
|
||||||
import org.diylc.swing.plugins.cloud.view.browser.UploadManagerFrame;
|
import org.diylc.swing.plugins.cloud.view.browser.UploadManagerFrame;
|
||||||
import org.diylc.swing.plugins.file.FileFilterEnum;
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
import org.diylc.swing.plugins.cloud.actions.*;
|
||||||
|
|
||||||
public class CloudPlugIn implements IPlugIn {
|
public class CloudPlugIn implements IPlugIn {
|
||||||
|
|
||||||
@@ -66,12 +67,10 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
private CloudService cloudService;
|
private CloudService cloudService;
|
||||||
|
|
||||||
private LibraryAction libraryAction;
|
private LibraryAction libraryAction;
|
||||||
|
|
||||||
private LoginAction loginAction;
|
private LoginAction loginAction;
|
||||||
private LogOutAction logOutAction;
|
private LogOutAction logOutAction;
|
||||||
private CreateAccountAction createAccountAction;
|
private CreateAccountAction createAccountAction;
|
||||||
private ManageAccountAction manageAccountAction;
|
private ManageAccountAction manageAccountAction;
|
||||||
|
|
||||||
private UploadAction uploadAction;
|
private UploadAction uploadAction;
|
||||||
private ChangePasswordAction changePasswordAction;
|
private ChangePasswordAction changePasswordAction;
|
||||||
private ManageProjectsAction manageProjectsAction;
|
private ManageProjectsAction manageProjectsAction;
|
||||||
@@ -85,6 +84,16 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||||
this.thumbnailGenerator = new ThumbnailGenerator(thumbnailPresenter);
|
this.thumbnailGenerator = new ThumbnailGenerator(thumbnailPresenter);
|
||||||
|
|
||||||
|
// Initialize actions
|
||||||
|
this.libraryAction = new LibraryAction(this);
|
||||||
|
this.loginAction = new LoginAction(this);
|
||||||
|
this.logOutAction = new LogOutAction(this);
|
||||||
|
this.createAccountAction = new CreateAccountAction(this);
|
||||||
|
this.manageAccountAction = new ManageAccountAction(this);
|
||||||
|
this.uploadAction = new UploadAction(this);
|
||||||
|
this.changePasswordAction = new ChangePasswordAction(this);
|
||||||
|
this.manageProjectsAction = new ManageProjectsAction(this);
|
||||||
|
|
||||||
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
|
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
|
||||||
swingUI.injectMenuAction(null, ONLINE_TITLE);
|
swingUI.injectMenuAction(null, ONLINE_TITLE);
|
||||||
swingUI.injectMenuAction(getLoginAction(), ONLINE_TITLE);
|
swingUI.injectMenuAction(getLoginAction(), ONLINE_TITLE);
|
||||||
@@ -101,6 +110,7 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
getUploadAction().setEnabled(false);
|
getUploadAction().setEnabled(false);
|
||||||
getManageProjectsAction().setEnabled(false);
|
getManageProjectsAction().setEnabled(false);
|
||||||
getManageAccountAction().setEnabled(false);
|
getManageAccountAction().setEnabled(false);
|
||||||
|
getChangePasswordAction().setEnabled(false);
|
||||||
getLogOutAction().setEnabled(false);
|
getLogOutAction().setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,58 +132,34 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LibraryAction getLibraryAction() {
|
public LibraryAction getLibraryAction() {
|
||||||
if (libraryAction == null) {
|
|
||||||
libraryAction = new LibraryAction();
|
|
||||||
}
|
|
||||||
return libraryAction;
|
return libraryAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginAction getLoginAction() {
|
public LoginAction getLoginAction() {
|
||||||
if (loginAction == null) {
|
|
||||||
loginAction = new LoginAction();
|
|
||||||
}
|
|
||||||
return loginAction;
|
return loginAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogOutAction getLogOutAction() {
|
public LogOutAction getLogOutAction() {
|
||||||
if (logOutAction == null) {
|
|
||||||
logOutAction = new LogOutAction();
|
|
||||||
}
|
|
||||||
return logOutAction;
|
return logOutAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateAccountAction getCreateAccountAction() {
|
public CreateAccountAction getCreateAccountAction() {
|
||||||
if (createAccountAction == null) {
|
|
||||||
createAccountAction = new CreateAccountAction();
|
|
||||||
}
|
|
||||||
return createAccountAction;
|
return createAccountAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManageAccountAction getManageAccountAction() {
|
public ManageAccountAction getManageAccountAction() {
|
||||||
if (manageAccountAction == null) {
|
|
||||||
manageAccountAction = new ManageAccountAction();
|
|
||||||
}
|
|
||||||
return manageAccountAction;
|
return manageAccountAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadAction getUploadAction() {
|
public UploadAction getUploadAction() {
|
||||||
if (uploadAction == null) {
|
|
||||||
uploadAction = new UploadAction();
|
|
||||||
}
|
|
||||||
return uploadAction;
|
return uploadAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangePasswordAction getChangePasswordAction() {
|
public ChangePasswordAction getChangePasswordAction() {
|
||||||
if (changePasswordAction == null) {
|
|
||||||
changePasswordAction = new ChangePasswordAction();
|
|
||||||
}
|
|
||||||
return changePasswordAction;
|
return changePasswordAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManageProjectsAction getManageProjectsAction() {
|
public ManageProjectsAction getManageProjectsAction() {
|
||||||
if (manageProjectsAction == null) {
|
|
||||||
manageProjectsAction = new ManageProjectsAction();
|
|
||||||
}
|
|
||||||
return manageProjectsAction;
|
return manageProjectsAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,310 +180,6 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LibraryAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public LibraryAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Search The Cloud");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Cloud.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
getCloudBrowser().setVisible(true);
|
|
||||||
getCloudBrowser().requestFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoginAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public LoginAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Log In");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LoginDialog dialog = DialogFactory.getInstance().createLoginDialog();
|
|
||||||
do {
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
try {
|
|
||||||
if (plugInPort.getCloudService().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);
|
|
||||||
loggedIn();
|
|
||||||
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("Could not login. Error: " + e1.getMessage(), "Login Error", IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
} while (true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LogOutAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public LogOutAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Log Out");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cloudService.logOut();
|
|
||||||
loggedOut();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CreateAccountAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public CreateAccountAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Create New Account");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCardAdd.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(null);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
cloudService.createUserAccount(dialog.getUserName(), dialog.getPassword(), dialog.getEmail(),
|
|
||||||
dialog.getWebsite(), dialog.getBio());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Failed to create the account. Error: " + e.getMessage(), "Cloud Error",
|
|
||||||
IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
swingUI.showMessage("Cloud account created successfully.", "Cloud", IView.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ManageAccountAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ManageAccountAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Manage Account");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCardEdit.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
try {
|
|
||||||
final UserEditDialog dialog =
|
|
||||||
DialogFactory.getInstance().createUserEditDialog(plugInPort.getCloudService().getUserDetails());
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
cloudService.updateUserDetails(dialog.getEmail(), dialog.getWebsite(), dialog.getBio());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Failed to update the account. Error: " + e.getMessage(), "Cloud Error",
|
|
||||||
IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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(),
|
|
||||||
"Cloud Error", IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChangePasswordAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ChangePasswordAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Change Password");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.KeyEdit.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
final ChangePasswordDialog dialog = DialogFactory.getInstance().createChangePasswordDialog();
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
cloudService.updatePassword(dialog.getOldPassword(), dialog.getNewPassword());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Failed to update the password. Error: " + e.getMessage(), "Cloud Error",
|
|
||||||
IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
swingUI.showMessage("Password updated.", "Cloud", IView.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class UploadAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public UploadAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Upload A Project");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.CloudUp.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("UploadAction triggered");
|
|
||||||
|
|
||||||
final File[] files =
|
|
||||||
DialogFactory.getInstance().showOpenMultiDialog(FileFilterEnum.DIY.getFilter(), null,
|
|
||||||
FileFilterEnum.DIY.getExtensions()[0], null, swingUI.getOwnerFrame());
|
|
||||||
if (files != null && files.length > 0) {
|
|
||||||
List<ITask<String[]>> tasks = new ArrayList<ITask<String[]>>();
|
|
||||||
final ListIterator<ITask<String[]>> taskIterator = tasks.listIterator();
|
|
||||||
|
|
||||||
for (final File file : files) {
|
|
||||||
taskIterator.add(new ITask<String[]>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] doInBackground() throws Exception {
|
|
||||||
LOG.debug("Uploading from " + file.getAbsolutePath());
|
|
||||||
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
|
||||||
return cloudService.getCategories();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(final String[] result) {
|
|
||||||
final UploadDialog dialog =
|
|
||||||
DialogFactory.getInstance().createUploadDialog(swingUI.getOwnerFrame(), thumbnailPresenter, result,
|
|
||||||
false);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
try {
|
|
||||||
final File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
|
||||||
if (ImageIO.write(CloudPlugIn.this.thumbnailGenerator.getThumbnail(), "png", thumbnailFile)) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void doInBackground() throws Exception {
|
|
||||||
cloudService.uploadProject(dialog.getName(), dialog.getCategory(), dialog
|
|
||||||
.getDescription(), dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(),
|
|
||||||
thumbnailFile, file, null);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void complete(Void result) {
|
|
||||||
swingUI
|
|
||||||
.showMessage(
|
|
||||||
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
|
||||||
"Upload Success", IView.INFORMATION_MESSAGE);
|
|
||||||
|
|
||||||
synchronized (taskIterator) {
|
|
||||||
if (taskIterator.hasPrevious())
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Exception e) {
|
|
||||||
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (taskIterator) {
|
|
||||||
if (taskIterator.hasPrevious())
|
|
||||||
swingUI.executeBackgroundTask(taskIterator.previous(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ManageProjectsAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public ManageProjectsAction() {
|
|
||||||
super();
|
|
||||||
putValue(AbstractAction.NAME, "Manage My Uploads");
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.CloudGear.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
UploadManagerFrame frame = createUploadManagerFrame();
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loggedIn() {
|
public void loggedIn() {
|
||||||
getLoginAction().setEnabled(false);
|
getLoginAction().setEnabled(false);
|
||||||
getCreateAccountAction().setEnabled(false);
|
getCreateAccountAction().setEnabled(false);
|
||||||
@@ -506,6 +188,7 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
getManageAccountAction().setEnabled(true);
|
getManageAccountAction().setEnabled(true);
|
||||||
getUploadAction().setEnabled(true);
|
getUploadAction().setEnabled(true);
|
||||||
getManageProjectsAction().setEnabled(true);
|
getManageProjectsAction().setEnabled(true);
|
||||||
|
getChangePasswordAction().setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loggedOut() {
|
public void loggedOut() {
|
||||||
@@ -516,5 +199,27 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
getManageAccountAction().setEnabled(false);
|
getManageAccountAction().setEnabled(false);
|
||||||
getUploadAction().setEnabled(false);
|
getUploadAction().setEnabled(false);
|
||||||
getManageProjectsAction().setEnabled(false);
|
getManageProjectsAction().setEnabled(false);
|
||||||
|
getChangePasswordAction().setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters for action classes
|
||||||
|
public ISwingUI getSwingUI() {
|
||||||
|
return swingUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPlugInPort getPlugInPort() {
|
||||||
|
return plugInPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPlugInPort getThumbnailPresenter() {
|
||||||
|
return thumbnailPresenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThumbnailGenerator getThumbnailGenerator() {
|
||||||
|
return thumbnailGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloudService getCloudService() {
|
||||||
|
return cloudService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.swing.plugins.cloud.view.ChangePasswordDialog;
|
||||||
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class ChangePasswordAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = Logger.getLogger(ChangePasswordAction.class);
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public ChangePasswordAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Change Password");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.KeyEdit.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
final ChangePasswordDialog dialog = DialogFactory.getInstance().createChangePasswordDialog();
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(new ITask<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
cloudPlugIn.getCloudService().updatePassword(dialog.getOldPassword(), dialog.getNewPassword());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Failed to update the password. Error: " + e.getMessage(), "Cloud Error",
|
||||||
|
IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Password updated.", "Cloud", IView.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.swing.plugins.cloud.view.UserEditDialog;
|
||||||
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class CreateAccountAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = Logger.getLogger(CreateAccountAction.class);
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public CreateAccountAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Create New Account");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCardAdd.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(null);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(new ITask<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
cloudPlugIn.getCloudService().createUserAccount(dialog.getUserName(), dialog.getPassword(), dialog.getEmail(),
|
||||||
|
dialog.getWebsite(), dialog.getBio());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Failed to create the account. Error: " + e.getMessage(), "Cloud Error",
|
||||||
|
IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Cloud account created successfully!\nPlease check your email and verify your address.", "Cloud", IView.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class LibraryAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public LibraryAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Search The Cloud");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Cloud.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
cloudPlugIn.getCloudBrowser().setVisible(true);
|
||||||
|
cloudPlugIn.getCloudBrowser().requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class LogOutAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public LogOutAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Log Out");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
cloudPlugIn.getCloudService().logOut();
|
||||||
|
cloudPlugIn.loggedOut();
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.plugins.cloud.service.CloudException;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.swing.plugins.cloud.view.LoginDialog;
|
||||||
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class LoginAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = Logger.getLogger(LoginAction.class);
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public LoginAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Log In");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LoginDialog dialog = DialogFactory.getInstance().createLoginDialog();
|
||||||
|
do {
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
try {
|
||||||
|
if (cloudPlugIn.getPlugInPort().getCloudService().logIn(dialog.getUserName(), dialog.getPassword())) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage(
|
||||||
|
"You have successfully logged into the system. You will remain logged in from this machine until logged out.",
|
||||||
|
"Login Successful", IView.INFORMATION_MESSAGE);
|
||||||
|
cloudPlugIn.loggedIn();
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage(
|
||||||
|
"Could not login. Possible reasons are wrong credentials or lack of internet connection.",
|
||||||
|
"Login Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (CloudException e1) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Could not login. Error: " + e1.getMessage(), "Login Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.plugins.cloud.service.CloudException;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.swing.plugins.cloud.view.UserEditDialog;
|
||||||
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class ManageAccountAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = Logger.getLogger(ManageAccountAction.class);
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public ManageAccountAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Manage Account");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCardEdit.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
final UserEditDialog dialog =
|
||||||
|
DialogFactory.getInstance().createUserEditDialog(cloudPlugIn.getPlugInPort().getCloudService().getUserDetails());
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(new ITask<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
cloudPlugIn.getCloudService().updateUserDetails(dialog.getEmail(), dialog.getWebsite(), dialog.getBio());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Failed to update the account. Error: " + e.getMessage(), "Cloud Error",
|
||||||
|
IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Cloud account updated successfully.", "Cloud", IView.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
} catch (CloudException e1) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Failed to retreive user details from the server. Error: " + e1.getMessage(),
|
||||||
|
"Cloud Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class ManageProjectsAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public ManageProjectsAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Manage My Uploads");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.CloudGear.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
cloudPlugIn.createUploadManagerFrame().setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
+134
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.swing.plugins.cloud.actions;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.diylc.common.ITask;
|
||||||
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.plugins.cloud.service.CloudException;
|
||||||
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.cloud.CloudPlugIn;
|
||||||
|
import org.diylc.swing.plugins.cloud.view.UploadDialog;
|
||||||
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
|
import org.diylc.utils.IconLoader;
|
||||||
|
|
||||||
|
public class UploadAction extends AbstractAction {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = Logger.getLogger(UploadAction.class);
|
||||||
|
private final CloudPlugIn cloudPlugIn;
|
||||||
|
|
||||||
|
public UploadAction(CloudPlugIn cloudPlugIn) {
|
||||||
|
super();
|
||||||
|
this.cloudPlugIn = cloudPlugIn;
|
||||||
|
putValue(AbstractAction.NAME, "Upload A Project");
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.CloudUp.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("UploadAction triggered");
|
||||||
|
|
||||||
|
final File[] files =
|
||||||
|
DialogFactory.getInstance().showOpenMultiDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||||
|
FileFilterEnum.DIY.getExtensions()[0], null, cloudPlugIn.getSwingUI().getOwnerFrame());
|
||||||
|
if (files != null && files.length > 0) {
|
||||||
|
List<ITask<String[]>> tasks = new ArrayList<ITask<String[]>>();
|
||||||
|
final ListIterator<ITask<String[]>> taskIterator = tasks.listIterator();
|
||||||
|
|
||||||
|
for (final File file : files) {
|
||||||
|
taskIterator.add(new ITask<String[]>() {
|
||||||
|
@Override
|
||||||
|
public String[] doInBackground() throws Exception {
|
||||||
|
LOG.debug("Uploading from " + file.getAbsolutePath());
|
||||||
|
cloudPlugIn.getThumbnailPresenter().loadProjectFromFile(file.getAbsolutePath());
|
||||||
|
return cloudPlugIn.getCloudService().getCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(final String[] result) {
|
||||||
|
final UploadDialog dialog =
|
||||||
|
DialogFactory.getInstance().createUploadDialog(cloudPlugIn.getSwingUI().getOwnerFrame(),
|
||||||
|
cloudPlugIn.getThumbnailPresenter(), result, false);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
try {
|
||||||
|
final File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
||||||
|
if (ImageIO.write(cloudPlugIn.getThumbnailGenerator().getThumbnail(), "png", thumbnailFile)) {
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(new ITask<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
cloudPlugIn.getCloudService().uploadProject(dialog.getName(), dialog.getCategory(), dialog
|
||||||
|
.getDescription(), dialog.getKeywords(), cloudPlugIn.getPlugInPort().getCurrentVersionNumber().toString(),
|
||||||
|
thumbnailFile, file, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Void result) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage(
|
||||||
|
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
||||||
|
"Upload Success", IView.INFORMATION_MESSAGE);
|
||||||
|
|
||||||
|
synchronized (taskIterator) {
|
||||||
|
if (taskIterator.hasPrevious())
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(taskIterator.previous(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
} else {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Could not prepare temporary files to be uploaded to the cloud.",
|
||||||
|
"Upload Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
cloudPlugIn.getSwingUI().showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (taskIterator) {
|
||||||
|
if (taskIterator.hasPrevious())
|
||||||
|
cloudPlugIn.getSwingUI().executeBackgroundTask(taskIterator.previous(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -170,7 +170,8 @@ public class UserEditDialog extends ButtonDialog {
|
|||||||
this.website = getWebsiteField().getText();
|
this.website = getWebsiteField().getText();
|
||||||
this.bio = getBioArea().getText();
|
this.bio = getBioArea().getText();
|
||||||
JButton okButton = getButton(OK);
|
JButton okButton = getButton(OK);
|
||||||
okButton.setEnabled((this.userName.length() > 0)
|
okButton.setEnabled(!this.userName.isEmpty()
|
||||||
|
&& !this.email.isEmpty() && this.email.contains("@")
|
||||||
&& (this.existingEntity != null || ((this.password != null) && (this.password.length() > 0))));
|
&& (this.existingEntity != null || ((this.password != null) && (this.password.length() > 0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +254,10 @@ public class UserEditDialog extends ButtonDialog {
|
|||||||
private JTextField getEmailField() {
|
private JTextField getEmailField() {
|
||||||
if (emailField == null) {
|
if (emailField == null) {
|
||||||
emailField = new JTextField();
|
emailField = new JTextField();
|
||||||
if (existingEntity != null)
|
if (existingEntity != null) {
|
||||||
emailField.setText(existingEntity.getEmail());
|
emailField.setText(existingEntity.getEmail());
|
||||||
|
emailField.setEditable(false);
|
||||||
|
}
|
||||||
emailField.getDocument().addDocumentListener(new DocumentListener() {
|
emailField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user