code cleanup

V1 file import - added support for more component types
minor improvements
This commit is contained in:
Branislav Stojkovic
2016-11-02 01:04:52 +01:00
parent 94c8512c11
commit ad6e45da23
24 changed files with 285 additions and 139 deletions
@@ -25,7 +25,7 @@ public class PropertyWrapper implements Cloneable {
private boolean changed = false; private boolean changed = false;
private String additionalOptions; private String additionalOptions;
private int sortOrder; private int sortOrder;
private String[] listItems; private Object[] listItems;
public PropertyWrapper(String name, Class<?> type, String getter, String setter, boolean defaultable, public PropertyWrapper(String name, Class<?> type, String getter, String setter, boolean defaultable,
IPropertyValidator validator, String additionalOptions, int sortOrder) { IPropertyValidator validator, String additionalOptions, int sortOrder) {
@@ -46,7 +46,7 @@ public class PropertyWrapper implements Cloneable {
if (additionalOptions.startsWith(EditableProperty.DYNAMIC_LIST)) { if (additionalOptions.startsWith(EditableProperty.DYNAMIC_LIST)) {
String functionName = additionalOptions.substring(EditableProperty.DYNAMIC_LIST.length()); String functionName = additionalOptions.substring(EditableProperty.DYNAMIC_LIST.length());
Method listMethod = object.getClass().getMethod(functionName); Method listMethod = object.getClass().getMethod(functionName);
listItems = (String[]) listMethod.invoke(object); listItems = (Object[]) listMethod.invoke(object);
} }
} }
@@ -112,11 +112,11 @@ public class PropertyWrapper implements Cloneable {
return sortOrder; return sortOrder;
} }
public String[] getListItems() { public Object[] getListItems() {
return listItems; return listItems;
} }
public void setOptions(String[] listItems) { public void setOptions(Object[] listItems) {
this.listItems = listItems; this.listItems = listItems;
} }
@@ -1,5 +1,12 @@
package org.diylc.core.annotations; package org.diylc.core.annotations;
/**
* Tells the system how to represent components in the B.O.M.
*
* @see ComponentDescriptor
*
* @author Branislav Stojkovic
*/
public enum BomPolicy { public enum BomPolicy {
SHOW_ALL_NAMES, SHOW_ONLY_TYPE_NAME, NEVER_SHOW, SHOW_ALL_NAMES, SHOW_ONLY_TYPE_NAME, NEVER_SHOW,
} }
@@ -7,7 +7,9 @@ import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
/** /**
* Annotation for {@link IDIYComponent} implementation. Describes component properties. * Annotation that needs to be used for each {@link IDIYComponent} implementation. Describes
* component properties and how component should be represented and interact with the rest of the
* system.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -9,7 +9,24 @@ import org.diylc.core.IPropertyValidator;
/** /**
* Used to annotate editable component property. Editable property XYZ must have both getter and * Used to annotate editable component property. Editable property XYZ must have both getter and
* setter named <code>getXYZ</code> and <code>setXYZ</code> respectively and this annotation must be * setter named <code>getXYZ</code> and <code>setXYZ</code> respectively and this annotation must be
* placed on the getter method. * placed on the getter method. <br>
* <br>
* In the example below, {@code category} is the property we want to edit and
* {@code getCategories()} provides a list of available values for category.
*
* <pre>
* <code>
* &#64;EditableProperty(additionalOptions = EditableProperty.DYNAMIC_LIST
* + "getCategories")
* public String getCategory() {
* return category;
* }
*
* public String[] getCategories() {
* return categories;
* }
* </code>
* </pre>
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -4,7 +4,18 @@ import java.util.List;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
/**
* Interface for creating components automatically each time a component is created by the user.
*
* @author Branislav Stojkovic
*/
public interface IAutoCreator { public interface IAutoCreator {
/**
* @param lastAdded the component created by the user
* @return {@link List} of {@link IDIYComponent}s that will be automatically created as a result.
* Empty {@link List} or {@code null} are valid responses for cases when no components
* should be auto-created.
*/
public List<IDIYComponent<?>> createIfNeeded(IDIYComponent<?> lastAdded); public List<IDIYComponent<?>> createIfNeeded(IDIYComponent<?> lastAdded);
} }
@@ -1,5 +1,12 @@
package org.diylc.core.annotations; package org.diylc.core.annotations;
/**
* Tells the system how keywords should be extracted from a component.
*
* @see ComponentDescriptor
*
* @author Branislav Stojkovic
*/
public enum KeywordPolicy { public enum KeywordPolicy {
/** /**
* The component is represented with its type. * The component is represented with its type.
@@ -4,6 +4,12 @@ import org.diylc.core.IPropertyValidator;
import org.diylc.core.ValidationException; import org.diylc.core.ValidationException;
import org.diylc.core.measures.AbstractMeasure; import org.diylc.core.measures.AbstractMeasure;
/**
* Validates any generic {@link AbstractMeasure} descendants and makes sure that the value is
* positive.
*
* @author Branislav Stojkovic
*/
public class PositiveMeasureValidator implements IPropertyValidator { public class PositiveMeasureValidator implements IPropertyValidator {
@Override @Override
@@ -31,6 +31,8 @@ import com.diyfever.httpproxy.ProxyFactory;
*/ */
public class CloudPresenter { public class CloudPresenter {
public static final CloudPresenter Instance = new CloudPresenter();
private static String USERNAME_KEY = "cloud.Username"; private static String USERNAME_KEY = "cloud.Username";
private static String TOKEN_KEY = "cloud.token"; private static String TOKEN_KEY = "cloud.token";
@@ -44,15 +46,11 @@ public class CloudPresenter {
private String machineId; private String machineId;
private String[] categories; private String[] categories;
private CloudListener listener;
private boolean loggedIn = false; private boolean loggedIn = false;
public CloudPresenter(CloudListener listener) { private CloudPresenter() {}
this.listener = listener;
}
public IServiceAPI getService() { private IServiceAPI getService() {
if (service == null) { if (service == null) {
serviceUrl = serviceUrl =
ConfigurationManager.getInstance().readString(IServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api/v1"); ConfigurationManager.getInstance().readString(IServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api/v1");
@@ -79,7 +77,6 @@ public class CloudPresenter {
LOG.info("Login success"); LOG.info("Login success");
ConfigurationManager.getInstance().writeValue(USERNAME_KEY, username); ConfigurationManager.getInstance().writeValue(USERNAME_KEY, username);
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res); ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res);
listener.loggedIn();
this.loggedIn = true; this.loggedIn = true;
return true; return true;
} }
@@ -102,7 +99,6 @@ public class CloudPresenter {
return false; return false;
} else { } else {
LOG.info("Login success"); LOG.info("Login success");
listener.loggedIn();
this.loggedIn = true; this.loggedIn = true;
return true; return true;
} }
@@ -114,7 +110,6 @@ public class CloudPresenter {
LOG.info("Logged out"); LOG.info("Logged out");
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, null); ConfigurationManager.getInstance().writeValue(TOKEN_KEY, null);
this.loggedIn = false; this.loggedIn = false;
listener.loggedOut();
} }
public boolean isLoggedIn() { public boolean isLoggedIn() {
@@ -6,15 +6,13 @@ import org.diylc.plugins.cloud.model.ProjectEntity;
/** /**
* Used to create paging of the search results. Use * Used to create paging of the search results. Use
* {@link PagingProvider#startSession(String, String, String)} to start the search session and then * {@link SearchSession#startSession(String, String, String)} to start the search session and then
* {@link PagingProvider#hasMoreData()} returns true if there's more data available and * {@link SearchSession#hasMoreData()} returns true if there's more data available and
* {@link PagingProvider#requestMoreData()} returns the next page. * {@link SearchSession#requestMoreData()} returns the next page.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
public class PagingProvider { public class SearchSession {
private CloudPresenter cloudPresenter;
private String searchFor; private String searchFor;
private String category; private String category;
@@ -24,8 +22,7 @@ public class PagingProvider {
private int currentPage; private int currentPage;
private List<ProjectEntity> currentResults; private List<ProjectEntity> currentResults;
public PagingProvider(CloudPresenter cloudPresenter) { public SearchSession() {
this.cloudPresenter = cloudPresenter;
} }
public List<ProjectEntity> startSession(String searchFor, String category, String sort) throws CloudException { public List<ProjectEntity> startSession(String searchFor, String category, String sort) throws CloudException {
@@ -34,7 +31,7 @@ public class PagingProvider {
this.sort = sort; this.sort = sort;
this.currentPage = 1; this.currentPage = 1;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage); return currentResults = CloudPresenter.Instance.search(searchFor, category, sort, currentPage, itemsPerPage);
} }
public boolean hasMoreData() { public boolean hasMoreData() {
@@ -43,6 +40,6 @@ public class PagingProvider {
public List<ProjectEntity> requestMoreData() throws CloudException { public List<ProjectEntity> requestMoreData() throws CloudException {
currentPage++; currentPage++;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage); return currentResults = CloudPresenter.Instance.search(searchFor, category, sort, currentPage, itemsPerPage);
} }
} }
@@ -36,7 +36,7 @@ public class TraceCut extends AbstractComponent<Void> {
private Color fillColor = FILL_COLOR; private Color fillColor = FILL_COLOR;
private Color borderColor = BORDER_COLOR; private Color borderColor = BORDER_COLOR;
private Color boardColor = AbstractBoard.BOARD_COLOR; private Color boardColor = AbstractBoard.BOARD_COLOR;
private Boolean cutBetweenHoles = true; private Boolean cutBetweenHoles = false;
private Size holeSpacing = VeroBoard.SPACING; private Size holeSpacing = VeroBoard.SPACING;
protected Point point = new Point(0, 0); protected Point point = new Point(0, 0);
@@ -49,6 +49,7 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
protected String name; protected String name;
protected ToggleSwitchType switchType = ToggleSwitchType.DPDT; protected ToggleSwitchType switchType = ToggleSwitchType.DPDT;
private OrientationHV orientation = OrientationHV.VERTICAL; private OrientationHV orientation = OrientationHV.VERTICAL;
private Size spacing = SPACING;
public MiniToggleSwitch() { public MiniToggleSwitch() {
super(); super();
@@ -57,7 +58,7 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
private void updateControlPoints() { private void updateControlPoints() {
Point firstPoint = controlPoints[0]; Point firstPoint = controlPoints[0];
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) getSpacing().convertToPixels();
switch (switchType) { switch (switchType) {
case SPST: case SPST:
controlPoints = new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing)}; controlPoints = new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing)};
@@ -189,6 +190,19 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
body = null; body = null;
} }
@EditableProperty
public Size getSpacing() {
if (spacing == null) {
spacing = SPACING;
}
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
updateControlPoints();
}
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
@@ -244,7 +258,7 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
if (body == null) { if (body == null) {
Point firstPoint = controlPoints[0]; Point firstPoint = controlPoints[0];
int margin = (int) MARGIN.convertToPixels(); int margin = (int) MARGIN.convertToPixels();
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) getSpacing().convertToPixels();
switch (switchType) { switch (switchType) {
case SPST: case SPST:
body = body =
@@ -12,6 +12,7 @@ import org.apache.log4j.Logger;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.OrientationHV;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractLeadedComponent; import org.diylc.components.AbstractLeadedComponent;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
@@ -23,6 +24,9 @@ import org.diylc.components.connectivity.CopperTrace;
import org.diylc.components.connectivity.HookupWire; import org.diylc.components.connectivity.HookupWire;
import org.diylc.components.connectivity.Jumper; import org.diylc.components.connectivity.Jumper;
import org.diylc.components.connectivity.SolderPad; import org.diylc.components.connectivity.SolderPad;
import org.diylc.components.connectivity.TraceCut;
import org.diylc.components.electromechanical.MiniToggleSwitch;
import org.diylc.components.electromechanical.ToggleSwitchType;
import org.diylc.components.misc.Label; import org.diylc.components.misc.Label;
import org.diylc.components.passive.PotentiometerPanel; import org.diylc.components.passive.PotentiometerPanel;
import org.diylc.components.passive.RadialElectrolytic; import org.diylc.components.passive.RadialElectrolytic;
@@ -32,6 +36,7 @@ import org.diylc.components.passive.Taper;
import org.diylc.components.semiconductors.DIL_IC; import org.diylc.components.semiconductors.DIL_IC;
import org.diylc.components.semiconductors.DiodePlastic; import org.diylc.components.semiconductors.DiodePlastic;
import org.diylc.components.semiconductors.LED; import org.diylc.components.semiconductors.LED;
import org.diylc.components.semiconductors.SIL_IC;
import org.diylc.components.semiconductors.TransistorTO92; import org.diylc.components.semiconductors.TransistorTO92;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.Project;
@@ -149,6 +154,13 @@ public class V1FileParser implements IOldFileParser {
} }
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0); pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
component = pad; component = pad;
} else if (nodeName.equalsIgnoreCase("cut")) {
LOG.debug("Recognized " + nodeName);
TraceCut cut = new TraceCut();
cut.setCutBetweenHoles(false);
cut.setName(nameAttr);
cut.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
component = cut;
} else if (nodeName.equalsIgnoreCase("trace")) { } else if (nodeName.equalsIgnoreCase("trace")) {
LOG.debug("Recognized " + nodeName); LOG.debug("Recognized " + nodeName);
CopperTrace trace = new CopperTrace(); CopperTrace trace = new CopperTrace();
@@ -312,6 +324,95 @@ public class V1FileParser implements IOldFileParser {
} }
ic.setValue(valueAttr); ic.setValue(valueAttr);
component = ic; component = ic;
} else if (nodeName.equalsIgnoreCase("switch")) {
LOG.debug("Recognized " + nodeName);
MiniToggleSwitch sw = new MiniToggleSwitch();
int sizeX = Math.abs(x1Attr - x2Attr);
int sizeY = Math.abs(y1Attr - y2Attr);
ToggleSwitchType switchType = null;
OrientationHV orientation = null;
if (Math.min(sizeX, sizeY) == 0 && Math.max(sizeX, sizeY) == 1) {
switchType = ToggleSwitchType.SPST;
orientation = sizeX < sizeY ? OrientationHV.VERTICAL : OrientationHV.HORIZONTAL;
}
if (Math.min(sizeX, sizeY) == 0 && Math.max(sizeX, sizeY) == 2) {
switchType = ToggleSwitchType.SPDT;
orientation = sizeX < sizeY ? OrientationHV.VERTICAL : OrientationHV.HORIZONTAL;
}
if (Math.min(sizeX, sizeY) == 1 && Math.max(sizeX, sizeY) == 2) {
switchType = ToggleSwitchType.DPDT;
orientation = sizeX < sizeY ? OrientationHV.VERTICAL : OrientationHV.HORIZONTAL;
}
if (Math.min(sizeX, sizeY) == 2 && Math.max(sizeX, sizeY) == 2) {
switchType = ToggleSwitchType._3PDT;
orientation = OrientationHV.VERTICAL;
}
if (Math.min(sizeX, sizeY) == 2 && Math.max(sizeX, sizeY) == 3) {
switchType = ToggleSwitchType._4PDT;
orientation = sizeX < sizeY ? OrientationHV.HORIZONTAL : OrientationHV.VERTICAL;
}
if (Math.min(sizeX, sizeY) == 2 && Math.max(sizeX, sizeY) == 4) {
switchType = ToggleSwitchType._5PDT;
orientation = sizeX < sizeY ? OrientationHV.HORIZONTAL : OrientationHV.HORIZONTAL;
}
if (switchType == null || orientation == null) {
String message = "Unsupported toggle switch dimensions";
LOG.debug(message);
if (!warnings.contains(message)) {
warnings.add(message);
}
} else {
sw.setName(nameAttr);
sw.setOrientation(orientation);
sw.setValue(switchType);
sw.setSpacing(new Size(0.1, SizeUnit.in));
// compensate for potential negative coordinates after the type and orientation have
// been set. Make sure that the top left corner is at (0, 0)
int dx = 0;
int dy = 0;
for (int j = 0; j < sw.getControlPointCount(); j++) {
Point p = new Point(sw.getControlPoint(j));
if (p.x < 0 && p.x < dx)
dx = p.x;
if (p.y < 0 && p.y < dy)
dy = p.y;
}
// Translate control points.
for (int j = 0; j < sw.getControlPointCount(); j++) {
Point p = new Point(sw.getControlPoint(j));
p.translate(Math.min(point1.x, point2.x) - dx, Math.min(point1.y, point2.y) - dy);
sw.setControlPoint(p, j);
}
component = sw;
}
} else if (nodeName.equalsIgnoreCase("lineic")) {
LOG.debug("Recognized " + nodeName);
SIL_IC ic = new SIL_IC();
int pinCount = 8;
if (x1Attr == x2Attr && y1Attr < y2Attr) {
pinCount = (y2Attr - y1Attr + 1);
ic.setOrientation(Orientation.DEFAULT);
} else if (x1Attr > x2Attr && y1Attr == y2Attr) {
pinCount = (x1Attr - x2Attr + 1);
ic.setOrientation(Orientation._90);
} else if (x1Attr == x2Attr && y1Attr > y2Attr) {
pinCount = (y1Attr - y2Attr + 1);
ic.setOrientation(Orientation._180);
} else if (x1Attr < x2Attr && y1Attr == y2Attr) {
pinCount = (x2Attr - x1Attr + 1);
ic.setOrientation(Orientation._270);
}
ic.setPinCount(SIL_IC.PinCount.valueOf("_" + pinCount));
ic.setName(nameAttr);
// Translate control points.
for (int j = 0; j < ic.getControlPointCount(); j++) {
Point p = new Point(ic.getControlPoint(j));
p.translate(point1.x, point1.y);
ic.setControlPoint(p, j);
}
ic.setValue(valueAttr);
component = ic;
} else if (nodeName.equalsIgnoreCase("pot")) { } else if (nodeName.equalsIgnoreCase("pot")) {
LOG.debug("Recognized " + nodeName); LOG.debug("Recognized " + nodeName);
PotentiometerPanel pot = new PotentiometerPanel(); PotentiometerPanel pot = new PotentiometerPanel();
@@ -2,15 +2,12 @@ package org.diylc.parsing;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class V2FileParser implements IOldFileParser { public class V2FileParser implements IOldFileParser {
private static final Logger LOG = Logger.getLogger(V2FileParser.class); // private static final Logger LOG = Logger.getLogger(V2FileParser.class);
@Override @Override
public boolean canParse(String version) { public boolean canParse(String version) {
@@ -20,21 +17,22 @@ public class V2FileParser implements IOldFileParser {
@Override @Override
public Project parseFile(Element root, List<String> warnings) { public Project parseFile(Element root, List<String> warnings) {
Project project = new Project(); Project project = new Project();
String projectName = root.getAttribute("projectName"); warnings.add("V2 file parser is not yet implemented due to lack of interest and short life of DIYLC V2.");
String credits = root.getAttribute("credits"); // String projectName = root.getAttribute("projectName");
String width = root.getAttribute("width"); // String credits = root.getAttribute("credits");
String height = root.getAttribute("height"); // String width = root.getAttribute("width");
NodeList childNodes = root.getChildNodes(); // String height = root.getAttribute("height");
for (int i = 0; i < childNodes.getLength(); i++) { // NodeList childNodes = root.getChildNodes();
Node node = childNodes.item(i); // for (int i = 0; i < childNodes.getLength(); i++) {
if (node.getNodeType() == Node.ELEMENT_NODE) { // Node node = childNodes.item(i);
if (node.getNodeName().equalsIgnoreCase("component")) { // if (node.getNodeType() == Node.ELEMENT_NODE) {
LOG.debug(node.getAttributes().getNamedItem("name").getNodeValue()); // if (node.getNodeName().equalsIgnoreCase("component")) {
} else { // LOG.debug(node.getAttributes().getNamedItem("name").getNodeValue());
LOG.debug("Unrecognized node name found: " + node.getNodeName()); // } else {
} // LOG.debug("Unrecognized node name found: " + node.getNodeName());
} // }
} // }
// }
return project; return project;
} }
+1 -1
View File
@@ -9,7 +9,7 @@
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/> <classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/app-framework.jar"/> <classpathentry kind="lib" path="lib/app-framework.jar"/>
<classpathentry kind="lib" path="lib/swing-framework.jar"/> <classpathentry kind="lib" path="lib/swing-framework.jar"/>
<classpathentry kind="lib" path="library/main.jar"/> <classpathentry kind="lib" path="library/main.jar" sourcepath="/diylc-library"/>
<classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/> <classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/>
<classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/> <classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
@@ -12,6 +12,11 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.AbstractMeasure; import org.diylc.core.measures.AbstractMeasure;
/**
* Based on {@link PropertyWrapper#getType()}, creates an appropriate {@link Component} that can edit that type.
*
* @author Branislav Stojkovic
*/
public class FieldEditorFactory { public class FieldEditorFactory {
private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class); private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class);
@@ -5,6 +5,8 @@ import java.awt.Dimension;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
@@ -22,11 +24,14 @@ public class MultiLineStringEditor extends JScrollPane {
private final PropertyWrapper property; private final PropertyWrapper property;
private static final Border border = new JTextField().getBorder();
public MultiLineStringEditor(PropertyWrapper property) { public MultiLineStringEditor(PropertyWrapper property) {
super(); super();
this.property = property; this.property = property;
setViewportView(getTextArea()); setViewportView(getTextArea());
setPreferredSize(new Dimension(192, 64)); setPreferredSize(new Dimension(192, 64));
setBorder(border);
} }
public JTextArea getTextArea() { public JTextArea getTextArea() {
@@ -52,21 +52,6 @@ public class PropertyEditorDialog extends ButtonDialog {
layoutGui(); layoutGui();
setLocationRelativeTo(owner); setLocationRelativeTo(owner);
//
// setModal(true);
//
// JPanel holderPanel = new JPanel();
// holderPanel.setLayout(new BorderLayout());
// holderPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
//
// holderPanel.add(createEditorFields(), BorderLayout.CENTER);
// holderPanel.add(createButtonPanel(), BorderLayout.SOUTH);
//
// setContentPane(holderPanel);
//
//
// pack();
// setLocationRelativeTo(owner);
} }
@Override @Override
@@ -163,15 +148,6 @@ public class PropertyEditorDialog extends ButtonDialog {
return defaultedProperties; return defaultedProperties;
} }
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties, String title) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
editor.setVisible(true);
if (OK.equals(editor.getSelectedButtonCaption())) {
return true;
}
return false;
}
@Override @Override
public void setVisible(boolean b) { public void setVisible(boolean b) {
if (b && componentToFocus != null) { if (b && componentToFocus != null) {
@@ -15,7 +15,6 @@ import org.diylc.common.ITask;
import org.diylc.core.IView; import org.diylc.core.IView;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.plugins.cloud.presenter.CloudException; import org.diylc.plugins.cloud.presenter.CloudException;
import org.diylc.plugins.cloud.presenter.CloudListener;
import org.diylc.plugins.cloud.presenter.CloudPresenter; import org.diylc.plugins.cloud.presenter.CloudPresenter;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
@@ -30,7 +29,7 @@ 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.swingframework.ButtonDialog; import org.diylc.swingframework.ButtonDialog;
public class CloudPlugIn implements IPlugIn, CloudListener { public class CloudPlugIn implements IPlugIn {
private static final String ONLINE_TITLE = "Project Cloud"; private static final String ONLINE_TITLE = "Project Cloud";
@@ -39,7 +38,6 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
private ISwingUI swingUI; private ISwingUI swingUI;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private IPlugInPort thumbnailPresenter; private IPlugInPort thumbnailPresenter;
private CloudPresenter cloudPresenter;
private LibraryAction libraryAction; private LibraryAction libraryAction;
@@ -81,7 +79,6 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public void connect(IPlugInPort plugInPort) { public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.cloudPresenter = new CloudPresenter(this);
initialize(); initialize();
} }
@@ -91,7 +88,7 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public Boolean doInBackground() throws Exception { public Boolean doInBackground() throws Exception {
return cloudPresenter.tryLogInWithToken(); return CloudPresenter.Instance.tryLogInWithToken();
} }
@Override @Override
@@ -113,13 +110,13 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
public CloudBrowserFrame getCloudBrowser() { public CloudBrowserFrame getCloudBrowser() {
if (cloudBrowser == null) { if (cloudBrowser == null) {
cloudBrowser = new CloudBrowserFrame(swingUI, plugInPort, cloudPresenter); cloudBrowser = new CloudBrowserFrame(swingUI, plugInPort);
} }
return cloudBrowser; return cloudBrowser;
} }
public UploadManagerFrame createUploadManagerFrame() { public UploadManagerFrame createUploadManagerFrame() {
return new UploadManagerFrame(swingUI, plugInPort, cloudPresenter); return new UploadManagerFrame(swingUI, plugInPort);
} }
public LibraryAction getLibraryAction() { public LibraryAction getLibraryAction() {
@@ -220,11 +217,12 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
dialog.setVisible(true); dialog.setVisible(true);
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) { if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
try { try {
if (cloudPresenter.logIn(dialog.getUserName(), dialog.getPassword())) { if (CloudPresenter.Instance.logIn(dialog.getUserName(), dialog.getPassword())) {
swingUI swingUI
.showMessage( .showMessage(
"You have successfully logged into the system. You will remain logged in from this machine until logged out.", "You have successfully logged into the system. You will remain logged in from this machine until logged out.",
"Login Successful", IView.INFORMATION_MESSAGE); "Login Successful", IView.INFORMATION_MESSAGE);
loggedIn();
break; break;
} else { } else {
swingUI.showMessage( swingUI.showMessage(
@@ -252,7 +250,8 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
cloudPresenter.logOut(); CloudPresenter.Instance.logOut();
loggedOut();
} }
} }
@@ -275,7 +274,7 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
cloudPresenter.createUserAccount(dialog.getUserName(), dialog.getPassword(), dialog.getEmail(), CloudPresenter.Instance.createUserAccount(dialog.getUserName(), dialog.getPassword(), dialog.getEmail(),
dialog.getWebsite(), dialog.getBio()); dialog.getWebsite(), dialog.getBio());
return null; return null;
} }
@@ -308,14 +307,14 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(cloudPresenter.getUserDetails()); final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(CloudPresenter.Instance.getUserDetails());
dialog.setVisible(true); dialog.setVisible(true);
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) { if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
swingUI.executeBackgroundTask(new ITask<Void>() { swingUI.executeBackgroundTask(new ITask<Void>() {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
cloudPresenter.updateUserDetails(dialog.getEmail(), dialog.getWebsite(), dialog.getBio()); CloudPresenter.Instance.updateUserDetails(dialog.getEmail(), dialog.getWebsite(), dialog.getBio());
return null; return null;
} }
@@ -357,7 +356,7 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
cloudPresenter.updatePassword(dialog.getOldPassword(), dialog.getNewPassword()); CloudPresenter.Instance.updatePassword(dialog.getOldPassword(), dialog.getNewPassword());
return null; return null;
} }
@@ -400,7 +399,7 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
public String[] 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 cloudPresenter.getCategories(); return CloudPresenter.Instance.getCategories();
} }
@Override @Override
@@ -417,7 +416,7 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
cloudPresenter.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(), CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, file, dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, file,
null); null);
return null; return null;
@@ -471,7 +470,6 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
} }
} }
@Override
public void loggedIn() { public void loggedIn() {
getLoginAction().setEnabled(false); getLoginAction().setEnabled(false);
getCreateAccountAction().setEnabled(false); getCreateAccountAction().setEnabled(false);
@@ -482,7 +480,6 @@ public class CloudPlugIn implements IPlugIn, CloudListener {
getManageProjectsAction().setEnabled(true); getManageProjectsAction().setEnabled(true);
} }
@Override
public void loggedOut() { public void loggedOut() {
getLoginAction().setEnabled(true); getLoginAction().setEnabled(true);
getCreateAccountAction().setEnabled(true); getCreateAccountAction().setEnabled(true);
@@ -42,7 +42,6 @@ public class CommentDialog extends JDialog {
private ProjectEntity project; private ProjectEntity project;
private List<CommentEntity> comments; private List<CommentEntity> comments;
private CloudPresenter presenter;
private JPanel mainPanel; private JPanel mainPanel;
private JPanel listPanel; private JPanel listPanel;
@@ -53,19 +52,17 @@ public class CommentDialog extends JDialog {
private ISimpleView cloudUI; private ISimpleView cloudUI;
public CommentDialog(ISimpleView cloudUI, ProjectEntity project, List<CommentEntity> comments, public CommentDialog(ISimpleView cloudUI, ProjectEntity project, List<CommentEntity> comments) {
CloudPresenter presenter) {
super(cloudUI.getOwnerFrame(), "Comments on " + project.getName()); super(cloudUI.getOwnerFrame(), "Comments on " + project.getName());
this.project = project; this.project = project;
this.comments = comments; this.comments = comments;
this.presenter = presenter;
this.cloudUI = cloudUI; this.cloudUI = cloudUI;
setMinimumSize(new Dimension(400, 600)); setMinimumSize(new Dimension(400, 600));
setContentPane(getMainPanel()); setContentPane(getMainPanel());
pack(); pack();
setLocationRelativeTo(cloudUI.getOwnerFrame()); setLocationRelativeTo(cloudUI.getOwnerFrame());
setModal(true); setModal(true);
if (!presenter.isLoggedIn()) { if (!CloudPresenter.Instance.isLoggedIn()) {
getReplyArea().setEnabled(false); getReplyArea().setEnabled(false);
getReplyArea().setText("Must be logged in to reply."); getReplyArea().setText("Must be logged in to reply.");
getSendButton().setEnabled(false); getSendButton().setEnabled(false);
@@ -148,7 +145,7 @@ public class CommentDialog extends JDialog {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
presenter.postComment(project.getId(), comment); CloudPresenter.Instance.postComment(project.getId(), comment);
return null; return null;
} }
@@ -162,7 +159,7 @@ public class CommentDialog extends JDialog {
getReplyArea().setText(""); getReplyArea().setText("");
CommentEntity newComment = new CommentEntity(); CommentEntity newComment = new CommentEntity();
newComment.setPostedAt(JUST_NOW); newComment.setPostedAt(JUST_NOW);
newComment.setUsername(presenter.getCurrentUsername()); newComment.setUsername(CloudPresenter.Instance.getCurrentUsername());
newComment.setComment(comment); newComment.setComment(comment);
addComment(newComment).requestFocusInWindow(); addComment(newComment).requestFocusInWindow();
getListPanel().revalidate(); getListPanel().revalidate();
@@ -34,6 +34,7 @@ public class UserEditDialog extends ButtonDialog {
private JTextField emailField; private JTextField emailField;
private JTextField websiteField; private JTextField websiteField;
private JTextArea bioArea; private JTextArea bioArea;
private JScrollPane bioPane;
private String userName; private String userName;
private String password; private String password;
@@ -130,7 +131,7 @@ public class UserEditDialog extends ButtonDialog {
gbc.gridy = 5; gbc.gridy = 5;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(new JScrollPane(getBioArea()), gbc); mainPanel.add(getBioPane(), gbc);
} }
return mainPanel; return mainPanel;
} }
@@ -254,7 +255,7 @@ public class UserEditDialog extends ButtonDialog {
return emailField; return emailField;
} }
public JTextField getWebsiteField() { private JTextField getWebsiteField() {
if (websiteField == null) { if (websiteField == null) {
websiteField = new JTextField(); websiteField = new JTextField();
if (existingEntity != null) if (existingEntity != null)
@@ -280,14 +281,23 @@ public class UserEditDialog extends ButtonDialog {
return websiteField; return websiteField;
} }
public JTextArea getBioArea() { private JScrollPane getBioPane() {
if (bioPane == null) {
bioPane = new JScrollPane(getBioArea());
bioPane.setPreferredSize(new Dimension(192, 64));
bioPane.setBorder(getBioArea().getBorder());
getBioArea().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
}
return bioPane;
}
private JTextArea getBioArea() {
if (bioArea == null) { if (bioArea == null) {
bioArea = new HTMLTextArea(); bioArea = new HTMLTextArea();
if (existingEntity != null) if (existingEntity != null)
bioArea.setText(existingEntity.getBio()); bioArea.setText(existingEntity.getBio());
bioArea.setFont(getUserNameField().getFont()); bioArea.setFont(getUserNameField().getFont());
bioArea.setBorder(getUserNameField().getBorder()); bioArea.setBorder(getUserNameField().getBorder());
bioArea.setPreferredSize(new Dimension(192, 69));
bioArea.getDocument().addDocumentListener(new DocumentListener() { bioArea.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
@@ -27,7 +27,7 @@ import org.diylc.core.IView;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.plugins.cloud.model.ProjectEntity; 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.SearchSession;
import org.diylc.swing.ISimpleView; import org.diylc.swing.ISimpleView;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
import org.diylc.utils.Pair; import org.diylc.utils.Pair;
@@ -54,19 +54,17 @@ public class CloudBrowserFrame extends JFrame implements ISimpleView {
private ResultsScrollPanel resultsScrollPane; private ResultsScrollPanel resultsScrollPane;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter; private SearchSession searchSession;
private PagingProvider pagingProvider;
private ISwingUI swingUI; private ISwingUI swingUI;
public CloudBrowserFrame(ISwingUI swingUI, IPlugInPort plugInPort, CloudPresenter cloudPresenter) { public CloudBrowserFrame(ISwingUI swingUI, IPlugInPort plugInPort) {
super(TITLE); super(TITLE);
this.swingUI = swingUI; this.swingUI = swingUI;
this.setIconImage(IconLoader.Cloud.getImage()); this.setIconImage(IconLoader.Cloud.getImage());
this.setPreferredSize(new Dimension(700, 640)); this.setPreferredSize(new Dimension(700, 640));
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.cloudPresenter = cloudPresenter; this.searchSession = new SearchSession();
this.pagingProvider = new PagingProvider(cloudPresenter);
setContentPane(getSearchPanel()); setContentPane(getSearchPanel());
this.pack(); this.pack();
@@ -85,7 +83,7 @@ public class CloudBrowserFrame extends JFrame implements ISimpleView {
@Override @Override
public Pair<String[], String[]> doInBackground() throws Exception { public Pair<String[], String[]> doInBackground() throws Exception {
return new Pair<String[], String[]>(cloudPresenter.getCategories(), cloudPresenter.getSortings()); return new Pair<String[], String[]>(CloudPresenter.Instance.getCategories(), CloudPresenter.Instance.getSortings());
} }
@Override @Override
@@ -181,7 +179,7 @@ public class CloudBrowserFrame extends JFrame implements ISimpleView {
private ResultsScrollPanel getResultsScrollPane() { private ResultsScrollPanel getResultsScrollPane() {
if (resultsScrollPane == null) { if (resultsScrollPane == null) {
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider, cloudPresenter, false); resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, searchSession, false);
} }
return resultsScrollPane; return resultsScrollPane;
} }
@@ -192,7 +190,7 @@ public class CloudBrowserFrame extends JFrame implements ISimpleView {
@Override @Override
public List<ProjectEntity> doInBackground() throws Exception { public List<ProjectEntity> doInBackground() throws Exception {
return pagingProvider.startSession(getSearchHeaderPanel().getSearchText(), return searchSession.startSession(getSearchHeaderPanel().getSearchText(),
getSearchHeaderPanel().getCategory(), getSearchHeaderPanel().getSorting()); getSearchHeaderPanel().getCategory(), getSearchHeaderPanel().getSorting());
} }
@@ -42,7 +42,7 @@ import org.diylc.images.IconLoader;
import org.diylc.plugins.cloud.model.CommentEntity; import org.diylc.plugins.cloud.model.CommentEntity;
import org.diylc.plugins.cloud.model.ProjectEntity; 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.SearchSession;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
import org.diylc.swing.ISimpleView; import org.diylc.swing.ISimpleView;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
@@ -59,7 +59,7 @@ import org.diylc.swingframework.ButtonDialog;
* Component that is capable of showing a list of {@link ProjectEntity} objects. Can work in paging * Component that is capable of showing a list of {@link ProjectEntity} objects. Can work in paging
* mode and pull one page of data at a time. * mode and pull one page of data at a time.
* *
* @see {@link PagingProvider} * @see {@link SearchSession}
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -88,22 +88,19 @@ public class ResultsScrollPanel extends JScrollPane {
* This flag tells us whether the loadMoreLabel should invoke a new data pull or not. * This flag tells us whether the loadMoreLabel should invoke a new data pull or not.
*/ */
private boolean armed; private boolean armed;
private PagingProvider provider; private SearchSession searchSession;
private CloudPresenter cloudPresenter;
private Icon spinnerIcon = IconLoader.Spinning.getIcon(); private Icon spinnerIcon = IconLoader.Spinning.getIcon();
private boolean showEditControls; private boolean showEditControls;
public ResultsScrollPanel(ISwingUI mainUI, ISimpleView cloudUI, IPlugInPort plugInPort, PagingProvider provider, public ResultsScrollPanel(ISwingUI mainUI, ISimpleView cloudUI, IPlugInPort plugInPort, SearchSession searchSession,
CloudPresenter cloudPresenter, boolean showEditControls) { boolean showEditControls) {
super(); super();
this.mainUI = mainUI; this.mainUI = mainUI;
this.cloudUI = cloudUI; this.cloudUI = cloudUI;
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.provider = provider; this.searchSession = searchSession;
this.cloudPresenter = cloudPresenter;
this.showEditControls = showEditControls; this.showEditControls = showEditControls;
this.getVerticalScrollBar().setUnitIncrement(16); this.getVerticalScrollBar().setUnitIncrement(16);
@@ -174,7 +171,7 @@ public class ResultsScrollPanel extends JScrollPane {
getViewport().setViewPosition(old); getViewport().setViewPosition(old);
} }
}); });
if (provider != null && provider.hasMoreData()) { if (searchSession != null && searchSession.hasMoreData()) {
getLoadMoreLabel().setText("Querying the cloud for more results..."); getLoadMoreLabel().setText("Querying the cloud for more results...");
getLoadMoreLabel().setIcon(spinnerIcon); getLoadMoreLabel().setIcon(spinnerIcon);
} else { } else {
@@ -211,7 +208,7 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public List<CommentEntity> doInBackground() throws Exception { public List<CommentEntity> doInBackground() throws Exception {
return cloudPresenter.getComments(project.getId()); return CloudPresenter.Instance.getComments(project.getId());
} }
@Override @Override
@@ -222,7 +219,7 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public void complete(List<CommentEntity> result) { public void complete(List<CommentEntity> result) {
CommentDialog dialog = new CommentDialog(cloudUI, project, result, cloudPresenter); CommentDialog dialog = new CommentDialog(cloudUI, project, result);
dialog.setVisible(true); dialog.setVisible(true);
} }
@@ -320,7 +317,7 @@ public class ResultsScrollPanel extends JScrollPane {
editButton.addMouseListener(new MouseAdapter() { editButton.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
List<PropertyWrapper> projectProperties = cloudPresenter.getProjectProperties(project); List<PropertyWrapper> projectProperties = CloudPresenter.Instance.getProjectProperties(project);
PropertyEditorDialog editor = PropertyEditorDialog editor =
DialogFactory.getInstance().createPropertyEditorDialog(cloudUI.getOwnerFrame(), projectProperties, DialogFactory.getInstance().createPropertyEditorDialog(cloudUI.getOwnerFrame(), projectProperties,
"Edit Published Project"); "Edit Published Project");
@@ -341,8 +338,8 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public ProjectEntity doInBackground() throws Exception { public ProjectEntity doInBackground() throws Exception {
cloudPresenter.updateProjectDetails(project, plugInPort.getCurrentVersionNumber().toString()); CloudPresenter.Instance.updateProjectDetails(project, plugInPort.getCurrentVersionNumber().toString());
return cloudPresenter.fetchUserUploads(project.getId()).get(0); return CloudPresenter.Instance.fetchUserUploads(project.getId()).get(0);
} }
@Override @Override
@@ -389,7 +386,7 @@ public class ResultsScrollPanel extends JScrollPane {
public String[] 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 cloudPresenter.getCategories(); return CloudPresenter.Instance.getCategories();
} }
@Override @Override
@@ -406,10 +403,10 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public ProjectEntity doInBackground() throws Exception { public ProjectEntity doInBackground() throws Exception {
cloudPresenter.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(), CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile,
file, project.getId()); file, project.getId());
return cloudPresenter.fetchUserUploads(project.getId()).get(0); return CloudPresenter.Instance.fetchUserUploads(project.getId()).get(0);
} }
@Override @Override
@@ -463,7 +460,7 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public Void doInBackground() throws Exception { public Void doInBackground() throws Exception {
cloudPresenter.deleteProject(project.getId()); CloudPresenter.Instance.deleteProject(project.getId());
return null; return null;
} }
@@ -601,14 +598,14 @@ public class ResultsScrollPanel extends JScrollPane {
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
if (armed && provider != null && provider.hasMoreData()) { if (armed && searchSession != null && searchSession.hasMoreData()) {
// disarm immediately so we don't trigger successive requests to the provider // disarm immediately so we don't trigger successive requests to the provider
armed = false; armed = false;
SwingWorker<List<ProjectEntity>, Void> worker = new SwingWorker<List<ProjectEntity>, Void>() { SwingWorker<List<ProjectEntity>, Void> worker = new SwingWorker<List<ProjectEntity>, Void>() {
@Override @Override
protected List<ProjectEntity> doInBackground() throws Exception { protected List<ProjectEntity> doInBackground() throws Exception {
return provider.requestMoreData(); return searchSession.requestMoreData();
} }
@Override @Override
@@ -29,17 +29,15 @@ public class UploadManagerFrame extends JFrame implements ISimpleView {
private ResultsScrollPanel resultsScrollPane; private ResultsScrollPanel resultsScrollPane;
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private CloudPresenter cloudPresenter;
private ISwingUI swingUI; private ISwingUI swingUI;
public UploadManagerFrame(ISwingUI swingUI, IPlugInPort plugInPort, CloudPresenter cloudPresenter) { public UploadManagerFrame(ISwingUI swingUI, IPlugInPort plugInPort) {
super(TITLE); super(TITLE);
this.swingUI = swingUI; this.swingUI = swingUI;
this.setIconImage(IconLoader.CloudGear.getImage()); this.setIconImage(IconLoader.CloudGear.getImage());
this.setPreferredSize(new Dimension(700, 640)); this.setPreferredSize(new Dimension(700, 640));
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.cloudPresenter = cloudPresenter;
setContentPane(getResultsScrollPane()); setContentPane(getResultsScrollPane());
this.pack(); this.pack();
@@ -51,7 +49,7 @@ public class UploadManagerFrame extends JFrame implements ISimpleView {
private ResultsScrollPanel getResultsScrollPane() { private ResultsScrollPanel getResultsScrollPane() {
if (resultsScrollPane == null) { if (resultsScrollPane == null) {
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, null, cloudPresenter, true); resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, null, true);
} }
return resultsScrollPane; return resultsScrollPane;
} }
@@ -62,7 +60,7 @@ public class UploadManagerFrame extends JFrame implements ISimpleView {
@Override @Override
public List<ProjectEntity> doInBackground() throws Exception { public List<ProjectEntity> doInBackground() throws Exception {
return cloudPresenter.fetchUserUploads(null); return CloudPresenter.Instance.fetchUserUploads(null);
} }
@Override @Override
+8
View File
@@ -1362,6 +1362,14 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Make order of items in the 'Edit Project' dialog more logical</description> <description>Make order of items in the 'Edit Project' dialog more logical</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Better support for V1 file import</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Toggle switch spacing can be changed</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Allow multi-line project description</description> <description>Allow multi-line project description</description>