use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceList method upload.
@FXML
private void upload(ActionEvent event) {
// 禁用上传按钮
((Button) event.getSource()).setDisable(true);
uploadTip.setText(MsgUtil.getMessage("ftp.upload.waiting"));
AlertUtil.showConfirm(MsgUtil.getMessage("ftp.upload.confirmation"), (resp) -> {
if (ButtonType.NO == resp) {
((Button) event.getSource()).setDisable(false);
uploadTip.setText(null);
return;
}
String filePath = uploadFile.getAbsolutePath();
String fileName = FileUtil.getFileName(filePath);
String ext = FileUtil.getFileExt(filePath);
// 重命名
String rename = UUID.randomUUID() + "." + ext;
// 上传文件到FTP
boolean uploaded = SpringUtil.getBean(FTPUtils.class).uploadFile(ResourceConsts.FTP_RES_PATH, uploadFile, rename);
if (!uploaded) {
AlertUtil.showAlert(AlertType.ERROR, MsgUtil.getMessage("ftp.upload.failure"));
// 启用上传按钮
((Button) event.getSource()).setDisable(false);
return;
}
// 封装资源记录
int type = ResourceType.parseType(ext);
Resource resource = new Resource();
resource.setKeyword(keywords.getText());
resource.setPath(rename);
resource.setName(fileName);
try {
resource.setType(type);
} catch (Exception e) {
LOG.warn("解析文件后缀名出现错误", e);
throw e;
}
// 记录到数据库
Integer id = action.addResource(resource);
if (id != null) {
AlertUtil.showAlert(AlertType.INFORMATION, MsgUtil.getMessage("ftp.upload.success"));
} else {
AlertUtil.showAlert(AlertType.ERROR, MsgUtil.getMessage("ftp.upload.converter.failure"));
}
// 启用上传按钮
((Button) event.getSource()).setDisable(false);
clear();
pagination.reload();
});
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class ResourceList method createTable.
private void createTable() {
// 数据库唯一表示
Column<Integer> id = new Column<>();
id.setPrimary(true);
id.setVisible(false);
id.setKey("id");
// 资源图标
Column<Integer> icon = new Column<>();
icon.setAlignment(Pos.CENTER_RIGHT);
icon.setKey("type");
icon.setText("");
icon.setMaxWidth(25);
Function<Integer, SVGGlyph> converter = new Function<Integer, SVGGlyph>() {
@Override
public SVGGlyph apply(Integer type) {
if (type == null) {
return null;
}
ResourceType resourceType = ResourceType.getResourceType(type);
return new SVGGlyph(resourceType.getIcon(), resourceType.getColor(), 22);
}
};
icon.setCellFactory(SVGIconCell.forTableColumn(converter));
// 资源名称
Column<String> name = new Column<>();
name.setAlignment(Pos.CENTER_LEFT);
name.setKey("name");
name.setText(MsgUtil.getMessage("resource.name"));
name.setMaxWidth(250);
// 日期
Column<Date> date = new Column<>();
date.setAlignment(Pos.CENTER);
date.setKey("createDate");
date.setText(type.getDateLabel());
date.setMaxWidth(160);
date.setCellFactory(Cell.forTableColumn(new StringConverter<Date>() {
@Override
public String toString(Date date) {
return DateUtil.date2Str(date, DateUtil.DATE_TIME_PAT_SHOW_);
}
@Override
public Date fromString(String string) {
return null;
}
}));
table.getColumns().addAll(id, icon, name, date);
// 查看按钮
Column<String> view = new Column<String>();
view.setCellFactory(BtnCell.forTableColumn(MsgUtil.getMessage("button.view"), Priority.ALWAYS, "blue-btn", rid -> {
SpringUtil.getBean(ResourceAction.class).browsed((Integer) rid);
ResourceAction action = SpringUtil.getBean(ResourceAction.class);
Resource resource = action.findResourceByID((Integer) rid);
// 跳转到查看页面
PageController controller = SpringUtil.getBean(PageController.class);
controller.loadContent(new ResourceViewer(resource), PageLevel.Level2);
}));
view.setAlignment(Pos.CENTER_RIGHT);
table.getColumns().add(view);
if (type.isEditable()) {
// 删除按钮
Column<String> delete = new Column<String>();
delete.setCellFactory(BtnCell.forTableColumn(MsgUtil.getMessage("button.delete"), "blue-btn", rid -> {
AlertUtil.showConfirm(MsgUtil.getMessage("alert.confirmation.data.delete"), response -> {
if (response == ButtonType.YES) {
SpringUtil.getBean(ResourceAction.class).detele((Integer) rid);
pagination.reload();
}
});
}));
delete.setAlignment(Pos.CENTER_RIGHT);
delete.setMaxWidth(58);
table.getColumns().add(delete);
}
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class DrawingController method initDrawings.
private void initDrawings(TypicalCase3D typicalCase3D) {
clean();
TypicalCase typicalCase = typicalCase3D.getTypicalCase();
String drawings = typicalCase.getDrawings();
if (StringUtils.isEmpty(drawings)) {
return;
}
this.drawings = StringUtil.split(drawings);
List<Resource> resources = SpringUtil.getBean(ResourceAction.class).findResourcesByIds(this.drawings);
for (Resource resource : resources) {
addDrawingPreviewBtn(resource);
}
index = 0;
group.selectToggle(group.getToggles().get(index));
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class LnkParser2 method upload.
private void upload(File uploadFile, String fileName, String keyword) {
String filePath = uploadFile.getAbsolutePath();
String ext = FileUtil.getFileExt(filePath);
// 重命名
String rename = UUID.randomUUID() + "." + ext;
// 上传文件到FTP
ftpUtils.uploadFile(ResourceConsts.FTP_RES_PATH, uploadFile, rename);
// 封装资源记录
int type = ResourceType.parseType(ext);
Resource resource = new Resource();
resource.setPath(rename);
resource.setName(fileName);
resource.setCreator(1);
resource.setKeyword(keyword);
try {
resource.setType(type);
} catch (Exception e) {
LOG.warn("解析文件后缀名出现错误", e);
throw e;
}
// 记录到数据库
ResourceService service = (ResourceService) resourceServiceFactory.getObject();
Integer id = service.addResource(resource);
if (id != null) {
LOG.info("{}录入数据库成功!", filePath);
} else {
LOG.error("{}录入数据库失败!", filePath);
}
}
use of com.cas.sim.tis.entity.Resource in project TeachingInSimulation by ScOrPiOzzy.
the class DrawingSelectDialog method reload.
private void reload() {
List<Resource> resources = SpringUtil.getBean(ResourceAction.class).findResourcesByCreator(types, search.getText(), Session.get(Session.KEY_LOGIN_ID));
JSONArray array = new JSONArray();
array.addAll(resources);
table.setItems(array);
table.build();
}
Aggregations