Browse Source

REPORT-27647 模板组件的安装下载-模板组件复用插件

1、抽出一个更通用的接口来添加面板
2、为共享加载器添加插件实现
persist/11.0
Harrison 5 years ago
parent
commit
5b0c5dc299
  1. 25
      designer-base/src/main/java/com/fr/design/fun/PropertyItemPaneProvider.java
  2. 31
      designer-base/src/main/java/com/fr/design/fun/impl/AbstractPropertyItemPaneProvider.java
  3. 139
      designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java
  4. 17
      designer-base/src/main/java/com/fr/design/mainframe/PaneHolder.java
  5. 68
      designer-base/src/main/java/com/fr/design/mainframe/PropertyItemBean.java
  6. 8
      designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java
  7. 392
      designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java
  8. 61
      designer-form/src/main/java/com/fr/design/mainframe/JForm.java
  9. 23
      designer-form/src/main/java/com/fr/design/mainframe/component/ComponentLibraryManager.java
  10. 72
      designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneCreator.java
  11. 412
      designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneProcessorImpl.java

25
designer-base/src/main/java/com/fr/design/fun/PropertyItemPaneProvider.java

@ -0,0 +1,25 @@
package com.fr.design.fun;
import com.fr.design.mainframe.PaneHolder;
import com.fr.design.mainframe.PropertyItemBean;
import com.fr.stable.fun.mark.Mutable;
import org.jetbrains.annotations.Nullable;
/**
* created by Harrison on 2020/03/23
**/
public interface PropertyItemPaneProvider<T> extends Mutable {
int CURRENT_LEVEL = 1;
String XML_TAG = "PropertyItemPaneProvider";
String key();
PropertyItemBean getItem();
@Nullable
PaneHolder<T> getPaneHolder(Class<?> clazz);
String replaceKey();
}

31
designer-base/src/main/java/com/fr/design/fun/impl/AbstractPropertyItemPaneProvider.java

@ -0,0 +1,31 @@
package com.fr.design.fun.impl;
import com.fr.design.fun.PropertyItemPaneProvider;
import com.fr.design.mainframe.PaneHolder;
import com.fr.stable.fun.impl.AbstractProvider;
import com.fr.stable.fun.mark.API;
/**
* created by Harrison on 2020/03/23
**/
@API(level = PropertyItemPaneProvider.CURRENT_LEVEL)
public abstract class AbstractPropertyItemPaneProvider<T> extends AbstractProvider implements PropertyItemPaneProvider<T> {
@Override
public PaneHolder<T> getPaneHolder(Class<?> clazz) {
if (sign().equals(clazz)) {
return getPathHolder0();
}
return null;
}
protected abstract PaneHolder<T> getPathHolder0();
protected abstract Class<T> sign();
@Override
public int currentAPILevel() {
return PropertyItemPaneProvider.CURRENT_LEVEL;
}
}

139
designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java

@ -3,7 +3,9 @@ package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.constants.UIConstants;
import com.fr.design.fun.PropertyItemPaneProvider;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.icontainer.UIEastResizableContainer;
@ -12,12 +14,38 @@ import com.fr.design.layout.VerticalFlowLayout;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.general.FRFont;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginRuntime;
import com.fr.plugin.injectable.PluginModule;
import com.fr.plugin.manage.PluginFilter;
import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener;
import com.fr.plugin.observer.PluginEventType;
import com.fr.plugin.observer.PluginListenerRegistration;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@ -26,6 +54,7 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -101,9 +130,95 @@ public class EastRegionContainerPane extends UIEastResizableContainer {
defaultAuthorityPane = getDefaultPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Not_Support_Authority_Edit"));
switchMode(PropertyMode.REPORT);
setContainerWidth(CONTAINER_WIDTH);
initPluginPane();
listenPlugin();
}
private void listenPlugin() {
PluginFilter filter = new PluginFilter() {
@Override
public boolean accept(PluginContext context) {
return context.contain(PropertyItemPaneProvider.XML_TAG);
}
};
PluginListenerRegistration.getInstance().listen(
PluginEventType.AfterRun,
new PluginEventListener() {
@Override
public void on(PluginEvent event) {
PluginContext context = event.getContext();
PluginRuntime runtime = context.getRuntime();
Set<PropertyItemPaneProvider> providers = runtime.get(PropertyItemPaneProvider.XML_TAG);
for (PropertyItemPaneProvider provider : providers) {
addPropertyItem(provider);
}
updateAllPropertyPane();
}
}, filter);
PluginListenerRegistration.getInstance().listen(
PluginEventType.BeforeStop,
new PluginEventListener(10) {
@Override
public void on(PluginEvent event) {
PluginContext context = event.getContext();
PluginRuntime runtime = context.getRuntime();
Set<PropertyItemPaneProvider> providers = runtime.get(PropertyItemPaneProvider.XML_TAG);
for (PropertyItemPaneProvider provider : providers) {
removePropertyItem(provider);
}
updateAllPropertyPane();
}
}, filter);
}
private void removePropertyItem(PropertyItemPaneProvider provider) {
propertyItemMap.remove(provider.key());
String replaceKey = provider.replaceKey();
PropertyItem replaceItem = propertyItemMap.get(replaceKey);
if (replaceItem != null) {
replaceItem.setReplace(false);
}
}
private void initPluginPane() {
ExtraDesignClassManager classManager = PluginModule.getAgent(PluginModule.ExtraDesign);
Set<PropertyItemPaneProvider> providers = classManager.getArray(PropertyItemPaneProvider.XML_TAG);
for (PropertyItemPaneProvider provider : providers) {
addPropertyItem(provider);
}
}
private void addPropertyItem(PropertyItemPaneProvider provider) {
String key = provider.key();
PropertyItemBean itemBean = provider.getItem();
PropertyItem propertyItem = new PropertyItem(itemBean.getName(),
itemBean.getTitle(),
itemBean.getBtnIconName(),
itemBean.getVisibleModes(),
itemBean.getEnableModes());
UIButton button = propertyItem.getButton();
List<ActionListener> buttonListeners = itemBean.getButtonListeners();
for (ActionListener buttonListener : buttonListeners) {
button.addActionListener(buttonListener);
}
propertyItemMap.put(key, propertyItem);
String replaceKey = provider.replaceKey();
PropertyItem replaceItem = propertyItemMap.get(replaceKey);
if (replaceItem != null) {
replaceItem.setReplace(true);
}
}
private void initPropertyItemList() {
propertyItemMap = new LinkedHashMap<>(); // 有序map
// 单元格元素
PropertyItem cellElement = new PropertyItem(KEY_CELL_ELEMENT, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cell_Element"),
@ -360,6 +475,11 @@ public class EastRegionContainerPane extends UIEastResizableContainer {
public void replaceConfiguredRolesPane(JComponent pane) {
propertyItemMap.get(KEY_CONFIGURED_ROLES).replaceContentPane(pane);
}
public void replaceKeyPane(String key, JComponent pane) {
propertyItemMap.get(key).replaceContentPane(pane);
}
public JComponent getConfiguredRolesPane() {
return propertyItemMap.get(KEY_CONFIGURED_ROLES).getContentPane();
@ -511,6 +631,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer {
private PopupDialog popupDialog; // 弹出框
private boolean isPoppedOut = false; // 是否弹出
private boolean isVisible = true; // 是否可见
private boolean replace = false; // 是否被替代
private boolean isEnabled = true; // 是否可用
private Set<PropertyMode> visibleModes;
private Set<PropertyMode> enableModes;
@ -563,13 +684,19 @@ public class EastRegionContainerPane extends UIEastResizableContainer {
}
public boolean isVisible() {
return isVisible;
// 取决于可见且未替代
return isVisible && !replace;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
public void setReplace(boolean replace) {
this.replace = replace;
}
public boolean isEnabled() {
return isEnabled;
}

17
designer-base/src/main/java/com/fr/design/mainframe/PaneHolder.java

@ -0,0 +1,17 @@
package com.fr.design.mainframe;
import javax.swing.JPanel;
/**
* created by Harrison on 2020/03/23
**/
public interface PaneHolder<T> {
/**
* 得到 Pane
*
* @param arg 参数
* @return 面板
*/
JPanel getInstance(T arg);
}

68
designer-base/src/main/java/com/fr/design/mainframe/PropertyItemBean.java

@ -0,0 +1,68 @@
package com.fr.design.mainframe;
import java.awt.event.ActionListener;
import java.util.List;
/**
* created by Harrison on 2020/03/23
**/
public class PropertyItemBean {
private String name;
private String title;
private String btnIconName;
private EastRegionContainerPane.PropertyMode[] visibleModes;
private EastRegionContainerPane.PropertyMode[] enableModes;
private List<ActionListener> buttonListeners;
public PropertyItemBean() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBtnIconName() {
return btnIconName;
}
public void setBtnIconName(String btnIconName) {
this.btnIconName = btnIconName;
}
public EastRegionContainerPane.PropertyMode[] getVisibleModes() {
return visibleModes;
}
public void setVisibleModes(EastRegionContainerPane.PropertyMode[] visibleModes) {
this.visibleModes = visibleModes;
}
public EastRegionContainerPane.PropertyMode[] getEnableModes() {
return enableModes;
}
public void setEnableModes(EastRegionContainerPane.PropertyMode[] enableModes) {
this.enableModes = enableModes;
}
public List<ActionListener> getButtonListeners() {
return buttonListeners;
}
public void setButtonListeners(List<ActionListener> buttonListeners) {
this.buttonListeners = buttonListeners;
}
}

8
designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java

@ -11,7 +11,7 @@ import java.awt.event.ActionEvent;
/**
* created by Harrison on 2020/03/22
**/
public class SnapChatUpdateAction extends UpdateAction implements SnapChat {
public abstract class SnapChatUpdateAction extends UpdateAction implements SnapChat {
private SnapChatKey uniqueKey;
@ -20,15 +20,13 @@ public class SnapChatUpdateAction extends UpdateAction implements SnapChat {
}
@Override
public void actionPerformed(ActionEvent e) {
public final void actionPerformed(ActionEvent e) {
markRead();
actionPerformed0(e);
}
protected void actionPerformed0(ActionEvent e) {
}
protected abstract void actionPerformed0(ActionEvent e);
@Override
public boolean hasRead() {

392
designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java

@ -1,19 +1,43 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.base.FRContext;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.component.pane.ComponentLibraryPaneCreator;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.manage.PluginFilter;
import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener;
import com.fr.plugin.observer.PluginListenerRegistration;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.form.share.ShareLoader;
import com.fr.form.ui.SharableWidgetBindInfo;
import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created with IntelliJ IDEA.
@ -22,6 +46,19 @@ import java.awt.BorderLayout;
* Time: 下午8:18
*/
public class FormWidgetDetailPane extends FormDockView{
private static final int LOCAL_WIDGET_LABEL_WIDTH = 90;
private UIScrollPane downPane;
private JPanel reuWidgetPanel;
private UIComboBox comboBox;
private SharableWidgetBindInfo[] elCaseBindInfoList;
private UIButton deleteButton;
private JPanel editPanel;
private JPanel resetPanel;
private JPanel menutPanelNorthPane;
private SwingWorker sw;
//组件面板是否可以编辑
private boolean isEdit;
public static FormWidgetDetailPane getInstance() {
if (HOLDER.singleton == null) {
@ -32,7 +69,6 @@ public class FormWidgetDetailPane extends FormDockView{
private FormWidgetDetailPane(){
setLayout(FRGUIPaneFactory.createBorderLayout());
listenPluginComponentPane();
}
@ -54,56 +90,350 @@ public class FormWidgetDetailPane extends FormDockView{
public Icon getViewIcon() {
return BaseUtils.readIcon("/com/fr/design/images/m_report/attributes.png");
}
/**
* 初始化
*/
@Override
public void refreshDockingView(){
FormDesigner designer = this.getEditingFormDesigner();
removeAll();
if(designer == null){
clearDockingView();
return;
}
initComponentPane();
reuWidgetPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
reuWidgetPanel.setBorder(null);
if (elCaseBindInfoList == null) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
return null;
}
};
sw.execute();
}
initReuWidgetPanel();
initMenuPanel();
add(reuWidgetPanel, BorderLayout.CENTER);
}
/**
* 初始化组件共享和复用面板
*/
private void initReuWidgetPanel() {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, false));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
}
/**
* 初始化菜单栏面板
*/
private void initMenuPanel() {
JPanel menutPanel = new JPanel();
menutPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
menutPanel.setBorder(BorderFactory.createEmptyBorder(3, 10, 10, 15));
menutPanelNorthPane = new JPanel(new BorderLayout());
UILabel localWidgetLabel = FRWidgetFactory.createLineWrapLabel(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Local_Widget"),
LOCAL_WIDGET_LABEL_WIDTH);
menutPanelNorthPane.add(localWidgetLabel, BorderLayout.WEST);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
menutPanelNorthPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
menutPanel.add(menutPanelNorthPane, BorderLayout.NORTH);
comboBox = new UIComboBox(getFormCategories());
comboBox.setPreferredSize(new Dimension(240, comboBox.getPreferredSize().height));
initComboBoxSelectedListener();
menutPanel.add(comboBox, BorderLayout.CENTER);
reuWidgetPanel.add(menutPanel, BorderLayout.NORTH);
}
/**
* 创建菜单栏按钮面板
*/
private JPanel initEditButtonPane() {
editPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
editPanel.add(createRefreshButton());
editPanel.add(createDownloadButton());
editPanel.add(createInstallButton());
editPanel.add(createDeleteButton());
return editPanel;
}
private void listenPluginComponentPane() {
PluginFilter filter = new PluginFilter() {
/**
* 创建取消删除面板
*/
private JPanel initResetButtonPane() {
resetPanel = new JPanel();
UIButton resetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Reset"));
resetPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
resetButton.setBackground(Color.white);
resetButton.setForeground(new Color(0x333334));
resetButton.addActionListener(new ActionListener() {
@Override
public boolean accept(PluginContext context) {
return context.contain(ComponentLibraryPaneProcessor.XML_TAG);
public void actionPerformed(ActionEvent e) {
refreshDownPanel(false);
replaceButtonPanel(false);
reuWidgetPanel.remove(deleteButton);
}
};
PluginListenerRegistration.getInstance().listenRunningChanged(new PluginEventListener() {
});
deleteButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Remove_Item"));
deleteButton.setBackground(Color.white);
deleteButton.setForeground(new Color(0xeb1d1f));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ShareLoader.getLoader().removeModulesFromList()) {
refreshShareMoudule();
reuWidgetPanel.remove(deleteButton);
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Successful"));
refreshDownPanel(false);
replaceButtonPanel(false);
refreshComboxData();
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Failed"));
}
}
});
JPanel deletePane = new JPanel(new BorderLayout());
deletePane.add(deleteButton, BorderLayout.CENTER);
deletePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
resetPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
resetPanel.add(resetButton, BorderLayout.CENTER);
resetPanel.add(deletePane, BorderLayout.WEST);
refreshDownPanel(true);
return resetPanel;
}
private void initComboBoxSelectedListener() {
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ShareLoader.getLoader().resetRemovedModuleList();
int filterIndex = comboBox.getSelectedIndex();
if (filterIndex == 0) {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
} else {
String filterName = comboBox.getSelectedItem().toString();
elCaseBindInfoList = ShareLoader.getLoader().getFilterBindInfoList(filterName);
}
refreshDownPanel(isEdit);
}
});
}
/**
* 创建工具条按钮
*/
private UIButton createToolButton(Icon icon, String toolTip, ActionListener actionListener) {
UIButton toolButton = new UIButton();
toolButton.setIcon(icon);
toolButton.setToolTipText(toolTip);
toolButton.set4ToolbarButton();
toolButton.addActionListener(actionListener);
return toolButton;
}
/**
* 创建刷新按钮
*/
private UIButton createRefreshButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/refresh.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
ShareLoader.getLoader().refreshModule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshComboxData();
refreshDownPanel(false);
return null;
}
};
sw.execute();
}
}
);
}
private void refreshComboxData() {
comboBox.setSelectedIndex(0);
comboBox.setModel(new DefaultComboBoxModel(getFormCategories()));
}
/**
* 创建下载模板的按钮
*/
private UIButton createDownloadButton() {
UIButton downloadButton = new UIButton();
downloadButton.setIcon(BaseUtils.readIcon("/com/fr/design/form/images/download icon.png"));
downloadButton.set4ToolbarButton();
downloadButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Download_Template"));
downloadButton.addActionListener(new ActionListener() {
@Override
public void on(PluginEvent event) {
refreshDockingView();
public void actionPerformed(ActionEvent e) {
String url = CloudCenter.getInstance().acquireUrlByKind("reuse.url");
if (StringUtils.isEmpty(url)) {
FRContext.getLogger().info("The URL is empty!");
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException exp) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate"));
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (URISyntaxException exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url);
}
}
});
return downloadButton;
}
/**
* 创建安装模板的按钮
*/
private UIButton createInstallButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/install icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Install_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileNameExtensionFilter(".reu", "reu"));
int returnValue = fileChooser.showDialog(new UILabel(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File chosenFile = fileChooser.getSelectedFile();
installFromDiskZipFile(chosenFile);
}
}
}
);
}
/**
* 创建删除模板的按钮
*/
private UIButton createDeleteButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/delete icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Delete_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replaceButtonPanel(true);
}
}
);
}
private void replaceButtonPanel(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
menutPanelNorthPane.remove(editPanel);
menutPanelNorthPane.add(initResetButtonPane(), BorderLayout.EAST);
} else {
menutPanelNorthPane.remove(resetPanel);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
ShareLoader.getLoader().resetRemovedModuleList();
}
}
private void installFromDiskZipFile(File chosenFile) {
if (chosenFile != null && chosenFile.getName().endsWith(ShareConstants.SUFFIX_MODULE)) {
try {
if (ShareLoader.getLoader().installModuleFromDiskZipFile(chosenFile)) {
refreshShareMoudule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
refreshComboxData();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}, filter);
}
}
private void initComponentPane() {
ComponentLibraryPaneCreator creator = ComponentLibraryPaneCreator.getNew();
JPanel componentLibraryPane = creator.create(this);
add(componentLibraryPane, BorderLayout.CENTER);
private void refreshShareMoudule() {
try {
ShareLoader.getLoader().refreshModule();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 获取报表块组件分类
*/
public String[] getFormCategories() {
return ArrayUtils.addAll(new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_AllCategories")}, ShareLoader.getLoader().getModuleCategory());
}
public void refreshDownPanel(boolean isEdit) {
reuWidgetPanel.remove(downPane);
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, isEdit));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
repaintContainer();
}
public void repaintContainer() {
validate();
repaint();
revalidate();
}
/**
* 清除数据
*/
public void clearDockingView() {
JScrollPane psp = new JScrollPane();
psp.setBorder(null);
this.add(psp, BorderLayout.CENTER);
}
/**
* 定位
* @return 位置

61
designer-form/src/main/java/com/fr/design/mainframe/JForm.java

@ -6,6 +6,7 @@ import com.fr.base.Parameter;
import com.fr.base.extension.FileExtension;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.DesignState;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.FormMobileAttrAction;
import com.fr.design.actions.TemplateParameterAction;
import com.fr.design.actions.core.WorkBookSupportable;
@ -29,6 +30,7 @@ import com.fr.design.designer.properties.FormWidgetAuthorityEditPane;
import com.fr.design.event.TargetModifiedEvent;
import com.fr.design.event.TargetModifiedListener;
import com.fr.design.fun.PreviewProvider;
import com.fr.design.fun.PropertyItemPaneProvider;
import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
import com.fr.design.gui.ilable.UILabel;
@ -65,6 +67,14 @@ import com.fr.form.ui.container.WLayout;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.page.PaperSettingProvider;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginRuntime;
import com.fr.plugin.injectable.PluginModule;
import com.fr.plugin.manage.PluginFilter;
import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener;
import com.fr.plugin.observer.PluginEventType;
import com.fr.plugin.observer.PluginListenerRegistration;
import com.fr.report.cell.Elem;
import com.fr.report.cell.cellattr.CellImage;
import com.fr.report.worksheet.FormElementCase;
@ -91,6 +101,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<Form> {
private static final String FORM_CARD = "FORM";
@ -116,12 +127,58 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
public JForm() {
super(new Form(new WBorderLayout("form")), "Form");
initPluginPane();
startListenPlugin();
}
public JForm(Form form, FILE file) {
super(form, file);
initPluginPane();
startListenPlugin();
}
private void startListenPlugin() {
PluginFilter filter = new PluginFilter() {
@Override
public boolean accept(PluginContext context) {
return context.contain(PropertyItemPaneProvider.XML_TAG);
}
};
PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun,
new PluginEventListener() {
@Override
public void on(PluginEvent event) {
PluginContext context = event.getContext();
PluginRuntime runtime = context.getRuntime();
Set<PropertyItemPaneProvider> providers = runtime.get(PropertyItemPaneProvider.XML_TAG);
for (PropertyItemPaneProvider provider : providers) {
addPane(provider);
}
}
}, filter);
}
private void initPluginPane() {
ExtraDesignClassManager classManager = PluginModule.getAgent(PluginModule.ExtraDesign);
Set<PropertyItemPaneProvider> providers = classManager.getArray(PropertyItemPaneProvider.XML_TAG);
for (PropertyItemPaneProvider provider : providers) {
addPane(provider);
}
}
private void addPane(PropertyItemPaneProvider provider) {
PaneHolder<FormDesigner> holder = provider.getPaneHolder(FormDesigner.class);
if (holder != null) {
JPanel panel = holder.getInstance(formDesign);
EastRegionContainerPane.getInstance().replaceKeyPane(provider.key(), panel);
}
}
@Override
public void refreshEastPropertiesPane() {
// 暂时用不到,遇到的时候再加刷新右侧tab面板的代码
@ -765,7 +822,7 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
refreshWidgetLibPane();
}
private void refreshWidgetLibPane() {
if (EastRegionContainerPane.getInstance().getWidgetLibPane() == null) {
new Thread() {

23
designer-form/src/main/java/com/fr/design/mainframe/component/ComponentLibraryManager.java

@ -1,23 +0,0 @@
package com.fr.design.mainframe.component;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.design.mainframe.component.pane.ComponentLibraryPaneProcessorImpl;
/**
* created by Harrison on 2020/03/16
**/
public class ComponentLibraryManager {
private static ComponentLibraryPaneProcessor DEFAULT = new ComponentLibraryPaneProcessorImpl();
public static ComponentLibraryPaneProcessor selectPaneProcessor() {
ComponentLibraryPaneProcessor right = ExtraDesignClassManager.getInstance().getSingle(ComponentLibraryPaneProcessor.XML_TAG);
if (right == null || DEFAULT.layerIndex() > right.layerIndex()) {
right = DEFAULT;
}
return right;
}
}

72
designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneCreator.java

@ -1,72 +0,0 @@
package com.fr.design.mainframe.component.pane;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DockingView;
import com.fr.design.mainframe.component.ComponentLibraryManager;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
/**
* created by Harrison on 2020/03/22
**/
public class ComponentLibraryPaneCreator {
private ComponentLibraryPaneProcessor processor;
public ComponentLibraryPaneCreator() {
processor = ComponentLibraryManager.selectPaneProcessor();
}
public static ComponentLibraryPaneCreator getNew() {
return new ComponentLibraryPaneCreator();
}
public JPanel create(DockingView dockingView) {
JPanel componentLibPanel = createComponentLibPanel();
processor.parentView(dockingView);
processor.parentPane(componentLibPanel);
JPanel menuPanel = createMenuPanel();
componentLibPanel.add(menuPanel, BorderLayout.NORTH);
UIScrollPane showPane = processor.createShowPanel(false);
componentLibPanel.add(showPane);
return componentLibPanel;
}
private JPanel createComponentLibPanel() {
JPanel reuWidgetPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
reuWidgetPanel.setBorder(null);
return reuWidgetPanel;
}
/**
* 初始化菜单栏面板
*/
private JPanel createMenuPanel() {
JPanel menuPanel = new JPanel();
menuPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
menuPanel.setBorder(BorderFactory.createEmptyBorder(3, 10, 10, 15));
JPanel menuPanelNorthPane = processor.createMenuNorthPane();
if (menuPanelNorthPane != null) {
menuPanel.add(menuPanelNorthPane, BorderLayout.NORTH);
}
UIComboBox menuPanelComboBox = processor.createMenuComBox();
if (menuPanelComboBox != null) {
menuPanel.add(menuPanelComboBox, BorderLayout.CENTER);
}
return menuPanel;
}
}

412
designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneProcessorImpl.java

@ -1,412 +0,0 @@
package com.fr.design.mainframe.component.pane;
import com.fr.base.BaseUtils;
import com.fr.design.fun.impl.AbstractComponentLibraryPaneProcessor;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DockingView;
import com.fr.design.mainframe.ShareWidgetPane;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.form.share.ShareLoader;
import com.fr.form.ui.SharableWidgetBindInfo;
import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* created by Harrison on 2020/03/16
**/
public class ComponentLibraryPaneProcessorImpl extends AbstractComponentLibraryPaneProcessor {
private static final int LOCAL_WIDGET_LABEL_WIDTH = 90;
private DockingView parentView;
private SwingWorker sw;
private JPanel componentLibPane;
private UIScrollPane showPane;
private UIComboBox menuPanelComboBox;
private JPanel menuPanelNorthPane;
private SharableWidgetBindInfo[] bindInfoArray;
private UIButton deleteButton;
private JPanel editPanel;
private JPanel resetPanel;
/**
* 组件面板是否可以编辑
*/
private boolean isEdit;
public ComponentLibraryPaneProcessorImpl() {
}
@Override
public void parentView(DockingView dockingView) {
parentView = dockingView;
if (bindInfoArray == null) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshShowPanel(false);
return null;
}
};
sw.execute();
}
}
@Override
public void parentPane(JPanel panel) {
this.componentLibPane = panel;
}
@Override
public void complete() {
}
/**
* 初始化组件共享和复用面板
*/
@Override
public UIScrollPane createShowPanel(boolean isEdit) {
showPane = new UIScrollPane(
new ShareWidgetPane(bindInfoArray, isEdit)
);
showPane.setBorder(null);
return showPane;
}
@Override
public UIComboBox createMenuComBox() {
menuPanelComboBox = new UIComboBox(getFormCategories());
menuPanelComboBox.setPreferredSize(new Dimension(240, menuPanelComboBox.getPreferredSize().height));
addComboBoxListener();
return menuPanelComboBox;
}
private void addComboBoxListener() {
menuPanelComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ShareLoader.getLoader().resetRemovedModuleList();
int filterIndex = menuPanelComboBox.getSelectedIndex();
if (filterIndex == 0) {
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
} else {
String filterName = menuPanelComboBox.getSelectedItem().toString();
bindInfoArray = ShareLoader.getLoader().getFilterBindInfoList(filterName);
}
refreshShowPanel(isEdit);
}
});
}
@Override
public JPanel createMenuNorthPane() {
menuPanelNorthPane = new JPanel(new BorderLayout());
UILabel localWidgetLabel = FRWidgetFactory.createLineWrapLabel(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Local_Widget"),
LOCAL_WIDGET_LABEL_WIDTH);
menuPanelNorthPane.add(localWidgetLabel, BorderLayout.WEST);
menuPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
menuPanelNorthPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
return menuPanelNorthPane;
}
/**
* 创建菜单栏按钮面板
*/
protected JPanel initEditButtonPane() {
editPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
editPanel.add(createRefreshButton());
editPanel.add(createDownloadButton());
editPanel.add(createInstallButton());
editPanel.add(createDeleteButton());
return editPanel;
}
/**
* 创建取消删除面板
*/
protected JPanel initResetButtonPane() {
resetPanel = new JPanel();
UIButton resetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Reset"));
resetPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
resetButton.setBackground(Color.white);
resetButton.setForeground(new Color(0x333334));
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshShowPanel(false);
replaceButtonPanel(false);
componentLibPane.remove(deleteButton);
}
});
deleteButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Remove_Item"));
deleteButton.setBackground(Color.white);
deleteButton.setForeground(new Color(0xeb1d1f));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ShareLoader.getLoader().removeModulesFromList()) {
refreshShareModule();
componentLibPane.remove(deleteButton);
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Successful"));
refreshShowPanel(false);
replaceButtonPanel(false);
refreshComboBoxData();
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Failed"));
}
}
});
JPanel deletePane = new JPanel(new BorderLayout());
deletePane.add(deleteButton, BorderLayout.CENTER);
deletePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
resetPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
resetPanel.add(resetButton, BorderLayout.CENTER);
resetPanel.add(deletePane, BorderLayout.WEST);
refreshShowPanel(true);
return resetPanel;
}
/**
* 创建工具条按钮
*/
protected UIButton createToolButton(Icon icon, String toolTip, ActionListener actionListener) {
UIButton toolButton = new UIButton();
toolButton.setIcon(icon);
toolButton.setToolTipText(toolTip);
toolButton.set4ToolbarButton();
toolButton.addActionListener(actionListener);
return toolButton;
}
/**
* 创建刷新按钮
*/
protected UIButton createRefreshButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/refresh.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
ShareLoader.getLoader().refreshModule();
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshComboBoxData();
refreshShowPanel(false);
return null;
}
};
sw.execute();
}
}
);
}
/**
* 创建下载模板的按钮
*/
protected UIButton createDownloadButton() {
UIButton downloadButton = new UIButton();
downloadButton.setIcon(BaseUtils.readIcon("/com/fr/design/form/images/download icon.png"));
downloadButton.set4ToolbarButton();
downloadButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Download_Template"));
downloadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String url = CloudCenter.getInstance().acquireUrlByKind("reuse.url");
if (StringUtils.isEmpty(url)) {
FineLoggerFactory.getLogger().info("The URL is empty!");
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException exp) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate"));
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (URISyntaxException exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url);
}
}
});
return downloadButton;
}
/**
* 创建安装模板的按钮
*/
protected UIButton createInstallButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/install icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Install_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileNameExtensionFilter(".reu", "reu"));
int returnValue = fileChooser.showDialog(new UILabel(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File chosenFile = fileChooser.getSelectedFile();
installFromDiskZipFile(chosenFile);
}
}
}
);
}
/**
* 创建删除模板的按钮
*/
protected UIButton createDeleteButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/delete icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Delete_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replaceButtonPanel(true);
}
}
);
}
/**
* 获取报表块组件分类
*/
protected String[] getFormCategories() {
return ArrayUtils.addAll(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_AllCategories")}, ShareLoader.getLoader().getModuleCategory());
}
protected void refreshShowPanel(boolean isEdit) {
componentLibPane.remove(showPane);
showPane = createShowPanel(isEdit);
componentLibPane.add(showPane);
repaint();
}
private void refreshComboBoxData() {
menuPanelComboBox.setSelectedIndex(0);
menuPanelComboBox.setModel(new DefaultComboBoxModel(getFormCategories()));
}
private void replaceButtonPanel(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
menuPanelNorthPane.remove(editPanel);
menuPanelNorthPane.add(initResetButtonPane(), BorderLayout.EAST);
} else {
menuPanelNorthPane.remove(resetPanel);
menuPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
ShareLoader.getLoader().resetRemovedModuleList();
}
}
private void installFromDiskZipFile(File chosenFile) {
if (chosenFile != null && chosenFile.getName().endsWith(ShareConstants.SUFFIX_MODULE)) {
try {
if (ShareLoader.getLoader().installModuleFromDiskZipFile(chosenFile)) {
refreshShareModule();
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshShowPanel(false);
refreshComboBoxData();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
private void refreshShareModule() {
try {
ShareLoader.getLoader().refreshModule();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
public void repaint() {
parentView.validate();
parentView.repaint();
parentView.revalidate();
}
}
Loading…
Cancel
Save