|
|
@ -14,6 +14,7 @@ import com.fr.design.login.DesignerLoginSource; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
import com.fr.design.mainframe.share.util.DownloadUtils; |
|
|
|
import com.fr.design.mainframe.share.util.DownloadUtils; |
|
|
|
|
|
|
|
import com.fr.design.mainframe.theme.dialog.TemplateThemeUsingDialog; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.transaction.CallBackAdaptor; |
|
|
|
import com.fr.transaction.CallBackAdaptor; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
@ -21,7 +22,11 @@ import com.fr.workspace.WorkContext; |
|
|
|
import javax.swing.Action; |
|
|
|
import javax.swing.Action; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
import javax.swing.SwingWorker; |
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
|
|
|
import java.awt.Window; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
|
|
import java.awt.event.WindowAdapter; |
|
|
|
|
|
|
|
import java.awt.event.WindowEvent; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Starryi |
|
|
|
* @author Starryi |
|
|
@ -31,6 +36,7 @@ import java.awt.event.ActionEvent; |
|
|
|
public class DownloadSuitableThemeAction extends UpdateAction { |
|
|
|
public class DownloadSuitableThemeAction extends UpdateAction { |
|
|
|
private final String themePath; |
|
|
|
private final String themePath; |
|
|
|
private boolean downloading = false; |
|
|
|
private boolean downloading = false; |
|
|
|
|
|
|
|
private JTemplate<?, ?> currentTemplate; |
|
|
|
|
|
|
|
|
|
|
|
public DownloadSuitableThemeAction(String themePath) { |
|
|
|
public DownloadSuitableThemeAction(String themePath) { |
|
|
|
this.themePath = themePath; |
|
|
|
this.themePath = themePath; |
|
|
@ -40,9 +46,8 @@ public class DownloadSuitableThemeAction extends UpdateAction { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
if (checkAuthority()) { |
|
|
|
currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
saveTheme(); |
|
|
|
fetchTheme(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean checkAuthority() { |
|
|
|
private boolean checkAuthority() { |
|
|
@ -63,43 +68,43 @@ public class DownloadSuitableThemeAction extends UpdateAction { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void saveTheme() { |
|
|
|
private void fetchTheme() { |
|
|
|
|
|
|
|
if (!checkAuthority()) { |
|
|
|
|
|
|
|
onThemeFetched(null); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
if (downloading) { |
|
|
|
if (downloading) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
downloading = true; |
|
|
|
downloading = true; |
|
|
|
|
|
|
|
|
|
|
|
final JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
new SwingWorker<FormTheme, Void>() { |
|
|
|
new SwingWorker<Boolean, Void>() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Boolean doInBackground() { |
|
|
|
protected FormTheme doInBackground() { |
|
|
|
FormTheme theme = fetchRemoteTheme(); |
|
|
|
return DownloadUtils.downloadThemeFile(themePath); |
|
|
|
if (theme == null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
theme = ensureThemeHasUniqueName(theme, theme.getName()); |
|
|
|
|
|
|
|
if (theme == null) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String themeName = theme.getName(); |
|
|
|
|
|
|
|
saveThemeToConfig(theme, new SaveToThemeConfigCallback(template, themeName)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void done() { |
|
|
|
protected void done() { |
|
|
|
|
|
|
|
FormTheme theme = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
theme = get(); |
|
|
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onThemeFetched(theme); |
|
|
|
downloading = false; |
|
|
|
downloading = false; |
|
|
|
} |
|
|
|
} |
|
|
|
}.execute(); |
|
|
|
}.execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private FormTheme fetchRemoteTheme() { |
|
|
|
public void onThemeFetched(FormTheme theme) { |
|
|
|
return DownloadUtils.downloadThemeFile(themePath); |
|
|
|
if (theme == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saveTheme(theme); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) { |
|
|
|
private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) { |
|
|
@ -118,36 +123,65 @@ public class DownloadSuitableThemeAction extends UpdateAction { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void saveThemeToConfig(final FormTheme theme, CallBackAdaptor callback) { |
|
|
|
private void saveTheme(FormTheme theme) { |
|
|
|
FormThemeConfig.getInstance().addTheme(theme, true, callback); |
|
|
|
final FormTheme uniqueNamedTheme = ensureThemeHasUniqueName(theme, theme.getName()); |
|
|
|
|
|
|
|
if (uniqueNamedTheme != null) { |
|
|
|
|
|
|
|
FormThemeConfig.getInstance().addTheme(theme, true, new CallBackAdaptor() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void afterCommit() { |
|
|
|
|
|
|
|
super.afterCommit(); |
|
|
|
|
|
|
|
onThemeSaved(uniqueNamedTheme); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void afterRollback() { |
|
|
|
|
|
|
|
super.afterRollback(); |
|
|
|
|
|
|
|
onThemeSaved(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
onThemeSaved(null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onThemeSaved(FormTheme theme) { |
|
|
|
|
|
|
|
if (theme == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Window designerFrame = DesignerContext.getDesignerFrame(); |
|
|
|
|
|
|
|
TemplateThemeUsingDialog<FormTheme> dialog = new TemplateThemeUsingDialog<>(designerFrame, currentTemplate, FormThemeConfig.getInstance()); |
|
|
|
|
|
|
|
dialog.addWindowListener(new UsingDialogAdapter(theme)); |
|
|
|
|
|
|
|
dialog.setVisible(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void applyTheme(JTemplate<?, ?> template, final String name, Window dialog) { |
|
|
|
|
|
|
|
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); |
|
|
|
|
|
|
|
TemplateTheme theme = config.cachedFetch(name); |
|
|
|
|
|
|
|
template.setTemplateTheme(theme); |
|
|
|
|
|
|
|
dialog.repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static class SaveToThemeConfigCallback extends CallBackAdaptor { |
|
|
|
private class UsingDialogAdapter extends WindowAdapter { |
|
|
|
private final JTemplate<?,?> template; |
|
|
|
private final FormTheme theme; |
|
|
|
private final String themeName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SaveToThemeConfigCallback(JTemplate<?, ?> template, String themeName) { |
|
|
|
public UsingDialogAdapter(FormTheme theme) { |
|
|
|
this.template = template; |
|
|
|
this.theme = theme; |
|
|
|
this.themeName = themeName; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterCommit() { |
|
|
|
public void windowOpened(WindowEvent e) { |
|
|
|
super.afterCommit(); |
|
|
|
super.windowOpened(e); |
|
|
|
|
|
|
|
Window window = e.getWindow(); |
|
|
|
int returnVal = FineJOptionPane.showConfirmDialog( |
|
|
|
int returnVal = FineJOptionPane.showConfirmDialog( |
|
|
|
DesignerContext.getDesignerFrame(), |
|
|
|
window, |
|
|
|
Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"), |
|
|
|
Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"), |
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Confirm"), |
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Confirm"), |
|
|
|
FineJOptionPane.OK_CANCEL_OPTION); |
|
|
|
FineJOptionPane.OK_CANCEL_OPTION); |
|
|
|
if (returnVal == JOptionPane.YES_OPTION) { |
|
|
|
if (returnVal == JOptionPane.YES_OPTION) { |
|
|
|
applyTheme(template, themeName); |
|
|
|
applyTheme(currentTemplate, theme.getName(), window); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
window.removeWindowListener(this); |
|
|
|
|
|
|
|
|
|
|
|
private void applyTheme(JTemplate<?,?> template, final String name) { |
|
|
|
|
|
|
|
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); |
|
|
|
|
|
|
|
TemplateTheme theme = config.cachedFetch(name); |
|
|
|
|
|
|
|
template.setTemplateTheme(theme); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|