use of se.light.assembly64.Support.isRemoteArtifact in project assembly64fx by freabemania.
the class Main method handleMouseClicked.
private static void handleMouseClicked(MouseEvent event) {
tree.setContextMenu(null);
TreeItem<GuiLocation> selectedItem = tree.getSelectionModel().getSelectedItem();
if (selectedItem == null || selectedItem.getValue() == null) {
return;
}
if (selectedItem.getValue().getType() == TYPE.ROOT) {
final ContextMenu contextMenu = new ContextMenu();
if (userService.getLocations().size() < MAX_INSTALLATIONS) {
contextMenu.getItems().add(createMenuWithAction(null, "Add new location", Type.ADD_LOCATION, selectedItem.getValue()));
}
contextMenu.getItems().add(createMenuWithAction(null, "Locally synced directory", Type.ADD_PRIVATE_DIR, null));
contextMenu.getItems().add(createMenuWithAction(null, "Install and update all", Type.INSTALL_AND_UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
contextMenu.getItems().add(createMenuWithAction(null, "Refresh view", Type.REFRESH_VIEW, selectedItem.getValue()));
contextMenu.getItems().add(createMenuWithAction(null, "Reset all views", Type.RESET_ALL_VIEWS, selectedItem.getValue()));
tree.setContextMenu(contextMenu);
return;
}
if (selectedItem.getValue().getType() == TYPE.INSTALLATION_ROOT) {
GuiLocation selectedInstallation = selectedItem.getValue();
if (userService.isInstallationExisting(selectedInstallation.getId())) {
if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
final ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().add(createMenuWithAction(null, "Update and install all", Type.INSTALLUPDATE_ALL, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Housekeep", Type.HOUSEKEEP, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Set as primary", Type.SET_AS_PRIMARY, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Reset view", Type.RESET_VIEW, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LOCATION, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
tree.setContextMenu(contextMenu);
} else if (event.getClickCount() == 2) {
String key = resolveInstallationExpandedKey(selectedInstallation.getId());
if (localDbService.hasLocalDBSetting(key)) {
localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
} else {
localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
}
}
} else {
final ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
tree.setContextMenu(contextMenu);
}
return;
}
if (selectedItem.getValue().getType() == TYPE.LEAF) {
if (event.getClickCount() == 2) {
GuiLocation selectedInstallation = selectedItem.getValue();
String key = resolveLeafInInstallationExpandedKey(selectedInstallation);
if (localDbService.hasLocalDBSetting(key)) {
localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
} else {
localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
}
} else if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
ContextMenu contextMenu = getContextMenu();
contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LEAF_LOCATION, selectedItem.getValue()));
}
return;
}
if (selectedItem.getValue().getType() == TYPE.INSTALLATION) {
if (event.getClickCount() == 2) {
tree.getSelectionModel().clearSelection();
GuiUtils.showDialog("searchMain.fxml", "Search assemblydb", selectedItem.getValue().getArtifact());
return;
} else {
try {
if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
if (tree.getContextMenu() == null) {
tree.setContextMenu(new ContextMenu());
}
ContextMenu contextMenu = tree.getContextMenu();
contextMenu.getItems().clear();
GuiLocation selectedInstallation = selectedItem.getValue();
List<ActionAndIdHolder> actions = new ArrayList<>();
Artifact clickedEntry = selectedInstallation.getArtifact();
boolean installed = artifactsService.isInstalled(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry);
if (!installed) {
actions.add(new ActionAndIdHolder(clickedEntry, Type.INSTALL, selectedInstallation));
} else if (artifactsService.needsUpdate(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry)) {
actions.add(new ActionAndIdHolder(clickedEntry, Type.UPDATE, selectedInstallation));
}
boolean containsInstall = actions.stream().filter(item -> item.getType() == Type.INSTALL).findFirst().isPresent();
boolean containsUpdate = actions.stream().filter(item -> item.getType() == Type.UPDATE).findFirst().isPresent();
if (Support.isRemoteArtifact(clickedEntry) || (Support.isLocalArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable())) {
if (containsInstall) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Install", Type.INSTALL, selectedInstallation));
} else if (containsUpdate) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Update", Type.INSTALL, selectedInstallation));
}
}
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Info", Type.INFO, selectedInstallation));
if (installed) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Open folder", Type.OPEN, selectedInstallation));
}
if (Support.isRemoteArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable()) {
if (!installed) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide", Type.HIDE, selectedInstallation));
} else {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Uninstall", Type.UNINSTALL, selectedInstallation));
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide & uninstall", Type.HIDE, selectedInstallation));
}
}
if (Support.isRemoteArtifact(clickedEntry) && userService.isPremium()) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Search", Type.SEARCH, selectedInstallation));
}
if (clickedEntry.isMarkedForUpdate()) {
if (!clickedEntry.isUpdating()) {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Cancel", Type.CANCEL_UPDATE, selectedInstallation));
}
}
if (installed && Support.isRemoteArtifact(clickedEntry)) {
String baseLocation = Support.appendPathIfMissing(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation().getLocation()) + clickedEntry.getAbsoluteInstallationPath();
File releaseNoteFile = new File(Support.appendPathIfMissing(baseLocation + "/releaselog.json"));
ReturningTask<Void> showExtraMenuTask = () -> {
if (releaseNoteFile.exists()) {
Platform.runLater(() -> {
contextMenu.getItems().add(createMenuWithAction(clickedEntry, "View new entries", Type.SHOW_RELEASES, selectedInstallation, baseLocation));
});
}
return null;
};
ExecutorUtil.executeAsyncWithRetry(showExtraMenuTask);
}
} else {
tree.getSelectionModel().clearSelection();
}
} catch (Exception e) {
LOGGER.error("Exception in mouseclick", e);
}
}
}
}
Aggregations