cloud search work

This commit is contained in:
bancika
2016-10-24 11:55:40 +02:00
parent a197bbc21a
commit a9df82cbab
7 changed files with 395 additions and 279 deletions
@@ -209,6 +209,7 @@ public class CloudPresenter {
public List<ProjectEntity> search(String criteria, String category, String sortOrder, int pageNumber, int itemsPerPage)
throws CloudException {
LOG.info(String.format("search(%1$s,%2$s,%3$s,%4$d,%5$d)", criteria, category, sortOrder, pageNumber, itemsPerPage));
try {
Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder);
if (res == null)
@@ -32,7 +32,8 @@ public enum IconLoader {
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"), Arrow(
"arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit(
"id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
"data_find.png"), CloudDownload("cloud-download.png");
"data_find.png"), CloudDownload("cloud-download.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue(
"nav_right_blue.png");
protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -323,14 +323,16 @@ public class MainFrame extends JFrame implements ISwingUI {
try {
T result = get();
task.complete(result);
getGlassPane().setVisible(false);
} catch (ExecutionException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution failed", e);
task.failed(e);
} catch (InterruptedException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution interrupted", e);
task.failed(e);
}
getGlassPane().setVisible(false);
}
};
worker.execute();
@@ -32,6 +32,7 @@ import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -72,6 +73,10 @@ public class CloudBrowserFrame extends JFrame {
private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter;
// search criteria
private String searchFor;
private String category;
private String sort;
private int pageNumber;
private int itemsPerPage = 10;
@@ -177,7 +182,7 @@ public class CloudBrowserFrame extends JFrame {
searchPanel.add(new JLabel("Filter By Category:"), gbc);
gbc.gridx = 3;
gbc.weightx = 1;
gbc.weightx = 0.3;
searchPanel.add(getCategoryBox(), gbc);
gbc.gridx = 4;
@@ -195,7 +200,7 @@ public class CloudBrowserFrame extends JFrame {
private JTextField getSearchField() {
if (searchField == null) {
searchField = new JTextField();
searchField = new JTextField(60);
}
return searchField;
}
@@ -249,20 +254,31 @@ public class CloudBrowserFrame extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
CloudBrowserFrame.this.pageNumber = 1;
CloudBrowserFrame.this.searchFor = getSearchField().getText();
CloudBrowserFrame.this.category =
getCategoryBox().getSelectedItem() == null ? "" : getCategoryBox().getSelectedItem().toString();
CloudBrowserFrame.this.sort =
getSortBox().getSelectedItem() == null ? "" : getSortBox().getSelectedItem().toString();
search();
}
});
}
return goButton;
}
private void search() {
executeBackgroundTask(new ITask<List<ProjectEntity>>() {
@Override
public List<ProjectEntity> doInBackground() throws Exception {
return cloudPresenter.search(getSearchField().getText(), getCategoryBox().getSelectedItem() == null ? ""
: getCategoryBox().getSelectedItem().toString(), getSortBox().getSelectedItem() == null ? ""
: getSortBox().getSelectedItem().toString(), CloudBrowserFrame.this.pageNumber,
CloudBrowserFrame.this.itemsPerPage);
return cloudPresenter.search(searchFor, category, sort, pageNumber, itemsPerPage);
}
@Override
public void failed(Exception e) {
showMessage("Search failed. Error: " + e.getMessage(), "Search Failed", IView.ERROR_MESSAGE);
showMessage("Search failed! Detailed message is in the logs. Please report to the author.", "Search Failed",
IView.ERROR_MESSAGE);
}
@Override
@@ -271,51 +287,38 @@ public class CloudBrowserFrame extends JFrame {
int count = 0;
for (Iterator<ProjectEntity> i = result.iterator(); i.hasNext();) {
ProjectEntity project = i.next();
addProjectToDisplay(project, count++, i.hasNext());
addProjectToDisplay(project, count++);
}
if (count == 0) {
showNoMatches();
count++;
}
addNavigationPanel(count);
}
});
}
});
}
return goButton;
private void showNoMatches() {
JLabel label = new JLabel("<html><font size='5' color='red'>No projects match the search criteria.</font></html>");
label.setHorizontalAlignment(SwingConstants.CENTER);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.weighty = Integer.MAX_VALUE;
getResultsPanel().add(label, gbc);
}
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
getGlassPane().setVisible(true);
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
@Override
protected T doInBackground() throws Exception {
return task.doInBackground();
}
@Override
protected void done() {
try {
T result = get();
task.complete(result);
} catch (ExecutionException e) {
LOG.error("Background task execution failed", e);
task.failed(e);
} catch (InterruptedException e) {
LOG.error("Background task execution interrupted", e);
task.failed(e);
}
getGlassPane().setVisible(false);
}
};
worker.execute();
}
private void addProjectToDisplay(final ProjectEntity project, int location, boolean hasNext) {
private void addProjectToDisplay(final ProjectEntity project, int location) {
JLabel thumbnailLabel = new JLabel(downloadImage(project.getThumbnailUrl()));
JLabel nameLabel = new JLabel("<html><b>" + project.getName() + "</b></html>");
nameLabel.setFont(nameLabel.getFont().deriveFont(12f));
JLabel descriptionLabel = new JLabel("<html>" + project.getDescription() + "</html>");
JLabel categoryLabel = new JLabel("Category: " + project.getCategory());
JLabel authorLabel = new JLabel("<html>by: <b>" + project.getOwner() + "</b></html>");
JLabel updatedLabel = new JLabel("Last updated: " + project.getUpdated());
JLabel categoryLabel = new JLabel("<html>Category: <b>" + project.getCategory() + "</b></html>");
JLabel authorLabel = new JLabel("<html>Author: <b>" + project.getOwner() + "</b></html>");
JLabel updatedLabel = new JLabel("<html>Last updated: <b>" + project.getUpdated() + "</b></html>");
JButton downloadButton = new JButton(IconLoader.CloudDownload.getIcon());
downloadButton.setBorderPainted(false);
@@ -365,7 +368,7 @@ public class CloudBrowserFrame extends JFrame {
@Override
public void failed(Exception e) {
CloudBrowserFrame.this.showMessage("Could not open file. " + e.getMessage(), "Error",
CloudBrowserFrame.this.showMessage("Could not open file. Detailed message is in the logs", "Error",
ISwingUI.ERROR_MESSAGE);
}
});
@@ -374,7 +377,7 @@ public class CloudBrowserFrame extends JFrame {
@Override
public void failed(Exception e) {
CloudBrowserFrame.this.showMessage("Could not save to file. " + e.getMessage(), "Error",
CloudBrowserFrame.this.showMessage("Could not save to file. Detailed message is in the logs", "Error",
ISwingUI.ERROR_MESSAGE);
}
});
@@ -386,9 +389,9 @@ public class CloudBrowserFrame extends JFrame {
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = location * 5;
gbc.gridy = location * 6;
gbc.fill = GridBagConstraints.NONE;
gbc.gridheight = 4;
gbc.gridheight = 5;
gbc.weightx = 0;
getResultsPanel().add(thumbnailLabel, gbc);
@@ -397,11 +400,11 @@ public class CloudBrowserFrame extends JFrame {
gbc.weightx = 1;
gbc.insets = new Insets(2, 6, 2, 2);
getResultsPanel().add(nameLabel, gbc);
gbc.gridx = 2;
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.insets = new Insets(2, 2, 2, 8);
getResultsPanel().add(authorLabel, gbc);
//
// gbc.gridx = 2;
// gbc.anchor = GridBagConstraints.NORTHEAST;
// gbc.insets = new Insets(2, 2, 2, 8);
// getResultsPanel().add(authorLabel, gbc);
gbc.gridy++;
gbc.gridx = 1;
@@ -416,7 +419,7 @@ public class CloudBrowserFrame extends JFrame {
getResultsPanel().add(categoryLabel, gbc);
gbc.gridx = 2;
gbc.gridheight = 2;
gbc.gridheight = 3;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.SOUTHEAST;
getResultsPanel().add(downloadButton, gbc);
@@ -426,9 +429,11 @@ public class CloudBrowserFrame extends JFrame {
gbc.gridheight = 1;
gbc.insets = new Insets(2, 6, 2, 2);
gbc.anchor = GridBagConstraints.NORTHWEST;
getResultsPanel().add(authorLabel, gbc);
gbc.gridy++;
getResultsPanel().add(updatedLabel, gbc);
if (hasNext) {
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 3;
@@ -437,6 +442,93 @@ public class CloudBrowserFrame extends JFrame {
gbc.insets = new Insets(2, 2, 2, 2);
getResultsPanel().add(new JSeparator(), gbc);
}
private void addNavigationPanel(int location) {
JPanel navigationPanel = new JPanel(new GridBagLayout());
navigationPanel.setBackground(Color.white);
JButton prevPageButton = new JButton(IconLoader.NavLeftBlue.getIcon());
prevPageButton.setBorderPainted(false);
prevPageButton.setContentAreaFilled(false);
prevPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
prevPageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (CloudBrowserFrame.this.pageNumber > 1) {
CloudBrowserFrame.this.pageNumber--;
CloudBrowserFrame.this.search();
}
}
});
JButton nextPageButton = new JButton(IconLoader.NavRightBlue.getIcon());
nextPageButton.setBorderPainted(false);
nextPageButton.setContentAreaFilled(false);
nextPageButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
nextPageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CloudBrowserFrame.this.pageNumber++;
CloudBrowserFrame.this.search();
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.SOUTHWEST;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.weightx = 0;
gbc.fill = GridBagConstraints.NONE;
navigationPanel.add(prevPageButton, gbc);
gbc.gridx++;
gbc.weightx = 1;
navigationPanel.add(new JLabel(), gbc);
gbc.gridx++;
gbc.weightx = 0;
navigationPanel.add(nextPageButton, gbc);
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.gridx = 0;
gbc.gridy = location * 6;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 100;
gbc.gridwidth = 3;
getResultsPanel().add(navigationPanel, gbc);
}
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
getGlassPane().setVisible(true);
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
@Override
protected T doInBackground() throws Exception {
return task.doInBackground();
}
@Override
protected void done() {
try {
T result = get();
task.complete(result);
getGlassPane().setVisible(false);
} catch (ExecutionException e) {
LOG.error("Background task execution failed", e);
getGlassPane().setVisible(false);
task.failed(e);
} catch (InterruptedException e) {
getGlassPane().setVisible(false);
LOG.error("Background task execution interrupted", e);
task.failed(e);
}
}
};
worker.execute();
}
public void showMessage(String message, String title, int messageType) {
@@ -35,11 +35,15 @@ public class UploadDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
private static final String BULLET = "&nbsp;&nbsp;&nbsp;&#8226;&nbsp;";
private static final String TERMS_HTML = "<html>" + BULLET
+ "All content uploaded to DIY Cloud is shared under Creative Commons 3.0 Licence.<br>" + BULLET
+ "Only finished and resonably verified projects may be uploaded to the DIY Cloud.<br>" + BULLET
private static final String TERMS_HTML = "<html>"
+ BULLET
+ "All content uploaded to DIY Cloud is shared under Creative Commons 3.0 Licence.<br>"
+ BULLET
+ "Only finished and resonably verified projects may be uploaded to the DIY Cloud.<br>"
+ BULLET
+ "Please provide a meaningful project description to make it possible for others to find the project.<br>"
+ BULLET + "If you are building on top of someone else's work, please leave credits in the description.<br>"
+ BULLET
+ "If you are building on top of someone else's work, please leave credits in the description.<br>"
+ BULLET
+ "Uploaded content may be reviewed, edited and removed by the administrators if it is not up to standards.<br>"
+ "</html>";
@@ -56,7 +60,8 @@ public class UploadDialog extends ButtonDialog {
private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter;
public UploadDialog(JFrame owner, IPlugInPort plugInPort, CloudPresenter cloudPresenter) {
public UploadDialog(JFrame owner, IPlugInPort plugInPort,
CloudPresenter cloudPresenter) {
super(owner, "Upload A Project", new String[] { OK, CANCEL });
this.plugInPort = plugInPort;
this.cloudPresenter = cloudPresenter;
@@ -153,7 +158,8 @@ public class UploadDialog extends ButtonDialog {
termsLabel = new JLabel();
termsLabel.setOpaque(true);
termsLabel.setBackground(UIManager.getColor("ToolTip.background"));
termsLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
termsLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEtchedBorder(),
BorderFactory.createEmptyBorder(2, 2, 2, 2)));
termsLabel.setText(TERMS_HTML);
}
@@ -183,11 +189,14 @@ public class UploadDialog extends ButtonDialog {
paintThumbnail(g, getBounds());
}
}, gbc);
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false);
Dimension d = UploadDialog.this.plugInPort
.getCanvasDimensions(false);
if (d.height > d.width)
thumbnailPanel.setPreferredSize(new Dimension(192 * d.width / d.height, 192));
thumbnailPanel.setPreferredSize(new Dimension(192 * d.width
/ d.height, 192));
else
thumbnailPanel.setPreferredSize(new Dimension(192, 192 * d.height / d.width));
thumbnailPanel.setPreferredSize(new Dimension(192, 192
* d.height / d.width));
thumbnailPanel.setBorder(BorderFactory.createEtchedBorder());
}
return thumbnailPanel;
@@ -199,8 +208,10 @@ public class UploadDialog extends ButtonDialog {
// set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Title"))
nameField.setText(plugInPort.getProjectProperties().get(i).getValue().toString());
if (plugInPort.getProjectProperties().get(i).getName()
.equals("Title"))
nameField.setText(plugInPort.getProjectProperties().get(i)
.getValue().toString());
}
return nameField;
}
@@ -223,8 +234,14 @@ public class UploadDialog extends ButtonDialog {
// set default from the project
for (int i = 0; i < plugInPort.getProjectProperties().size(); i++)
if (plugInPort.getProjectProperties().get(i).getName().equals("Description"))
descriptionArea.setText(plugInPort.getProjectProperties().get(i).getValue().toString());
if (plugInPort.getProjectProperties().get(i).getName()
.equals("Description"))
try {
descriptionArea.setText(plugInPort
.getProjectProperties().get(i).getValue()
.toString());
} catch (Exception e) {
}
descriptionArea.setBorder(getNameField().getBorder());
descriptionArea.setFont(getNameField().getFont());
}
@@ -243,7 +260,7 @@ public class UploadDialog extends ButtonDialog {
}
public String getDescription() {
return getDescriptionArea().getText();
return getDescriptionArea().getText().replace("\n", "<br>");
}
public String getCategory() {
@@ -251,11 +268,13 @@ public class UploadDialog extends ButtonDialog {
}
public BufferedImage getThumbnail() {
BufferedImage thumbnailImage =
new BufferedImage(getThumbnailPanel().getWidth(), getThumbnailPanel().getHeight(), BufferedImage.TYPE_INT_RGB);
BufferedImage thumbnailImage = new BufferedImage(getThumbnailPanel()
.getWidth(), getThumbnailPanel().getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D cg = thumbnailImage.createGraphics();
paintThumbnail(cg, new Rectangle(thumbnailImage.getWidth(), thumbnailImage.getHeight()));
paintThumbnail(cg, new Rectangle(thumbnailImage.getWidth(),
thumbnailImage.getHeight()));
return thumbnailImage;
}
@@ -276,7 +295,8 @@ public class UploadDialog extends ButtonDialog {
}
g2d.scale(zoomRatio, zoomRatio);
UploadDialog.this.plugInPort.draw(g2d, EnumSet.of(DrawOption.ANTIALIASING), null);
UploadDialog.this.plugInPort.draw(g2d,
EnumSet.of(DrawOption.ANTIALIASING), null);
}
public String getKeywords() {