forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~STARRYI/design:REPORT-60601/feature/x to feature/x * commit 'a875973026c58cb5b5d81dd142bfa0a429c38c9b': REPORT-60601 组件可更新提醒 无JIRA任务 可换行文本控件的颜色不符合预期feature/x
starryi
3 years ago
17 changed files with 925 additions and 75 deletions
@ -0,0 +1,154 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.block; |
||||||
|
|
||||||
|
import com.fr.design.DesignerEnvManager; |
||||||
|
import com.fr.design.extra.Process; |
||||||
|
import com.fr.design.login.DesignerLoginHelper; |
||||||
|
import com.fr.design.login.DesignerLoginSource; |
||||||
|
import com.fr.design.mainframe.share.collect.ComponentCollector; |
||||||
|
import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane; |
||||||
|
import com.fr.design.mainframe.share.util.DownloadUtils; |
||||||
|
import com.fr.design.mainframe.share.util.ShareComponentUtils; |
||||||
|
import com.fr.design.ui.util.UIUtil; |
||||||
|
import com.fr.form.share.DefaultSharableWidget; |
||||||
|
import com.fr.form.share.Group; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/10/26 |
||||||
|
*/ |
||||||
|
public class LocalWidgetUpdater implements Process<Double> { |
||||||
|
|
||||||
|
private double processValue = -1; |
||||||
|
public LocalWidgetBlock widgetBlock; |
||||||
|
private SwingWorker<Boolean, Void> worker; |
||||||
|
|
||||||
|
public LocalWidgetUpdater(LocalWidgetBlock widgetBlock) { |
||||||
|
this.widgetBlock = widgetBlock; |
||||||
|
} |
||||||
|
|
||||||
|
private DefaultSharableWidget getWidget() { |
||||||
|
return this.widgetBlock.getWidget(); |
||||||
|
} |
||||||
|
|
||||||
|
private Group getGroup() { |
||||||
|
return this.widgetBlock.getGroup(); |
||||||
|
} |
||||||
|
|
||||||
|
public double getProcessValue() { |
||||||
|
return processValue; |
||||||
|
} |
||||||
|
public boolean isUpdating() { |
||||||
|
return 0 <= processValue && processValue <= 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void updateWidget(String remoteLatestWidgetId, UpdateListener updateListener) { |
||||||
|
if (OnlineWidgetRepoPane.getInstance().isShowPackagePanel()) { |
||||||
|
ComponentCollector.getInstance().collectDownloadPktNum(); |
||||||
|
} |
||||||
|
|
||||||
|
LocalWidgetUpdater.this.process(0.0D); |
||||||
|
String userName = DesignerEnvManager.getEnvManager().getDesignerLoginUsername(); |
||||||
|
if (StringUtils.isEmpty(userName)) { |
||||||
|
DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
final DefaultSharableWidget widget = getWidget(); |
||||||
|
|
||||||
|
worker = new SwingWorker<Boolean, Void>() { |
||||||
|
|
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() { |
||||||
|
if (isCancelled()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
String filePath; |
||||||
|
try { |
||||||
|
filePath = DownloadUtils.download(remoteLatestWidgetId, widget.getName() + "." + widget.getId(), LocalWidgetUpdater.this); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return false; |
||||||
|
} |
||||||
|
ShareComponentUtils.checkReadMe(); |
||||||
|
//安装
|
||||||
|
File file = new File(filePath); |
||||||
|
try { |
||||||
|
if (file.exists()) { |
||||||
|
getGroup().installUniqueIdModule(file); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
//删掉下载组件的目录
|
||||||
|
StableUtils.deleteFile(file); |
||||||
|
} |
||||||
|
return true; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
LocalWidgetUpdater.this.process(-1.0); |
||||||
|
boolean success = false; |
||||||
|
try { |
||||||
|
success = get(); |
||||||
|
} catch (InterruptedException | ExecutionException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
if (updateListener != null) { |
||||||
|
updateListener.onUpdated(success, getGroup().getGroupName(), widget.getId()); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
worker.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
public void cancelUpdate() { |
||||||
|
if (worker.isDone() || worker.isCancelled()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
worker.cancel(true); |
||||||
|
process(-1.0); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void process(Double processValue) { |
||||||
|
this.processValue = processValue; |
||||||
|
|
||||||
|
UIUtil.invokeAndWaitIfNeeded(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
Container absoluteLayoutParent = getAbsoluteLayoutAncestor(widgetBlock); |
||||||
|
widgetBlock.repaint(); |
||||||
|
if (absoluteLayoutParent != null) { |
||||||
|
// 位于Block上方的遮罩层也要重绘下,否则Block的内容会绘制到遮罩层上方
|
||||||
|
absoluteLayoutParent.repaint(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public Container getAbsoluteLayoutAncestor(Component component) { |
||||||
|
Container container = component.getParent(); |
||||||
|
while (container != null && container.getLayout() != null) { |
||||||
|
container = container.getParent(); |
||||||
|
} |
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
public interface UpdateListener { |
||||||
|
void onUpdated(boolean success, String group, String id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.local; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.LayoutManager2; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/11/2 |
||||||
|
*/ |
||||||
|
public class FramePane extends JPanel { |
||||||
|
|
||||||
|
public FramePane() { |
||||||
|
setLayout(null); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void doLayout() { |
||||||
|
super.doLayout(); |
||||||
|
for (int i = 0; i < getComponentCount(); i++) { |
||||||
|
getComponent(i).setSize(getSize()); |
||||||
|
getComponent(i).setPreferredSize(getSize()); |
||||||
|
getComponent(i).setBounds(0, 0, getWidth(), getHeight()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,140 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.local; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.share.util.OnlineShopUtils; |
||||||
|
import com.fr.form.share.Group; |
||||||
|
import com.fr.form.share.SharableWidgetProvider; |
||||||
|
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
|
import com.fr.form.share.group.DefaultShareGroupManager; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugin.basic.version.Version; |
||||||
|
import com.fr.stable.ProductConstants; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
import java.util.concurrent.atomic.AtomicBoolean; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/11/3 |
||||||
|
*/ |
||||||
|
public class LocalWidgetRepoUpdater { |
||||||
|
private LocalWidgetRepoUpdater() {} |
||||||
|
private static class Holder { |
||||||
|
public static LocalWidgetRepoUpdater INSTANCE = new LocalWidgetRepoUpdater(); |
||||||
|
} |
||||||
|
public static LocalWidgetRepoUpdater getInstance() { |
||||||
|
return LocalWidgetRepoUpdater.Holder.INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
private final Map<String, OnlineShareWidget> remoteLatestWidgetsBackup = new HashMap<>(); |
||||||
|
|
||||||
|
private final AtomicBoolean isCheckingComponentUpdates = new AtomicBoolean(false); |
||||||
|
private SwingWorker<Boolean, Void> checkingComponentsUpdateWorker; |
||||||
|
|
||||||
|
private Set<String> getLocalWidgetIds() { |
||||||
|
Set<String> widgetIds = new HashSet<>(); |
||||||
|
Group[] groups = DefaultShareGroupManager.getInstance().getAllGroup(); |
||||||
|
for (Group group: groups) { |
||||||
|
SharableWidgetProvider[] widgetProviders = group.getAllBindInfoList(); |
||||||
|
for (SharableWidgetProvider provider: widgetProviders) { |
||||||
|
widgetIds.add(provider.getId()); |
||||||
|
} |
||||||
|
} |
||||||
|
return widgetIds; |
||||||
|
} |
||||||
|
|
||||||
|
public void clearUpdate() { |
||||||
|
remoteLatestWidgetsBackup.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
public OnlineShareWidget checkUpdate(SharableWidgetProvider provider) { |
||||||
|
OnlineShareWidget remoteLatestWidget = remoteLatestWidgetsBackup.get(provider.getId()); |
||||||
|
if (remoteLatestWidget != null && StringUtils.isNotEmpty(remoteLatestWidget.getVersion())) { |
||||||
|
Version remoteLatestVersion = Version.create(remoteLatestWidget.getVersion()); |
||||||
|
Version localVersion = Version.create(provider.getVersion()); |
||||||
|
|
||||||
|
boolean isUpdatable = remoteLatestVersion.compareTo(localVersion) > 0; |
||||||
|
if (isUpdatable) { |
||||||
|
return remoteLatestWidget; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public List<SharableWidgetProvider> getUpdatableWidgetProviders() { |
||||||
|
List<SharableWidgetProvider> updatableProviders = new ArrayList<>(); |
||||||
|
|
||||||
|
Group[] groups = DefaultShareGroupManager.getInstance().getAllGroup(); |
||||||
|
for (Group group: groups) { |
||||||
|
SharableWidgetProvider[] widgetProviders = group.getAllBindInfoList(); |
||||||
|
for (SharableWidgetProvider widgetProvider: widgetProviders) { |
||||||
|
if (checkUpdate(widgetProvider) != null) { |
||||||
|
updatableProviders.add(widgetProvider); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return updatableProviders; |
||||||
|
} |
||||||
|
|
||||||
|
public void fetchComponentUpdates(FetchComponentUpdatesListener listener) { |
||||||
|
if (isCheckingComponentUpdates.get()) { |
||||||
|
if (checkingComponentsUpdateWorker != null) { |
||||||
|
checkingComponentsUpdateWorker.cancel(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
clearUpdate(); |
||||||
|
listener.onFetchedBefore(); |
||||||
|
checkingComponentsUpdateWorker = new SwingWorker<Boolean, Void>() { |
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() { |
||||||
|
if (isCancelled()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
if (isCheckingComponentUpdates.compareAndSet(false, true)) { |
||||||
|
clearUpdate(); |
||||||
|
|
||||||
|
Set<String> widgetIds = getLocalWidgetIds(); |
||||||
|
String envVersion = ProductConstants.RELEASE_VERSION; |
||||||
|
|
||||||
|
List<OnlineShareWidget> remoteLatestWidgetList = OnlineShopUtils.getLatestReusesByDesignerVersion(widgetIds, envVersion); |
||||||
|
remoteLatestWidgetsBackup.clear(); |
||||||
|
for (OnlineShareWidget widget: remoteLatestWidgetList) { |
||||||
|
remoteLatestWidgetsBackup.put(widget.getUuid(), widget); |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void done() { |
||||||
|
boolean success = false; |
||||||
|
try { |
||||||
|
success = get(); |
||||||
|
} catch (InterruptedException | ExecutionException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
listener.onFetchedAfter(success, remoteLatestWidgetsBackup); |
||||||
|
isCheckingComponentUpdates.set(false); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
checkingComponentsUpdateWorker.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
public interface FetchComponentUpdatesListener { |
||||||
|
void onFetchedBefore(); |
||||||
|
void onFetchedAfter(boolean success, Map<String, OnlineShareWidget> remoteLatestWidgets); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue