@Override public void actionPerformed(ActionEvent e) { String loc = RepositoryLocationChooser.selectLocation( lastLocation, "", RapidMinerGUI.getMainFrame(), true, false, true, true, true); if (loc != null) { RepositoryLocation location; try { location = new RepositoryLocation(loc); } catch (Exception ex) { SwingTools.showSimpleErrorMessage("malformed_rep_location", ex, loc); return; } try { if (location.locateEntry() != null) { // overwrite? if (SwingTools.showConfirmDialog("overwrite", ConfirmDialog.YES_NO_OPTION, location) != ConfirmDialog.YES_OPTION) { return; } } RepositoryManager.getInstance(null).store(object, location, null); lastLocation = location; } catch (RepositoryException ex) { SwingTools.showSimpleErrorMessage("cannot_store_obj_at_location", ex, loc); } } }
public String getRepositoryLocation() throws MalformedRepositoryLocationException { if (tree.getSelectionPath() != null) { Entry selectedEntry = (Entry) tree.getSelectionPath().getLastPathComponent(); RepositoryLocation selectedLocation = selectedEntry.getLocation(); if (selectedEntry instanceof Folder) { if (enforceValidRepositoryEntryName) { selectedLocation = new RepositoryLocation(selectedLocation, locationFieldRepositoryEntry.getText()); } else { selectedLocation = new RepositoryLocation(selectedLocation, locationField.getText()); } } if (RepositoryLocationChooser.this.resolveRelativeTo != null && resolveBox.isSelected()) { return selectedLocation.makeRelative(RepositoryLocationChooser.this.resolveRelativeTo); } else { return selectedLocation.getAbsoluteLocation(); } } else { if (enforceValidRepositoryEntryName) { return locationFieldRepositoryEntry.getText(); } else { return locationField.getText(); } } }
public void locateExpandedEntries() { for (String absoluteLocation : expandedNodes) { try { RepositoryLocation repositoryLocation = new RepositoryLocation(absoluteLocation); repositoryLocation.locateEntry(); } catch (MalformedRepositoryLocationException e) { LogService.getRoot().warning("Unable to expand the location:" + absoluteLocation); e.printStackTrace(); } catch (RepositoryException e) { LogService.getRoot().warning("Unable to expand the location:" + absoluteLocation); e.printStackTrace(); } } }
/** Returns true if the user entered a valid, non-empty repository location. */ public boolean hasSelection(boolean allowFolders) { if (!allowFolders && ((enforceValidRepositoryEntryName && locationFieldRepositoryEntry.getText().isEmpty()) || (!enforceValidRepositoryEntryName && locationField.getText().isEmpty()) || (enforceValidRepositoryEntryName && !RepositoryLocation.isNameValid(locationFieldRepositoryEntry.getText())))) { return false; } else { try { getRepositoryLocation(); return true; } catch (MalformedRepositoryLocationException e) { // LogService.getRoot().warning("Malformed repository location: " + e); LogService.getRoot() .log( Level.WARNING, I18N.getMessage( LogService.getRoot().getResourceBundle(), "com.rapidminer.repository.gui.RepositoryLocationChooser.malformed_repository_location", e), e); return false; } } }
@Override public void apply() { RepositoryLocation absLoc; try { absLoc = operator.getParameterAsRepositoryLocation(key); final RepositoryLocation processLoc = operator.getProcess().getRepositoryLocation().parent(); if (processLoc == null) { SwingTools.showVerySimpleErrorMessage( "quickfix_failed", "Process is not stored in repository."); } else { String relative = absLoc.makeRelative(processLoc); operator.setParameter(key, relative); } } catch (UserError e) { // Should not happen. Parameter should be set, otherwise we would not have created this // prefix. SwingTools.showVerySimpleErrorMessage("quickfix_failed", e.toString()); } }
protected void addCommonSteps() { addStep(new AnnotationDeclarationWizardStep(getState())); addStep(new MetaDataDeclarationWizardStep(getState())); if (getReader() == null) { addStep( new StoreDataWizardStep( this, getState(), (preselectedLocation != null) ? preselectedLocation.getAbsoluteLocation() : null)); } }
public RepositoryLocationChooser( Dialog owner, RepositoryLocation resolveRelativeTo, String initialValue, final boolean allowEntries, final boolean allowFolders, boolean enforceValidRepositoryEntryName, final boolean onlyWriteableRepositories) { if (initialValue != null) { try { RepositoryLocation repositoryLocation; if (resolveRelativeTo != null) { repositoryLocation = new RepositoryLocation(resolveRelativeTo, initialValue); } else { repositoryLocation = new RepositoryLocation(initialValue); } locationField.setText(repositoryLocation.getName()); locationFieldRepositoryEntry.setText(repositoryLocation.getName()); resultLabel.setText(repositoryLocation.toString()); } catch (Exception e) { } } this.resolveRelativeTo = resolveRelativeTo; this.enforceValidRepositoryEntryName = enforceValidRepositoryEntryName; tree = new RepositoryTree(owner, !allowEntries, onlyWriteableRepositories); if (initialValue != null) { if (tree.expandIfExists(resolveRelativeTo, initialValue)) { locationField.setText(""); locationFieldRepositoryEntry.setText(""); } } tree.getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (e.getPath() != null) { currentEntry = (Entry) e.getPath().getLastPathComponent(); if (currentEntry instanceof Folder) { // && allowFolders)) { // locationField.setText(""); } else if ((!(currentEntry instanceof Folder)) && allowEntries) { // if (true) { // //!(currentEntry instanceof Folder)) { locationField.setText(currentEntry.getLocation().getName()); locationFieldRepositoryEntry.setText(currentEntry.getLocation().getName()); } updateResult(); } } }); KeyListener keyListener = new KeyListener() { @Override public void keyPressed(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) { updateResult(); } @Override public void keyTyped(KeyEvent e) { TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { Entry selectedEntry = (Entry) selectionPath.getLastPathComponent(); if (!(selectedEntry instanceof Folder)) { tree.setSelectionPath(selectionPath.getParentPath()); } } } }; locationField.addKeyListener(keyListener); locationFieldRepositoryEntry.addKeyListener(keyListener); locationFieldRepositoryEntry.addObserver(this, true); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 0, 0, 0); c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.anchor = GridBagConstraints.FIRST_LINE_START; c.gridwidth = GridBagConstraints.REMAINDER; JScrollPane treePane = new ExtendedJScrollPane(tree); treePane.setBorder(ButtonDialog.createBorder()); add(treePane, c); c.insets = new Insets(ButtonDialog.GAP, 0, 0, ButtonDialog.GAP); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.weighty = 0; c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 0; locationLabel = new ResourceLabel("repository_chooser.entry_name"); locationLabel.setLabelFor(locationField); add(locationLabel, c); c.weightx = 1; c.insets = new Insets(ButtonDialog.GAP, 0, 0, 0); c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; add(locationField, c); add(locationFieldRepositoryEntry, c); if (enforceValidRepositoryEntryName) { locationField.setVisible(false); } else { locationFieldRepositoryEntry.setVisible(false); } c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 0; c.insets = new Insets(ButtonDialog.GAP, 0, 0, ButtonDialog.GAP); add(new ResourceLabel("repository_chooser.location"), c); c.weightx = 1; c.insets = new Insets(ButtonDialog.GAP, 0, 0, 0); c.gridwidth = GridBagConstraints.REMAINDER; add(resultLabel, c); if (resolveRelativeTo != null) { resolveBox = new JCheckBox( new ResourceActionAdapter( "repository_chooser.resolve", resolveRelativeTo.getAbsoluteLocation())); resolveBox.setSelected( ParameterService.getParameterValue( RapidMinerGUI.PROPERTY_RESOLVE_RELATIVE_REPOSITORY_LOCATIONS) .equals("true")); add(resolveBox, c); resolveBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateResult(); } }); } }
private void storeInFolder(final Folder folder) { // get current process name (if present) String currentName = null; if (RapidMinerGUI.getMainFrame().getProcess().getProcessLocation() != null) { currentName = RapidMinerGUI.getMainFrame().getProcess().getProcessLocation().getShortName(); } final String name = SwingTools.showRepositoryEntryInputDialog("store_process", currentName); if (name != null) { if (name.isEmpty()) { SwingTools.showVerySimpleErrorMessage("please_enter_non_empty_name"); return; } try { // check if folder already contains entry with said name RepositoryLocation entryLocation = new RepositoryLocation(folder.getLocation(), name); if (folder.containsEntry(name)) { Entry existingEntry = entryLocation.locateEntry(); if (!(existingEntry instanceof ProcessEntry)) { // existing entry is not a ProcessEntry, cannot overwrite SwingTools.showVerySimpleErrorMessage("repository_entry_already_exists", name); return; } else { // existing entry is ProcessEntry,let #overwriteProcess() handle it overwriteProcess((ProcessEntry) existingEntry); return; } } } catch (RepositoryException e1) { SwingTools.showSimpleErrorMessage("cannot_store_process_in_repository", e1, name); return; } catch (MalformedRepositoryLocationException e1) { SwingTools.showSimpleErrorMessage("cannot_store_process_in_repository", e1, name); return; } ProgressThread storeProgressThread = new ProgressThread("store_process") { public void run() { getProgressListener().setTotal(100); Process process = RapidMinerGUI.getMainFrame().getProcess(); RepositoryProcessLocation processLocation = null; try { processLocation = new RepositoryProcessLocation( new RepositoryLocation(folder.getLocation(), name)); getProgressListener().setCompleted(10); Process.checkIfSavable(process); folder.createProcessEntry(name, process.getRootOperator().getXML(false)); process.setProcessLocation(processLocation); tree.expandPath(tree.getSelectionPath()); RapidMinerGUI.addToRecentFiles(process.getProcessLocation()); RapidMinerGUI.getMainFrame().processHasBeenSaved(); } catch (Exception e) { SwingTools.showSimpleErrorMessage( "cannot_save_process", e, processLocation, e.getMessage()); RapidMinerGUI.getMainFrame().getProcess().setProcessLocation(null); } finally { getProgressListener().setCompleted(10); getProgressListener().complete(); } } }; storeProgressThread.start(); } }