hades
4 years ago
50 changed files with 1462 additions and 134 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; |
||||
} |
||||
} |
@ -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,52 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import com.fr.base.CellBorderStyle; |
||||
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 ButtonUI getUI() { |
||||
return new UIForbiddenButtonUI(); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
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); |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
boolean flag = true; |
||||
if (template != null) { |
||||
flag = c.isEnabled() && !template.isSaving() && !template.isOpening(); |
||||
} |
||||
c.setEnabled(flag); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
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 ButtonUI getUI() { |
||||
return new UISaveForbiddenButtonUI(); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
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); |
||||
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
boolean flag = true; |
||||
if (template != null) { |
||||
flag = !template.isSaving(); |
||||
} |
||||
c.setEnabled(flag); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.gui.imenu; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/11 |
||||
*/ |
||||
public class UIForBiddenHeadMenu extends UIHeadMenu { |
||||
|
||||
public UIForBiddenHeadMenu(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
@Override |
||||
public void updateUI() { |
||||
setUI(new UIForbiddenMenuUI()); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.gui.imenu; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import java.awt.Graphics; |
||||
import javax.swing.JComponent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/11 |
||||
*/ |
||||
public class UIForbiddenMenuUI extends UIMenuUI { |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
// JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
|
||||
// boolean flag = true;
|
||||
// if (template != null) {
|
||||
// flag = !template.isSaving() && !template.isOpening();
|
||||
// }
|
||||
// c.setEnabled(flag);
|
||||
super.paint(g, c); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
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(); |
||||
|
||||
/**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,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,115 @@
|
||||
package com.fr.design.worker.open; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
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(); |
||||
return; |
||||
} |
||||
// 当前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); |
||||
return; |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
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,82 @@
|
||||
package com.fr.design.worker.save; |
||||
|
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrame; |
||||
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.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; |
||||
|
||||
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); |
||||
} |
||||
this.template.setSaving(false); |
||||
// 恢复界面
|
||||
if (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) { |
||||
// 开始禁用
|
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover(); |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
} catch (Exception exception) { |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
WorkerManager.getInstance().removeWorker(taskName); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue