simplified auto-create logic

cloud management work
This commit is contained in:
bancika
2016-10-31 13:11:53 +01:00
parent a74f00a5fd
commit f9a32ebce3
13 changed files with 77 additions and 83 deletions
@@ -31,14 +31,13 @@ public class ComponentType {
private BomPolicy bomPolicy; private BomPolicy bomPolicy;
private boolean autoEdit; private boolean autoEdit;
private boolean rotatable; private boolean rotatable;
private IAutoCreator autoCreator;
private KeywordPolicy keywordPolicy; private KeywordPolicy keywordPolicy;
private String keywordTag; private String keywordTag;
public ComponentType(String name, String description, CreationMethod creationMethod, String category, public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder, String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable, boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable,
IAutoCreator autoCreator, KeywordPolicy keywordPolicy, String keywordTag) { KeywordPolicy keywordPolicy, String keywordTag) {
super(); super();
this.name = name; this.name = name;
this.description = description; this.description = description;
@@ -54,7 +53,6 @@ public class ComponentType {
this.bomPolicy = bomPolicy; this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit; this.autoEdit = autoEdit;
this.rotatable = rotatable; this.rotatable = rotatable;
this.autoCreator = autoCreator;
this.keywordPolicy = keywordPolicy; this.keywordPolicy = keywordPolicy;
this.keywordTag = keywordTag; this.keywordTag = keywordTag;
} }
@@ -115,10 +113,6 @@ public class ComponentType {
return rotatable; return rotatable;
} }
public IAutoCreator getAutoCreateor() {
return autoCreator;
}
public KeywordPolicy getKeywordPolicy() { public KeywordPolicy getKeywordPolicy() {
return keywordPolicy; return keywordPolicy;
} }
@@ -1,9 +0,0 @@
package org.diylc.core.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoCreator {
public Class<? extends IAutoCreator> creatorClass();
}
@@ -20,11 +20,9 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.core.CreationMethod; import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IPropertyValidator; import org.diylc.core.IPropertyValidator;
import org.diylc.core.annotations.AutoCreator;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
/** /**
@@ -73,7 +71,6 @@ public class ComponentProcessor {
BomPolicy bomPolicy; BomPolicy bomPolicy;
boolean autoEdit; boolean autoEdit;
boolean rotatable; boolean rotatable;
IAutoCreator autoCreator = null;
KeywordPolicy keywordPolicy; KeywordPolicy keywordPolicy;
String keywordTag; String keywordTag;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) { if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
@@ -108,14 +105,6 @@ public class ComponentProcessor {
keywordPolicy = KeywordPolicy.NEVER_SHOW; keywordPolicy = KeywordPolicy.NEVER_SHOW;
keywordTag = null; keywordTag = null;
} }
if (clazz.isAnnotationPresent(AutoCreator.class)) {
AutoCreator annotation = clazz.getAnnotation(AutoCreator.class);
try {
autoCreator = annotation.creatorClass().newInstance();
} catch (Exception e) {
LOG.error("Could not instantiate auto-creator for " + name, e);
}
}
icon = null; icon = null;
// Draw component icon. // Draw component icon.
try { try {
@@ -134,7 +123,7 @@ public class ComponentProcessor {
} }
ComponentType componentType = ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder, new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy, keywordTag); flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, keywordPolicy, keywordTag);
componentTypeMap.put(clazz.getName(), componentType); componentTypeMap.put(clazz.getName(), componentType);
return componentType; return componentType;
} }
@@ -41,7 +41,7 @@ public class InstantiationManager {
private static final ComponentType clipboardType = new ComponentType("Clipboard contents", private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null, "Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, true, null, KeywordPolicy.NEVER_SHOW, null); false, true, KeywordPolicy.NEVER_SHOW, null);
public InstantiationManager() {} public InstantiationManager() {}
@@ -312,42 +312,27 @@ public class Presenter implements IPlugInPort {
Set<Class<?>> componentTypeClasses = null; Set<Class<?>> componentTypeClasses = null;
try { try {
componentTypeClasses = Utils.getClasses("org.diylc.components"); componentTypeClasses = Utils.getClasses("org.diylc.components");
} catch (Exception e) {
// TODO Auto-generated catch block for (Class<?> clazz : componentTypeClasses) {
e.printStackTrace(); if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
} ComponentType componentType =
// for (String path : classPath) { ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
// path = path.replace('\\', '/'); List<ComponentType> nestedList;
// File f = new File(path); if (componentTypes.containsKey(componentType.getCategory())) {
// try { nestedList = componentTypes.get(componentType.getCategory());
// if (f.isDirectory()) { } else {
// LOG.info("Scanning folder for components: " nestedList = new ArrayList<ComponentType>();
// + f.getAbsolutePath()); componentTypes.put(componentType.getCategory(), nestedList);
// componentTypeClasses.addAll(JarScanner.getInstance() }
// .scanFolder(path, IDIYComponent.class)); nestedList.add(componentType);
// } else {
// LOG.info("Scanning JAR for components: "
// + f.getAbsolutePath());
// componentTypeClasses.addAll(JarScanner.getInstance()
// .scanJar(f, IDIYComponent.class));
// }
// } catch (Exception e) {
// LOG.warn("Could not scan path " + path, e);
// }
// }
for (Class<?> clazz : componentTypeClasses) {
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
List<ComponentType> nestedList;
if (componentTypes.containsKey(componentType.getCategory())) {
nestedList = componentTypes.get(componentType.getCategory());
} else {
nestedList = new ArrayList<ComponentType>();
componentTypes.put(componentType.getCategory(), nestedList);
} }
nestedList.add(componentType);
} }
for (Map.Entry<String, List<ComponentType>> e : componentTypes.entrySet()) {
LOG.debug(e.getKey() + ": " + e.getValue());
}
} catch (Exception e) {
LOG.error("Error loading component types", e);
} }
} }
return componentTypes; return componentTypes;
@@ -356,11 +341,17 @@ public class Presenter implements IPlugInPort {
public List<IAutoCreator> getAutoCreators() { public List<IAutoCreator> getAutoCreators() {
if (autoCreators == null) { if (autoCreators == null) {
autoCreators = new ArrayList<IAutoCreator>(); autoCreators = new ArrayList<IAutoCreator>();
for (Map.Entry<String, List<ComponentType>> entry : getComponentTypes().entrySet()) { Set<Class<?>> classes = null;
for (ComponentType t : entry.getValue()) { try {
if (t.getAutoCreateor() != null) classes = Utils.getClasses("org.diylc.components.autocreate");
autoCreators.add(t.getAutoCreateor()); for (Class<?> clazz : classes) {
if (IAutoCreator.class.isAssignableFrom(clazz)) {
autoCreators.add((IAutoCreator) clazz.newInstance());
LOG.debug("Loaded auto-cretor: " + clazz.getName());
}
} }
} catch (Exception e) {
LOG.error("Error loading auto-creator types", e);
} }
} }
return autoCreators; return autoCreators;
@@ -1,10 +1,11 @@
package org.diylc.components.connectivity; package org.diylc.components.autocreate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.components.connectivity.SolderPad;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.IAutoCreator; import org.diylc.core.annotations.IAutoCreator;
@@ -11,7 +11,6 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.AutoCreator;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -21,7 +20,6 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@AutoCreator(creatorClass = SolderPadAutoCreator.class)
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false, description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
@@ -32,10 +32,10 @@ public enum IconLoader {
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"), Arrow( "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( "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( "id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
"data_find.png"), CloudDownload("cloud_download.png"), CloudUpload("cloud_upload.png"), NavLeftBlue( "data_find.png"), CloudDownload("cloud_download.png"), CloudDelete("cloud_delete.png"), CloudUpload(
"nav_left_blue.png"), NavRightBlue("nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg( "cloud_upload.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue("nav_right_blue.png"), MissingImage(
"cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait("cloud_wait.png"), Spinning("spinning.gif"), Megaphone( "missing_image.png"), CloudBg("cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait("cloud_wait.png"), Spinning(
"megaphone.png"), Download("download.png"), Eye("eye.png"), Messages("messages.png"); "spinning.gif"), Megaphone("megaphone.png"), Download("download.png"), Eye("eye.png"), Messages("messages.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

@@ -176,7 +176,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); resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider, cloudPresenter, false);
} }
return resultsScrollPane; return resultsScrollPane;
} }
@@ -2,6 +2,7 @@ package org.diylc.swing.plugins.cloud.view.browser;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@@ -81,14 +82,17 @@ public class ResultsScrollPanel extends JScrollPane {
private Icon spinnerIcon = IconLoader.Spinning.getIcon(); private Icon spinnerIcon = IconLoader.Spinning.getIcon();
private boolean showEditControls;
public ResultsScrollPanel(ISwingUI mainUI, ISimpleView cloudUI, IPlugInPort plugInPort, PagingProvider provider, public ResultsScrollPanel(ISwingUI mainUI, ISimpleView cloudUI, IPlugInPort plugInPort, PagingProvider provider,
CloudPresenter cloudPresenter) { CloudPresenter cloudPresenter, 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.provider = provider;
this.cloudPresenter = cloudPresenter; this.cloudPresenter = cloudPresenter;
this.showEditControls = showEditControls;
this.getVerticalScrollBar().setUnitIncrement(16); this.getVerticalScrollBar().setUnitIncrement(16);
this.setBorder(null); this.setBorder(null);
@@ -230,6 +234,7 @@ public class ResultsScrollPanel extends JScrollPane {
downloadButton.setBorderPainted(false); downloadButton.setBorderPainted(false);
downloadButton.setContentAreaFilled(false); downloadButton.setContentAreaFilled(false);
downloadButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); downloadButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
downloadButton.setToolTipText("Download to local drive");
downloadButton.addActionListener(new ActionListener() { downloadButton.addActionListener(new ActionListener() {
@Override @Override
@@ -292,6 +297,25 @@ public class ResultsScrollPanel extends JScrollPane {
} }
}); });
JButton reuploadButton = new JButton(IconLoader.CloudUpload.getIcon());
reuploadButton.setContentAreaFilled(false);
reuploadButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
reuploadButton.setToolTipText("Re-upload to the cloud");
JButton deleteButton = new JButton(IconLoader.CloudDelete.getIcon());
deleteButton.setContentAreaFilled(false);
deleteButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
deleteButton.setToolTipText("Delete from the cloud");
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.setBackground(Color.white);
// buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.add(downloadButton);
if (showEditControls) {
buttonPanel.add(reuploadButton);
buttonPanel.add(deleteButton);
}
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
@@ -308,6 +332,10 @@ public class ResultsScrollPanel extends JScrollPane {
gbc.insets = new Insets(2, 6, 2, 2); gbc.insets = new Insets(2, 6, 2, 2);
getResultsPanel().add(nameLabel, gbc); getResultsPanel().add(nameLabel, gbc);
gbc.gridx++;
gbc.weightx = 0.1;
getResultsPanel().add(new JLabel(), gbc);
gbc.gridx++; gbc.gridx++;
gbc.weightx = 0; gbc.weightx = 0;
getResultsPanel().add(commentLabel, gbc); getResultsPanel().add(commentLabel, gbc);
@@ -322,7 +350,7 @@ public class ResultsScrollPanel extends JScrollPane {
gbc.gridx = 1; gbc.gridx = 1;
gbc.weighty = 1; gbc.weighty = 1;
gbc.weightx = 1; gbc.weightx = 1;
gbc.gridwidth = 5; gbc.gridwidth = 6;
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(2, 6, 2, 2); gbc.insets = new Insets(2, 6, 2, 2);
@@ -330,19 +358,22 @@ public class ResultsScrollPanel extends JScrollPane {
gbc.gridy++; gbc.gridy++;
gbc.gridwidth = 1; gbc.gridwidth = 1;
gbc.weightx = 1;
gbc.fill = GridBagConstraints.NONE; gbc.fill = GridBagConstraints.NONE;
gbc.weighty = 0; gbc.weighty = 0;
getResultsPanel().add(categoryLabel, gbc); getResultsPanel().add(categoryLabel, gbc);
gbc.gridx++; gbc.gridx++;
gbc.gridheight = 3; gbc.gridheight = 3;
gbc.gridwidth = 3; gbc.gridwidth = 4;
gbc.weightx = 0;
gbc.insets = new Insets(2, 2, 2, 2); gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.SOUTHEAST; gbc.anchor = GridBagConstraints.SOUTHEAST;
getResultsPanel().add(downloadButton, gbc); getResultsPanel().add(buttonPanel, gbc);
gbc.gridy++; gbc.gridy++;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 1;
gbc.gridheight = 1; gbc.gridheight = 1;
gbc.insets = new Insets(2, 6, 2, 2); gbc.insets = new Insets(2, 6, 2, 2);
gbc.anchor = GridBagConstraints.NORTHWEST; gbc.anchor = GridBagConstraints.NORTHWEST;
@@ -51,7 +51,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); resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, null, cloudPresenter, true);
} }
return resultsScrollPane; return resultsScrollPane;
} }
@@ -9,8 +9,7 @@ import org.apache.log4j.Logger;
import org.diylc.common.EventType; import org.diylc.common.EventType;
import org.diylc.common.IPlugIn; import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.components.connectivity.SolderPad; import org.diylc.components.autocreate.SolderPadAutoCreator;
import org.diylc.components.connectivity.SolderPadAutoCreator;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.swing.ActionFactory; import org.diylc.swing.ActionFactory;