use of com.kyj.fx.voeditor.visual.framework.GagoyleParentOnLoaded in project Gargoyle by callakrsos.
the class DefaultPluginLoader method load.
/**
* 불러들인 플러그인에서 노드위치정보를 로드해온다.
*
* @return
*
* @작성자 : KYJ
* @작성일 : 2015. 12. 18.
*/
@Override
public List<JarWrapper> load() {
File[] pluginFiles = searchPlugins();
if (pluginFiles == null)
return Collections.emptyList();
return Stream.of(pluginFiles).map(file -> {
try {
@SuppressWarnings("resource") JarFile jarFile = new JarFile(file);
ZipEntry entry = jarFile.getEntry(PLUGIN_INI);
Properties properties = new Properties();
properties.load(jarFile.getInputStream(entry));
JarWrapper zipWrapper = new JarWrapper();
zipWrapper.location = file;
zipWrapper.jarFile = jarFile;
zipWrapper.prop = properties;
return zipWrapper;
} catch (Exception e) {
LOGGER.error(String.format("is not jar file \n%s", ValueUtil.toString(e)));
}
return null;
}).filter(/* jar파일이라면 로드됨. */
zipWrapper -> zipWrapper != null).map(/* 클래스정보 노출 */
zipWrapper -> {
String clazz = zipWrapper.prop.getProperty(KEY_DISPLAY_JAVAFX_NODE_CLASS);
String diplayMenuName = zipWrapper.prop.getProperty(KEY_DISPLAY_MENU_NAME);
String menuPath = zipWrapper.prop.getProperty(KEY_DISPLAY_MENU_PATH);
String configNodeClass = zipWrapper.prop.getProperty(KEY_DISPLAY_CONFIG_JAVAFX_NODE_CLASS);
String configNodeName = zipWrapper.prop.getProperty(KEY_DISPLAY_CONFIG_NAME);
String addOnParentLoadedListener = zipWrapper.prop.getProperty(ADD_ON_PARENT_LOADED_LISTENER);
String setOnParentBeforeLoadedListener = zipWrapper.prop.getProperty(SET_ON_PARENT_BEFORE_LOADED_LISTENER);
String classpath = zipWrapper.prop.getProperty(KEY_CLASSPATH);
String openType = zipWrapper.prop.getProperty(OPEN_TYPE);
if (clazz != null && !clazz.isEmpty()) {
zipWrapper.clazz = clazz;
zipWrapper.displayMenuName = diplayMenuName;
zipWrapper.menuPath = menuPath;
zipWrapper.configNodeClass = configNodeClass;
zipWrapper.configNodeName = configNodeName;
zipWrapper.addOnParentLoadedListener = addOnParentLoadedListener;
zipWrapper.setOnParentBeforeLoadedListener = setOnParentBeforeLoadedListener;
zipWrapper.openType = ValueUtil.isEmpty(openType) ? "INNER" : openType;
zipWrapper.classpath = classpath;
return zipWrapper;
}
return null;
}).filter(/* 유효한 정보만 다시 필터링하고 클래스 로딩 */
zipWrapper -> {
try {
URLClassLoader createLoader = DynamicClassLoader.createLoader(zipWrapper.location, zipWrapper.classpath);
zipWrapper.loader = createLoader;
Class<?> loadFromJarFile = createLoader.loadClass(zipWrapper.clazz);
if (Parent.class.isAssignableFrom(loadFromJarFile) || CloseableParent.class.isAssignableFrom(loadFromJarFile)) {
zipWrapper.nodeClass = loadFromJarFile;
LOGGER.debug(String.format("valide plugin class info : %s ", loadFromJarFile.getName()));
} else {
return false;
}
if (ValueUtil.isNotEmpty(zipWrapper.addOnParentLoadedListener)) {
try {
Class<?> addOnParentLoadedListenerClass = DynamicClassLoader.loadFromJarFile(zipWrapper.location, zipWrapper.addOnParentLoadedListener);
if (GagoyleParentOnLoaded.class.isAssignableFrom(addOnParentLoadedListenerClass)) {
zipWrapper.addOnParentLoadedListenerClass = (Class<GagoyleParentOnLoaded>) addOnParentLoadedListenerClass;
LOGGER.debug(String.format("added plugin listener :: class info : %s ", zipWrapper.addOnParentLoadedListener));
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
}
if (ValueUtil.isNotEmpty(zipWrapper.setOnParentBeforeLoadedListener)) {
try {
Class<?> setOnParentBeforeLoadedListenerClass = DynamicClassLoader.loadFromJarFile(zipWrapper.location, zipWrapper.setOnParentBeforeLoadedListener);
if (setOnParentBeforeLoadedListenerClass != null) {
if (GagoyleParentBeforeLoad.class.isAssignableFrom(setOnParentBeforeLoadedListenerClass)) {
zipWrapper.setOnParentBeforeLoadedListenerClass = (Class<GagoyleParentBeforeLoad>) setOnParentBeforeLoadedListenerClass;
LOGGER.debug(String.format("added plugin listener :: class info : %s ", zipWrapper.setOnParentBeforeLoadedListener));
}
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
return false;
}
return true;
}).collect(Collectors.toList());
}
use of com.kyj.fx.voeditor.visual.framework.GagoyleParentOnLoaded in project Gargoyle by callakrsos.
the class SystemLayoutViewController method initialize.
@FXML
public void initialize() {
// 쿼리 리스너를 등록
DbUtil.registQuertyListener(this);
try {
FXMLLoader loader = FxUtil.createNewFxmlLoader();
loader.setLocation(SystemLayoutViewController.class.getResource("DAOLoaderView.fxml"));
TitledPane titledPane = loader.load();
VBox.setVgrow(titledPane, Priority.ALWAYS);
accordionItems.getChildren().add(titledPane);
DAOLoaderController controller = loader.getController();
controller.setSystemLayoutViewController(this);
} catch (IOException e1) {
e1.printStackTrace();
}
SharedMemory.setSystemLayoutView(this);
SharedMemory.setWorkspaceTab(tabPanWorkspace);
// tab key에 대한 이벤트 처리 등록....
SharedMemory.getPrimaryStage().addEventHandler(KeyEvent.ANY, event -> {
boolean isCloseALLtabKeyCode = event.isControlDown() && event.isShiftDown() && KeyCode.W == event.getCode();
boolean isTabMoveCode = event.isControlDown() && isNumberCode(event.getCode());
ObservableList<DockTab> tabs = tabPanWorkspace.getTabs();
if (isCloseALLtabKeyCode) {
LOGGER.debug("CLOSE ALL TABS...");
for (int i = tabs.size() - 1; i > 0; i--) {
tabs.remove(i);
}
} else if (isTabMoveCode) {
int tabIndex = Integer.parseInt(event.getCode().getName());
if (tabIndex > 0 && tabs.size() < tabIndex)
return;
LOGGER.debug("MOVE TAB" + event.getCode().getName());
tabPanWorkspace.getSelectionModel().select(tabIndex - 1);
}
});
String baseDir = ResourceLoader.getInstance().get(ResourceLoader.BASE_DIR);
selectDirFile = new File(baseDir);
createNewTreeViewMenuItems();
webvWelcome.getEngine().setJavaScriptEnabled(true);
webvWelcome.getEngine().load(HOME_URL);
txtUrl.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (KeyCode.ENTER == event.getCode()) {
webvWelcome.getEngine().load(txtUrl.getText());
}
});
btnUrlSearch.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
if (event.getClickCount() >= 1) {
webvWelcome.getEngine().load(txtUrl.getText());
}
});
webvWelcome.setOnKeyPressed(key -> {
if (key.getCode() == KeyCode.F12) {
FxUtil.createStageAndShow("Simple Web Console", new WebViewConsole(webvWelcome));
}
});
treeProjectFile.setRoot(createNewTree(selectDirFile));
treeProjectFile.setShowRoot(false);
// 트리 컨테스트 요청 이벤트
treeProjectFile.setOnContextMenuRequested(this::treeProjectFileOnContextMenuRequested);
// 트리 마우스 이벤트
treeProjectFile.setOnMouseClicked(this::treeProjectFileOnMouseClick);
// 트리 키 이벤트
treeProjectFile.addEventHandler(KeyEvent.KEY_PRESSED, this::treeProjectFileOnKeyPressed);
/** 플러그인들을 로드함. **/
Platform.runLater(new Runnable() {
@Override
public void run() {
List<JarWrapper> load = PluginLoader.getInstance().load();
load.stream().forEach(jarWrapper -> {
try {
String displayMenuName = jarWrapper.getDisplayMenuName();
MenuItem pluginMenu = new MenuItem(displayMenuName);
pluginMenu.setUserData(jarWrapper);
pluginMenu.setOnAction(event -> {
JarWrapper jar = (JarWrapper) pluginMenu.getUserData();
try {
Class<?> nodeClass = jar.getNodeClass();
Object newInstance = jar.loader.loadClass(nodeClass.getName()).newInstance();
if (newInstance instanceof CloseableParent<?>) {
loadNewSystemTab(jar.getDisplayMenuName(), (CloseableParent<?>) newInstance);
} else {
loadNewSystemTab(jar.getDisplayMenuName(), (Parent) newInstance, SkinManager.getInstance().getJavafxDefaultSkin());
}
} catch (Exception e) {
LOGGER.error("regist fail plugin.");
LOGGER.error(ValueUtil.toString(e));
}
});
try {
Class<GagoyleParentBeforeLoad> setBeforeParentLoadListenerClass = jarWrapper.getSetOnParentBeforeLoadedListenerClass();
if (setBeforeParentLoadListenerClass != null)
setOnbeforeParentLoad(setBeforeParentLoadListenerClass.newInstance());
} catch (Exception e) {
LOGGER.error("regist fail 'GagoyleParentBeforeLoad' listener.");
}
try {
Class<GagoyleParentOnLoaded> addOnParentLoadedListenerClass = jarWrapper.getAddOnParentLoadedListenerClass();
if (addOnParentLoadedListenerClass != null)
addOnParentLoadedListener(addOnParentLoadedListenerClass.newInstance());
} catch (Exception e) {
LOGGER.error("regist fail 'GagoyleParentOnLoaded' listener.");
}
menuPlugins.getItems().add(pluginMenu);
} catch (Exception e) {
LOGGER.debug(ValueUtil.toString(e));
}
});
}
});
//tab image 아이콘 처리
try (InputStream is = getClass().getResourceAsStream("/META-INF/images/eclipse/eview16/packages.gif")) {
tabPackageExplorer.setGraphic(new ImageView(new Image(is)));
} catch (IOException e) {
e.printStackTrace();
}
tabPanWorkspace.getTabs().addListener(dockTabCloseListener);
}
Aggregations