Browse Source
* commit '95c9de86aab052dde404fcd9fa03de1e1b0fb82f': REPORT-10390 远程设计交互修订research/10.0
yaoh.wu
6 years ago
6 changed files with 192 additions and 407 deletions
@ -0,0 +1,173 @@
|
||||
package com.fr.design; |
||||
|
||||
import com.fr.design.data.DesignTableDataManager; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.env.DesignerWorkspaceGenerator; |
||||
import com.fr.design.env.DesignerWorkspaceInfo; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.file.TemplateTreePane; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.utils.DesignUtils; |
||||
import com.fr.env.EnvListPane; |
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.license.exception.RegistEditionException; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.EnvChangedListener; |
||||
import com.fr.workspace.WorkContext; |
||||
import com.fr.workspace.WorkContextCallback; |
||||
import com.fr.workspace.Workspace; |
||||
import com.fr.workspace.connect.AuthException; |
||||
|
||||
import javax.swing.JOptionPane; |
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.UIManager; |
||||
import java.util.HashMap; |
||||
|
||||
import static javax.swing.JOptionPane.ERROR_MESSAGE; |
||||
|
||||
public class EnvChangeEntrance { |
||||
|
||||
private String currentEnvName = ""; |
||||
|
||||
public static EnvChangeEntrance getInstance() { |
||||
return HOLDER.singleton; |
||||
} |
||||
|
||||
private static class HOLDER { |
||||
private static EnvChangeEntrance singleton = new EnvChangeEntrance(); |
||||
} |
||||
|
||||
|
||||
private EnvChangeEntrance() { |
||||
currentEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); |
||||
GeneralContext.addEnvChangedListener(new EnvChangedListener() { |
||||
@Override |
||||
public void envChanged() { |
||||
currentEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private boolean envListOkAction(EnvListPane envListPane) { |
||||
final String selectedName = envListPane.updateEnvManager(); |
||||
return switch2Env(selectedName); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 切换到新环境 |
||||
* |
||||
* @param envName 新工作环境名称 |
||||
* @return 是否成功 |
||||
*/ |
||||
public boolean switch2Env(final String envName) { |
||||
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); |
||||
DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); |
||||
|
||||
try { |
||||
Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv); |
||||
boolean checkValid = workspace != null && selectedEnv.checkValid(); |
||||
if (!checkValid) { |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), |
||||
UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); |
||||
return false; |
||||
} |
||||
WorkContext.switchTo(workspace, new WorkContextCallback() { |
||||
@Override |
||||
public void done() { |
||||
DesignerEnvManager.getEnvManager().setCurEnvName(envName); |
||||
DesignUtils.refreshDesignerFrame(); |
||||
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||
if (template != null) { |
||||
template.refreshToolArea(); |
||||
} |
||||
DesignTableDataManager.fireDSChanged(new HashMap<String, String>()); |
||||
} |
||||
}); |
||||
|
||||
} catch (AuthException | RegistEditionException e) { |
||||
// String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed");
|
||||
// String title = Toolkit.i18nText("Fine-Design_Basic_Lic_Does_Not_Support_Remote");
|
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), |
||||
UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); |
||||
return false; |
||||
} catch (Exception exception) { |
||||
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), |
||||
UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); |
||||
return false; |
||||
} |
||||
TemplateTreePane.getInstance().refreshDockingView(); |
||||
DesignModelAdapter<?, ?> model = DesignModelAdapter.getCurrentModelAdapter(); |
||||
if (model != null) { |
||||
model.envChanged(); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 编辑items |
||||
* |
||||
* @see EnvChangeEntrance#chooseEnv() |
||||
* @deprecated use {@link EnvChangeEntrance#chooseEnv()} |
||||
*/ |
||||
@Deprecated |
||||
public void editItems() { |
||||
chooseEnv(); |
||||
} |
||||
|
||||
/** |
||||
* 出现对话框,选择使用的工作环境 |
||||
*/ |
||||
public void chooseEnv() { |
||||
final EnvListPane envListPane = new EnvListPane(); |
||||
final BasicDialog envListDialog = envListPane.showWindow(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame())); |
||||
|
||||
envListPane.populateEnvManager(currentEnvName); |
||||
envListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
envListDialog.dispose(); |
||||
envListOkAction(envListPane); |
||||
} |
||||
|
||||
@Override |
||||
public void doCancel() { |
||||
|
||||
envListDialog.dispose(); |
||||
} |
||||
}); |
||||
envListDialog.setVisible(true); |
||||
} |
||||
|
||||
/** |
||||
* 处理异常 |
||||
*/ |
||||
public void dealEvnExceptionWhenStartDesigner() { |
||||
final EnvListPane envListPane = new EnvListPane(); |
||||
envListPane.populateEnvManager(currentEnvName); |
||||
BasicDialog envListDialog = envListPane.showWindow(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame())); |
||||
envListDialog.addDialogActionListener(new DialogActionAdapter() { |
||||
|
||||
@Override |
||||
public void doOk() { |
||||
|
||||
if (!envListOkAction(envListPane)) { |
||||
System.exit(0); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void doCancel() { |
||||
System.exit(0); |
||||
} |
||||
}); |
||||
envListDialog.setVisible(true); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue