Henry.Wang
4 years ago
57 changed files with 1648 additions and 152 deletions
@ -0,0 +1,26 @@
|
||||
package com.fr.design.actions; |
||||
|
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ibutton.UIForbiddenButton; |
||||
import javax.swing.AbstractButton; |
||||
import javax.swing.JComponent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/12 |
||||
*/ |
||||
public abstract class ForbiddenUpdateAction extends UpdateAction { |
||||
|
||||
@Override |
||||
public JComponent createToolBarComponent() { |
||||
Object object = this.getValue(UIForbiddenButton.class.getName()); |
||||
if (!(object instanceof AbstractButton)) { |
||||
UIButton button = null; |
||||
button = new UIForbiddenButton(); |
||||
object = initButton(button, UIForbiddenButton.class.getName()); |
||||
} |
||||
|
||||
return (JComponent) object; |
||||
} |
||||
} |
@ -1 +1,44 @@
|
||||
package com.fr.design.actions.file;
import com.fr.design.actions.UpdateAction;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.menu.KeySetUtils;
import java.awt.event.ActionEvent;
/**
* Author : daisy
* Date: 13-8-16
* Time: 下午3:23
*/
public class CloseCurrentTemplateAction extends UpdateAction {
public CloseCurrentTemplateAction() {
this.setMenuKeySet(KeySetUtils.CLOSE_CURRENT_TEMPLATE);
this.setName(getMenuKeySet().getMenuKeySetName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setAccelerator(getMenuKeySet().getKeyStroke());
}
/**
* 动作
* @param e 事件
*/
public void actionPerformed(ActionEvent e) {
MutilTempalteTabPane.getInstance().setIsCloseCurrent(true);
MutilTempalteTabPane.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
}
} |
||||
package com.fr.design.actions.file; |
||||
|
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.file.HistoryTemplateListPane; |
||||
import com.fr.design.file.MutilTempalteTabPane; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.menu.KeySetUtils; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* Author : daisy |
||||
* Date: 13-8-16 |
||||
* Time: 下午3:23 |
||||
*/ |
||||
public class CloseCurrentTemplateAction extends UpdateAction { |
||||
|
||||
public CloseCurrentTemplateAction() { |
||||
this.setMenuKeySet(KeySetUtils.CLOSE_CURRENT_TEMPLATE); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setAccelerator(getMenuKeySet().getKeyStroke()); |
||||
} |
||||
|
||||
/** |
||||
* 动作 |
||||
* @param e 事件 |
||||
*/ |
||||
public void actionPerformed(ActionEvent e) { |
||||
MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); |
||||
MutilTempalteTabPane.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); |
||||
MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); |
||||
} |
||||
|
||||
@Override |
||||
public void update() { |
||||
super.update(); |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
if (template != null) { |
||||
this.setEnabled(!template.isSaving()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.design.env; |
||||
|
||||
import com.fr.workspace.WorkContext; |
||||
import com.fr.workspace.Workspace; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/11 |
||||
*/ |
||||
public class DesignerWorkspaceLoader { |
||||
|
||||
public static void init() { |
||||
Workspace workspace = WorkContext.getCurrent(); |
||||
if (workspace.isLocal()) { |
||||
return; |
||||
} |
||||
workspace.isWarDeploy(); |
||||
workspace.isCluster(); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.fr.design.env; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import javax.swing.ImageIcon; |
||||
import javax.swing.JDialog; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/10 |
||||
*/ |
||||
public class WorkspaceChangeLoadingDialog extends JDialog { |
||||
|
||||
private static final ImageIcon LOADING_ICON = new ImageIcon(WorkspaceChangeLoadingDialog.class.getResource("/com/fr/web/images/loading-local.gif")); |
||||
|
||||
private static WorkspaceChangeLoadingDialog dialog; |
||||
|
||||
public WorkspaceChangeLoadingDialog() { |
||||
super(DesignerContext.getDesignerFrame()); |
||||
setLayout(new BorderLayout()); |
||||
this.getContentPane().setBackground(Color.WHITE); |
||||
this.setResizable(false); |
||||
this.setUndecorated(true); |
||||
this.setAlwaysOnTop(true); |
||||
this.setModal(false); |
||||
this.setSize(new Dimension(400, 100)); |
||||
this.add(new UILabel(LOADING_ICON, UILabel.CENTER), BorderLayout.NORTH); |
||||
this.add(new UILabel(Toolkit.i18nText("Fine-Design_Change_Workspace_Tip"), UILabel.CENTER), BorderLayout.CENTER); |
||||
GUICoreUtils.centerWindow(this); |
||||
} |
||||
|
||||
|
||||
public static void showDialog() { |
||||
dialog = new WorkspaceChangeLoadingDialog(); |
||||
dialog.setVisible(true); |
||||
} |
||||
|
||||
public static void hideDialog() { |
||||
dialog.dispose(); |
||||
} |
||||
} |
@ -0,0 +1,64 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import com.fr.base.CellBorderStyle; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import javax.swing.Action; |
||||
import javax.swing.Icon; |
||||
import javax.swing.plaf.ButtonUI; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/9 |
||||
*/ |
||||
public class UIForbiddenButton extends UIButton { |
||||
|
||||
public UIForbiddenButton() { |
||||
super(); |
||||
} |
||||
|
||||
public UIForbiddenButton(String string) { |
||||
super(string); |
||||
} |
||||
|
||||
public UIForbiddenButton(Icon icon) { |
||||
super(icon); |
||||
} |
||||
|
||||
public UIForbiddenButton(Action action) { |
||||
super(action); |
||||
} |
||||
|
||||
public UIForbiddenButton(String text, Icon icon) { |
||||
super(text, icon); |
||||
} |
||||
|
||||
public UIForbiddenButton(Icon normal, Icon rollOver, Icon pressed) { |
||||
super(normal, rollOver, pressed); |
||||
} |
||||
|
||||
public UIForbiddenButton(String resource, boolean needSetDisabledIcon) { |
||||
super(resource, needSetDisabledIcon); |
||||
} |
||||
|
||||
@Override |
||||
public CellBorderStyle getBorderStyle() { |
||||
return super.getBorderStyle(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isEnabled() { |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
boolean enabled = true; |
||||
if (template != null) { |
||||
enabled = super.isEnabled() && template.checkEnable(); |
||||
} |
||||
return enabled; |
||||
} |
||||
|
||||
@Override |
||||
public ButtonUI getUI() { |
||||
return new UIForbiddenButtonUI(); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import java.awt.Graphics; |
||||
import javax.swing.JComponent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/11 |
||||
*/ |
||||
public class UIForbiddenButtonUI extends UIButtonUI { |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
super.paint(g, c); |
||||
c.setEnabled(c.isEnabled()); |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import javax.swing.Action; |
||||
import javax.swing.Icon; |
||||
import javax.swing.plaf.ButtonUI; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/10 |
||||
*/ |
||||
public class UISaveForbiddenButton extends UIButton { |
||||
public UISaveForbiddenButton() { |
||||
} |
||||
|
||||
public UISaveForbiddenButton(String string) { |
||||
super(string); |
||||
} |
||||
|
||||
public UISaveForbiddenButton(Icon icon) { |
||||
super(icon); |
||||
} |
||||
|
||||
public UISaveForbiddenButton(Action action) { |
||||
super(action); |
||||
} |
||||
|
||||
public UISaveForbiddenButton(String text, Icon icon) { |
||||
super(text, icon); |
||||
} |
||||
|
||||
public UISaveForbiddenButton(Icon normal, Icon rollOver, Icon pressed) { |
||||
super(normal, rollOver, pressed); |
||||
} |
||||
|
||||
public UISaveForbiddenButton(String resource, boolean needSetDisabledIcon) { |
||||
super(resource, needSetDisabledIcon); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isEnabled() { |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
boolean enabled = true; |
||||
if (template != null) { |
||||
enabled = !template.isSaving(); |
||||
} |
||||
return enabled; |
||||
} |
||||
|
||||
@Override |
||||
public ButtonUI getUI() { |
||||
return new UISaveForbiddenButtonUI(); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import java.awt.Graphics; |
||||
import javax.swing.JComponent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/14 |
||||
*/ |
||||
public class UISaveForbiddenButtonUI extends UIButtonUI { |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
super.paint(g, c); |
||||
c.setEnabled(c.isEnabled()); |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.worker.save.CallbackSaveWorker; |
||||
|
||||
/** |
||||
* 模板保存接口 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/9 |
||||
*/ |
||||
public interface JTemplateSave { |
||||
|
||||
/** |
||||
* 保存后需要根据是否成功做外部回调,可选保存位置 |
||||
* |
||||
* @return |
||||
*/ |
||||
CallbackSaveWorker save(); |
||||
|
||||
|
||||
/** |
||||
* 另存为后需要根据是否成功做外部回调,可选保存位置 |
||||
* |
||||
* @return |
||||
*/ |
||||
CallbackSaveWorker saveAs(); |
||||
|
||||
|
||||
/** |
||||
* 保存到当前工作目录(reportlets)后需要根据是否成功做外部回调 |
||||
* |
||||
* |
||||
* @return |
||||
*/ |
||||
CallbackSaveWorker save2Env(); |
||||
|
||||
|
||||
/** |
||||
* 另存为到当前工作目录(reportlets)后需要根据是否成功做外部回调 |
||||
* |
||||
* @return |
||||
*/ |
||||
CallbackSaveWorker saveAs2Env(); |
||||
|
||||
/**D |
||||
* 直接保存 |
||||
*/ |
||||
void saveDirectly(); |
||||
|
||||
|
||||
/** |
||||
* 直接另存为 |
||||
*/ |
||||
void saveAsDirectly(); |
||||
|
||||
} |
@ -0,0 +1,60 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.general.IOUtils; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Container; |
||||
import java.awt.Dimension; |
||||
import java.awt.LayoutManager; |
||||
import javax.swing.ImageIcon; |
||||
import javax.swing.JPanel; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/9 |
||||
*/ |
||||
public class OpenLoadingPane extends JPanel { |
||||
|
||||
private UILabel loadingLabel; |
||||
|
||||
public OpenLoadingPane() { |
||||
|
||||
setLayout(new LayoutManager() { |
||||
|
||||
@Override |
||||
public void removeLayoutComponent(Component comp) { |
||||
} |
||||
|
||||
@Override |
||||
public Dimension preferredLayoutSize(Container parent) { |
||||
return parent.getPreferredSize(); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension minimumLayoutSize(Container parent) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void layoutContainer(Container parent) { |
||||
int width = parent.getParent().getWidth(); |
||||
int height = parent.getParent().getHeight(); |
||||
int loadingLabelWidth = loadingLabel.getPreferredSize().width; |
||||
int loadingLabelHeight = loadingLabel.getPreferredSize().height; |
||||
int loadingLabelX = (width - loadingLabelWidth) / 2; |
||||
int loadingLabelY = (height - loadingLabelHeight) / 2; |
||||
loadingLabel.setBounds(loadingLabelX, loadingLabelY, loadingLabelWidth, loadingLabelHeight); |
||||
} |
||||
|
||||
@Override |
||||
public void addLayoutComponent(String name, Component comp) { |
||||
} |
||||
}); |
||||
setBackground(Color.WHITE); |
||||
loadingLabel = new UILabel(new ImageIcon(IOUtils.readImage("com/fr/plugin/chart/vanchart/export/loading.png"))); |
||||
add(loadingLabel); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.stable.StableUtils; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/12 |
||||
*/ |
||||
public class TemplateSavingChecker { |
||||
|
||||
|
||||
public static boolean check() { |
||||
List<String> list = getSavingTemplate(); |
||||
if (!list.isEmpty()) { |
||||
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design_Close_Template_Tip", StableUtils.join(list, "、")), |
||||
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), |
||||
FineJOptionPane.INFORMATION_MESSAGE); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
private static List<String> getSavingTemplate() { |
||||
List<String> result = new ArrayList<>(); |
||||
for (JTemplate<?, ?> template : HistoryTemplateListCache.getInstance().getHistoryList()) { |
||||
if (template.isSaving()) { |
||||
result.add(template.getEditingFILE().getName()); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,102 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import java.awt.AlphaComposite; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Composite; |
||||
import java.awt.Container; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.LayoutManager; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import javax.swing.ImageIcon; |
||||
import javax.swing.JComponent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/12 |
||||
*/ |
||||
public class TransparentPane extends JComponent { |
||||
|
||||
private static final ImageIcon LOADING_ICON = new ImageIcon(TransparentPane.class.getResource("/com/fr/web/images/loading-local.gif")); |
||||
|
||||
private UILabel loadingLabel; |
||||
private UILabel label; |
||||
private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); |
||||
|
||||
public TransparentPane() { |
||||
|
||||
addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
// do nothing
|
||||
} |
||||
}); |
||||
|
||||
setLayout(getCoverLayout()); |
||||
setBackground(null); |
||||
setOpaque(false); |
||||
|
||||
loadingLabel = new UILabel(LOADING_ICON); |
||||
label = new UILabel(Toolkit.i18nText("Fine-Design_Saving_Template_Tip")); |
||||
add(loadingLabel); |
||||
add(label); |
||||
} |
||||
|
||||
protected LayoutManager getCoverLayout() { |
||||
return new LayoutManager() { |
||||
|
||||
@Override |
||||
public void removeLayoutComponent(Component comp) { |
||||
} |
||||
|
||||
@Override |
||||
public Dimension preferredLayoutSize(Container parent) { |
||||
return parent.getPreferredSize(); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension minimumLayoutSize(Container parent) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void layoutContainer(Container parent) { |
||||
int width = parent.getParent().getWidth(); |
||||
int height = parent.getParent().getHeight(); |
||||
int loadingLabelWidth = loadingLabel.getPreferredSize().width; |
||||
int loadingLabelHeight = loadingLabel.getPreferredSize().height; |
||||
int buttonX = (width - loadingLabelWidth) / 2; |
||||
int buttonY = (height - loadingLabelHeight) / 2; |
||||
int labelWidth = label.getPreferredSize().width; |
||||
int labelHeight = label.getPreferredSize().height; |
||||
int labelX = (width - labelWidth) / 2; |
||||
int labelY = (height - labelHeight) / 2 + loadingLabelHeight; |
||||
label.setBounds(labelX, labelY, labelWidth, labelHeight); |
||||
loadingLabel.setBounds(buttonX, buttonY, loadingLabelWidth, loadingLabelHeight); |
||||
} |
||||
|
||||
@Override |
||||
public void addLayoutComponent(String name, Component comp) { |
||||
} |
||||
}; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
Composite oldComposite = g2d.getComposite(); |
||||
g2d.setComposite(composite); |
||||
g2d.setColor(Color.BLACK); |
||||
g2d.fillRect(0, 0, getWidth(), getHeight()); |
||||
g2d.setComposite(oldComposite); |
||||
super.paint(g); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.fr.design.worker; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import javax.swing.SwingWorker; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/2 |
||||
*/ |
||||
public class WorkerManager { |
||||
|
||||
private static final WorkerManager INSTANCE = new WorkerManager(); |
||||
|
||||
private Map<String, SwingWorker> workerMap = new HashMap<>(); |
||||
|
||||
public static WorkerManager getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
@Nullable |
||||
public SwingWorker getWorker(String taskName) { |
||||
return workerMap.get(taskName); |
||||
} |
||||
|
||||
public boolean isCompleted(String taskName) { |
||||
SwingWorker worker = getWorker(taskName); |
||||
return worker == null || worker.isDone(); |
||||
} |
||||
|
||||
public void registerWorker(String taskName, SwingWorker worker) { |
||||
workerMap.put(taskName, worker); |
||||
} |
||||
|
||||
public void removeWorker(String taskName) { |
||||
workerMap.remove(taskName); |
||||
} |
||||
|
||||
public void cancelWorker(String taskName) { |
||||
SwingWorker worker = getWorker(taskName); |
||||
if (worker != null && !worker.isDone()) { |
||||
worker.cancel(true); |
||||
removeWorker(taskName); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.design.worker.open; |
||||
|
||||
import com.fr.base.io.BaseBook; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/13 |
||||
*/ |
||||
public class OpenResult<T extends BaseBook, R> { |
||||
|
||||
private final T baseBook; |
||||
|
||||
private final R ref; |
||||
|
||||
public OpenResult(T baseBook, R r) { |
||||
this.baseBook = baseBook; |
||||
this.ref = r; |
||||
} |
||||
|
||||
public T getBaseBook() { |
||||
return baseBook; |
||||
} |
||||
|
||||
public R getRef() { |
||||
return ref; |
||||
} |
||||
} |
@ -0,0 +1,117 @@
|
||||
package com.fr.design.worker.open; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrameFileDealerPane; |
||||
import com.fr.design.mainframe.EastRegionContainerPane; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.worker.WorkerManager; |
||||
import com.fr.file.FILE; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.util.concurrent.Callable; |
||||
import java.util.concurrent.CancellationException; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.concurrent.TimeoutException; |
||||
import javax.swing.SwingWorker; |
||||
|
||||
/** |
||||
* 模板打开的worker |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/9 |
||||
*/ |
||||
public class OpenWorker<T> extends SwingWorker<T, Void> { |
||||
|
||||
private static final int TIME_OUT = 400; |
||||
|
||||
private final Callable<T> callable; |
||||
|
||||
private final JTemplate<?, ?> template; |
||||
|
||||
private Callable<JTemplate<?, ?>> templateCallable; |
||||
|
||||
private boolean slowly = false; |
||||
|
||||
private String taskName; |
||||
|
||||
private T result; |
||||
|
||||
public OpenWorker(Callable<T> callable, JTemplate<?, ?> template) { |
||||
this.callable = callable; |
||||
this.template = template; |
||||
} |
||||
|
||||
@Override |
||||
protected T doInBackground() throws Exception { |
||||
return this.callable.call(); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
result = get(); |
||||
} catch (CancellationException ignored) { |
||||
return; |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
this.template.setOpening(false); |
||||
// 后续动作
|
||||
if (slowly && templateCallable != null) { |
||||
try { |
||||
JTemplate<?, ?> book = templateCallable.call(); |
||||
FILE tplFile = book.getEditingFILE(); |
||||
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
// 当前tab页是正在打开的模板
|
||||
if (ComparatorUtils.equals(currentTemplate.getEditingFILE(), tplFile)) { |
||||
currentTemplate.whenClose(); |
||||
DesignerContext.getDesignerFrame().addAndActivateJTemplate(book); |
||||
HistoryTemplateListCache.getInstance().replaceCurrentEditingTemplate(book); |
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
} else { |
||||
// 当前tab页是其他模板
|
||||
for (int i = 0, len = HistoryTemplateListCache.getInstance().getHistoryCount(); i < len; i++) { |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().get(i); |
||||
if (ComparatorUtils.equals(template.getEditingFILE(), book.getEditingFILE())) { |
||||
template.whenClose(); |
||||
HistoryTemplateListCache.getInstance().getHistoryList().set(i, book); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
WorkerManager.getInstance().removeWorker(taskName); |
||||
} |
||||
|
||||
public void addCallBack(Callable<JTemplate<?, ?>> templateCallable) { |
||||
this.templateCallable = templateCallable; |
||||
} |
||||
|
||||
public void start(String taskName) { |
||||
this.taskName = taskName; |
||||
this.template.setOpening(true); |
||||
this.execute(); |
||||
WorkerManager.getInstance().registerWorker(taskName, this); |
||||
} |
||||
|
||||
public T getResult() { |
||||
if (result != null) { |
||||
return result; |
||||
} |
||||
try { |
||||
return this.get(TIME_OUT, TimeUnit.MILLISECONDS); |
||||
} catch (TimeoutException e) { |
||||
slowly = true; |
||||
} catch (Exception exception) { |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
WorkerManager.getInstance().removeWorker(taskName); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
package com.fr.design.worker.save; |
||||
|
||||
import com.fr.common.util.Collections; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.concurrent.Callable; |
||||
|
||||
/** |
||||
* 保存之后需要做些外部回调 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/8 |
||||
*/ |
||||
public class CallbackSaveWorker extends SaveWorker { |
||||
|
||||
private List<Runnable> successRunnableList; |
||||
|
||||
private List<Runnable> failRunnableList; |
||||
|
||||
public CallbackSaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) { |
||||
super(callable, template); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
super.done(); |
||||
|
||||
if (success) { |
||||
fireRunnable(successRunnableList); |
||||
} else { |
||||
fireRunnable(failRunnableList); |
||||
} |
||||
successRunnableList = null; |
||||
failRunnableList = null; |
||||
} |
||||
|
||||
private void fireRunnable(List<Runnable> list) { |
||||
if (Collections.isEmpty(list)) { |
||||
return; |
||||
} |
||||
for (Runnable runnable : list) { |
||||
runnable.run(); |
||||
} |
||||
} |
||||
|
||||
private void addCallback(List<Runnable> runnableList, Runnable runnable) { |
||||
if (runnableList == null) { |
||||
runnableList = new LinkedList<>(); |
||||
} |
||||
if (runnable != null) { |
||||
runnableList.add(runnable); |
||||
} |
||||
} |
||||
|
||||
public void addSuccessCallback(Runnable successRunnable) { |
||||
if (successRunnableList == null) { |
||||
successRunnableList = new LinkedList<>(); |
||||
} |
||||
if (successRunnable != null) { |
||||
successRunnableList.add(successRunnable); |
||||
} |
||||
} |
||||
|
||||
public void addFailCallback(Runnable failRunnable) { |
||||
if (failRunnableList == null) { |
||||
failRunnableList = new LinkedList<>(); |
||||
} |
||||
if (failRunnable != null) { |
||||
failRunnableList.add(failRunnable); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.fr.design.worker.save; |
||||
|
||||
import com.fr.design.mainframe.JTemplate; |
||||
import java.util.concurrent.Callable; |
||||
|
||||
/** |
||||
* 空实现 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/9 |
||||
*/ |
||||
public class EmptyCallBackSaveWorker extends CallbackSaveWorker { |
||||
|
||||
public EmptyCallBackSaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) { |
||||
super(callable, template); |
||||
} |
||||
|
||||
public EmptyCallBackSaveWorker() { |
||||
this(null, null); |
||||
} |
||||
|
||||
@Override |
||||
protected Boolean doInBackground() throws Exception { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
// do nothing
|
||||
} |
||||
|
||||
@Override |
||||
public void start(String taskName) { |
||||
// do nothing
|
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
package com.fr.design.worker.save; |
||||
|
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrameFileDealerPane; |
||||
import com.fr.design.mainframe.EastRegionContainerPane; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.worker.WorkerManager; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.util.concurrent.Callable; |
||||
import java.util.concurrent.TimeUnit; |
||||
import java.util.concurrent.TimeoutException; |
||||
import javax.swing.JOptionPane; |
||||
import javax.swing.SwingWorker; |
||||
|
||||
/** |
||||
* 模板保存的worker |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/1 |
||||
*/ |
||||
public class SaveWorker extends SwingWorker<Boolean, Void> { |
||||
|
||||
private static final int TIME_OUT = 400; |
||||
|
||||
private final Callable<Boolean> callable; |
||||
|
||||
private String taskName; |
||||
|
||||
private final JTemplate<?, ?> template; |
||||
|
||||
protected boolean success; |
||||
|
||||
private boolean slowly; |
||||
|
||||
public SaveWorker(Callable<Boolean> callable, JTemplate<?, ?> template) { |
||||
this.callable = callable; |
||||
this.template = template; |
||||
} |
||||
|
||||
@Override |
||||
protected Boolean doInBackground() throws Exception { |
||||
return callable.call(); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
success = get(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
FineJOptionPane.showMessageDialog( |
||||
DesignerContext.getDesignerFrame(), |
||||
Toolkit.i18nText("Fine-Design-Basic_Save_Failure"), |
||||
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), |
||||
JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
this.template.setSaving(false); |
||||
// 恢复界面
|
||||
if (slowly && ComparatorUtils.equals(this.template.getName(), HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getName())) { |
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
DesignerContext.getDesignerFrame().refreshUIToolBar(); |
||||
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().hideCover(); |
||||
} |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
WorkerManager.getInstance().removeWorker(taskName); |
||||
} |
||||
|
||||
public void start(String taskName) { |
||||
this.taskName = taskName; |
||||
this.template.setSaving(true); |
||||
this.execute(); |
||||
// worker纳入管理
|
||||
WorkerManager.getInstance().registerWorker(taskName, this); |
||||
try { |
||||
this.get(TIME_OUT, TimeUnit.MILLISECONDS); |
||||
} catch (TimeoutException timeoutException) { |
||||
slowly = true; |
||||
// 开始禁用
|
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover(); |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
} catch (Exception exception) { |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
WorkerManager.getInstance().removeWorker(taskName); |
||||
} |
||||
} |
||||
} |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in new issue