mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
add support for update/delete project
move some code to background threads
This commit is contained in:
Binary file not shown.
@@ -104,7 +104,8 @@ public interface IServiceAPI {
|
|||||||
@ParamName("page") Integer page, @ParamName("itemsPerPage") Integer itemsPerPage, @ParamName("sort") String sort);
|
@ParamName("page") Integer page, @ParamName("itemsPerPage") Integer itemsPerPage, @ParamName("sort") String sort);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a project using token to authenticate.
|
* Uploads a project using token to authenticate. When projectI is specified, it updates the
|
||||||
|
* existing project instead. In that case, the project must belong to the user.
|
||||||
*
|
*
|
||||||
* @param username
|
* @param username
|
||||||
* @param token
|
* @param token
|
||||||
@@ -116,13 +117,27 @@ public interface IServiceAPI {
|
|||||||
* @param keywords
|
* @param keywords
|
||||||
* @param thumbnail
|
* @param thumbnail
|
||||||
* @param project
|
* @param project
|
||||||
|
* @param projectId
|
||||||
* @return "Success" if the upload was successful or error message if it failed.
|
* @return "Success" if the upload was successful or error message if it failed.
|
||||||
*/
|
*/
|
||||||
String upload(@ParamName("username") String username, @ParamName("token") String token,
|
String uploadProject(@ParamName("username") String username, @ParamName("token") String token,
|
||||||
@ParamName("machineId") String machineId, @ParamName("projectName") String projectName,
|
@ParamName("machineId") String machineId, @ParamName("projectName") String projectName,
|
||||||
@ParamName("category") String category, @ParamName("description") String description,
|
@ParamName("category") String category, @ParamName("description") String description,
|
||||||
@ParamName("diylcVersion") String diylcVersion, @ParamName("keywords") String keywords,
|
@ParamName("diylcVersion") String diylcVersion, @ParamName("keywords") String keywords,
|
||||||
@ParamName("thumbnail") File thumbnail, @ParamName("project") File project);
|
@ParamName("thumbnail") File thumbnail, @ParamName("project") File project,
|
||||||
|
@ParamName("projectId") Integer projectId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Deletes an existing project. The project must belong to the user
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @param token
|
||||||
|
* @param machineId
|
||||||
|
* @param projectId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String deleteProject(@ParamName("username") String username, @ParamName("token") String token,
|
||||||
|
@ParamName("machineId") String machineId, @ParamName("projectId") Integer projectId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts a comment to the specified project.
|
* Posts a comment to the specified project.
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class CloudPresenter {
|
|||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void upload(String projectName, String category, String description, String keywords, String diylcVersion,
|
public void uploadProject(String projectName, String category, String description, String keywords, String diylcVersion,
|
||||||
File thumbnail, File project) throws IOException, CloudException {
|
File thumbnail, File project) throws IOException, CloudException {
|
||||||
String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
|
String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
|
||||||
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
|
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
|
||||||
@@ -144,8 +144,8 @@ public class CloudPresenter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String res =
|
String res =
|
||||||
getService().upload(username, token, getMachineId(), projectName, category, description, diylcVersion,
|
getService().uploadProject(username, token, getMachineId(), projectName, category, description, diylcVersion,
|
||||||
keywords, thumbnail, project);
|
keywords, thumbnail, project, null);
|
||||||
if (!res.equals(SUCCESS))
|
if (!res.equals(SUCCESS))
|
||||||
throw new CloudException(res);
|
throw new CloudException(res);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Binary file not shown.
@@ -13,7 +13,6 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
|||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.plugins.cloud.model.UserEntity;
|
import org.diylc.plugins.cloud.model.UserEntity;
|
||||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
|
||||||
import org.diylc.swing.gui.components.OverwritePromptFileChooser;
|
import org.diylc.swing.gui.components.OverwritePromptFileChooser;
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.swing.plugins.cloud.view.ChangePasswordDialog;
|
import org.diylc.swing.plugins.cloud.view.ChangePasswordDialog;
|
||||||
@@ -138,8 +137,8 @@ public class DialogFactory {
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadDialog createUploadDialog(IPlugInPort plugInPort, CloudPresenter cloudPresenter) {
|
public UploadDialog createUploadDialog(IPlugInPort plugInPort, String[] categories) {
|
||||||
UploadDialog dialog = new UploadDialog(mainFrame, plugInPort, cloudPresenter);
|
UploadDialog dialog = new UploadDialog(mainFrame, plugInPort, categories);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -390,28 +390,46 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
|
|||||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||||
FileFilterEnum.DIY.getExtensions()[0], null);
|
FileFilterEnum.DIY.getExtensions()[0], null);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
swingUI.executeBackgroundTask(new ITask<File>() {
|
swingUI.executeBackgroundTask(new ITask<String[]>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File doInBackground() throws Exception {
|
public String[] doInBackground() throws Exception {
|
||||||
LOG.debug("Uploading from " + file.getAbsolutePath());
|
LOG.debug("Uploading from " + file.getAbsolutePath());
|
||||||
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
||||||
return file;
|
return cloudPresenter.getCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(File result) {
|
public void complete(final String[] result) {
|
||||||
UploadDialog dialog = DialogFactory.getInstance().createUploadDialog(thumbnailPresenter, cloudPresenter);
|
final UploadDialog dialog = DialogFactory.getInstance().createUploadDialog(thumbnailPresenter, result);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
try {
|
try {
|
||||||
File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
final File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
||||||
if (ImageIO.write(dialog.getThumbnail(), "png", thumbnailFile)) {
|
if (ImageIO.write(dialog.getThumbnail(), "png", thumbnailFile)) {
|
||||||
cloudPresenter.upload(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, result);
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground() throws Exception {
|
||||||
|
cloudPresenter.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
|
||||||
|
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, file);
|
||||||
|
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(
|
swingUI.showMessage(
|
||||||
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
||||||
"Upload Success", IView.INFORMATION_MESSAGE);
|
"Upload Success", IView.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.", "Upload Error",
|
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.", "Upload Error",
|
||||||
IView.ERROR_MESSAGE);
|
IView.ERROR_MESSAGE);
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import javax.swing.event.ChangeListener;
|
|||||||
|
|
||||||
import org.diylc.common.DrawOption;
|
import org.diylc.common.DrawOption;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.plugins.cloud.presenter.CloudException;
|
|
||||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
|
||||||
import org.diylc.swingframework.ButtonDialog;
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
import org.diylc.utils.KeywordExtractor;
|
import org.diylc.utils.KeywordExtractor;
|
||||||
|
|
||||||
@@ -55,12 +53,12 @@ public class UploadDialog extends ButtonDialog {
|
|||||||
private JTextField keywordsField;
|
private JTextField keywordsField;
|
||||||
|
|
||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
private CloudPresenter cloudPresenter;
|
private String[] categories;
|
||||||
|
|
||||||
public UploadDialog(JFrame owner, IPlugInPort plugInPort, CloudPresenter cloudPresenter) {
|
public UploadDialog(JFrame owner, IPlugInPort plugInPort, String[] categories) {
|
||||||
super(owner, "Upload A Project", new String[] {OK, CANCEL});
|
super(owner, "Upload A Project", new String[] {OK, CANCEL});
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
this.cloudPresenter = cloudPresenter;
|
this.categories = categories;
|
||||||
layoutGui();
|
layoutGui();
|
||||||
getButton(OK).setEnabled(false);
|
getButton(OK).setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -208,12 +206,7 @@ public class UploadDialog extends ButtonDialog {
|
|||||||
|
|
||||||
private JComboBox getCategoryBox() {
|
private JComboBox getCategoryBox() {
|
||||||
if (categoryBox == null) {
|
if (categoryBox == null) {
|
||||||
try {
|
categoryBox = new JComboBox(categories);
|
||||||
categoryBox = new JComboBox(cloudPresenter.getCategories());
|
|
||||||
} catch (CloudException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return categoryBox;
|
return categoryBox;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-1
@@ -29,6 +29,7 @@ import org.diylc.plugins.cloud.model.ProjectEntity;
|
|||||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
||||||
import org.diylc.plugins.cloud.presenter.PagingProvider;
|
import org.diylc.plugins.cloud.presenter.PagingProvider;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.utils.Pair;
|
||||||
|
|
||||||
public class CloudBrowserFrame extends JFrame {
|
public class CloudBrowserFrame extends JFrame {
|
||||||
|
|
||||||
@@ -68,6 +69,31 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
rootPane.setDefaultButton(getSearchHeaderPanel().getGoButton());
|
rootPane.setDefaultButton(getSearchHeaderPanel().getGoButton());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible(boolean b) {
|
||||||
|
super.setVisible(b);
|
||||||
|
if (b) {
|
||||||
|
executeBackgroundTask(new ITask<Pair<String[], String[]>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pair<String[], String[]> doInBackground() throws Exception {
|
||||||
|
return new Pair<String[], String[]>(cloudPresenter.getCategories(), cloudPresenter.getSortings());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(Exception e) {
|
||||||
|
LOG.error("Could not fetch categories and sortings from the cloud", e);
|
||||||
|
showMessage("Could not fetch categories and sortings from the cloud", "Cloud Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Pair<String[], String[]> result) {
|
||||||
|
getSearchHeaderPanel().updateLists(result.getFirst(), result.getSecond());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public JPanel getMainPanel() {
|
public JPanel getMainPanel() {
|
||||||
if (mainPanel == null) {
|
if (mainPanel == null) {
|
||||||
mainPanel = new JPanel(new GridBagLayout());
|
mainPanel = new JPanel(new GridBagLayout());
|
||||||
@@ -133,7 +159,7 @@ public class CloudBrowserFrame extends JFrame {
|
|||||||
|
|
||||||
private SearchHeaderPanel getSearchHeaderPanel() {
|
private SearchHeaderPanel getSearchHeaderPanel() {
|
||||||
if (searchHeaderPanel == null) {
|
if (searchHeaderPanel == null) {
|
||||||
searchHeaderPanel = new SearchHeaderPanel(cloudPresenter);
|
searchHeaderPanel = new SearchHeaderPanel();
|
||||||
searchHeaderPanel.getGoButton().addActionListener(new ActionListener() {
|
searchHeaderPanel.getGoButton().addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+14
-19
@@ -5,6 +5,7 @@ import java.awt.GridBagConstraints;
|
|||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -12,8 +13,6 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
import org.diylc.plugins.cloud.presenter.CloudException;
|
|
||||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
|
||||||
|
|
||||||
public class SearchHeaderPanel extends JPanel {
|
public class SearchHeaderPanel extends JPanel {
|
||||||
|
|
||||||
@@ -24,10 +23,7 @@ public class SearchHeaderPanel extends JPanel {
|
|||||||
private JComboBox sortBox;
|
private JComboBox sortBox;
|
||||||
private JButton goButton;
|
private JButton goButton;
|
||||||
|
|
||||||
private CloudPresenter cloudPresenter;
|
public SearchHeaderPanel() {
|
||||||
|
|
||||||
public SearchHeaderPanel(CloudPresenter cloudPresenter) {
|
|
||||||
this.cloudPresenter = cloudPresenter;
|
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
|
|
||||||
this.setBackground(Color.white);
|
this.setBackground(Color.white);
|
||||||
@@ -50,7 +46,7 @@ public class SearchHeaderPanel extends JPanel {
|
|||||||
this.add(new JLabel("Filter By Category:"), gbc);
|
this.add(new JLabel("Filter By Category:"), gbc);
|
||||||
|
|
||||||
gbc.gridx = 3;
|
gbc.gridx = 3;
|
||||||
gbc.weightx = 0.3;
|
gbc.weightx = 0.5;
|
||||||
this.add(getCategoryBox(), gbc);
|
this.add(getCategoryBox(), gbc);
|
||||||
|
|
||||||
gbc.gridx = 4;
|
gbc.gridx = 4;
|
||||||
@@ -69,6 +65,15 @@ public class SearchHeaderPanel extends JPanel {
|
|||||||
getSearchField().requestFocusInWindow();
|
getSearchField().requestFocusInWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLists(String[] categories, String[] sortings) {
|
||||||
|
Object selectedCategory = getCategoryBox().getSelectedItem();
|
||||||
|
Object selectedSorting = getSortBox().getSelectedItem();
|
||||||
|
getCategoryBox().setModel(new DefaultComboBoxModel(categories));
|
||||||
|
getSortBox().setModel(new DefaultComboBoxModel(sortings));
|
||||||
|
getCategoryBox().setSelectedItem(selectedCategory);
|
||||||
|
getSortBox().setSelectedItem(selectedSorting);
|
||||||
|
}
|
||||||
|
|
||||||
private JTextField getSearchField() {
|
private JTextField getSearchField() {
|
||||||
if (searchField == null) {
|
if (searchField == null) {
|
||||||
searchField = new JTextField(60);
|
searchField = new JTextField(60);
|
||||||
@@ -78,24 +83,14 @@ public class SearchHeaderPanel extends JPanel {
|
|||||||
|
|
||||||
private JComboBox getCategoryBox() {
|
private JComboBox getCategoryBox() {
|
||||||
if (categoryBox == null) {
|
if (categoryBox == null) {
|
||||||
try {
|
categoryBox = new JComboBox();
|
||||||
categoryBox = new JComboBox(cloudPresenter.getCategories());
|
|
||||||
} catch (CloudException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return categoryBox;
|
return categoryBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JComboBox getSortBox() {
|
private JComboBox getSortBox() {
|
||||||
if (sortBox == null) {
|
if (sortBox == null) {
|
||||||
try {
|
sortBox = new JComboBox();
|
||||||
sortBox = new JComboBox(cloudPresenter.getSortings());
|
|
||||||
} catch (CloudException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sortBox;
|
return sortBox;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user