You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
80 lines
2.7 KiB
package com.fr.start.common; |
|
|
|
import com.fr.base.extension.FileExtension; |
|
import com.fr.design.DesignerEnvManager; |
|
import com.fr.file.FILE; |
|
import com.fr.file.FILEFactory; |
|
import com.fr.file.FileFILE; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.startup.ui.StartupPageModel; |
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import java.io.File; |
|
import java.util.Optional; |
|
|
|
/** |
|
* created by Harrison on 2022/07/09 |
|
**/ |
|
public class DesignerStartupUtil { |
|
|
|
/** |
|
* 如果是在启动页中 |
|
* |
|
* @param file 文件 |
|
* @return 成功/失败 |
|
*/ |
|
public static boolean openTemplateIfOnWaiting(File file) { |
|
|
|
DesignerStartupContext context = DesignerStartupContext.getInstance(); |
|
// 如果在启动页展示中 |
|
if (context.isOnWaiting()) { |
|
FileFILE fileFILE = new FileFILE(file); |
|
// 设置上一次启动模板为当前模板 |
|
// 注意这里需要设置为 envFullName |
|
DesignerEnvManager.getEnvManager().setLastOpenFile(fileFILE.getEnvFullName()); |
|
StartupPageModel model = context.getStartupPageModel(); |
|
Optional.ofNullable(model) |
|
.ifPresent((e) -> { |
|
// 执行上一次模板的启动 |
|
Runnable openLastTemplateRunnable = e.getOpenLastTemplateRunnable(); |
|
openLastTemplateRunnable.run(); |
|
}); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
@Nullable |
|
public static FILE convertArgs2FILE(String[] args) { |
|
|
|
// p:需要打开这个报表文件,这个代码不能删除. |
|
FILE file = null; |
|
for (String arg : args) { |
|
if (ComparatorUtils.equals("demo", arg)) { |
|
file = FILEFactory.createFILE(FILEFactory.ENV_PREFIX + DesignerEnvManager.getEnvManager().getLastOpenFile()); |
|
break; |
|
} |
|
File f = new File(arg); |
|
String path = f.getAbsolutePath(); |
|
if (isAcceptFilePathEnd(path)) { |
|
file = new FileFILE(f); |
|
} |
|
} |
|
return file; |
|
} |
|
|
|
private static boolean isAcceptFilePathEnd(String path) { |
|
FileExtension[] acceptFileExtensions = new FileExtension[]{ |
|
FileExtension.CPT, FileExtension.XLS, FileExtension.XLSX, FileExtension.FRM, FileExtension.CHT, FileExtension.VIS |
|
}; |
|
for (FileExtension acceptFileExtension : acceptFileExtensions) { |
|
String[] extensions = acceptFileExtension.getExtensions(); |
|
for (String extension : extensions) { |
|
if (path.endsWith("." + extension)) { |
|
return true; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
}
|
|
|