public FileNewAction(Window parent) { super(I18n.getText("menus.file.new"), Builder.getIcon("filenew.png", 22)); putValue(SHORT_DESCRIPTION, "Create a new series"); putValue(MNEMONIC_KEY, I18n.getMnemonic("menus.file.new")); putValue(ACCELERATOR_KEY, I18n.getKeyStroke("menus.file.new")); this.parent = parent; }
public EditPasteAction(AbstractEditor editor) { super("Paste", Builder.getIcon("editpaste.png", 22)); putValue(SHORT_DESCRIPTION, "Paste"); putValue(MNEMONIC_KEY, I18n.getMnemonic("menus.edit.paste")); putValue(ACCELERATOR_KEY, I18n.getKeyStroke("menus.edit.paste")); system = Toolkit.getDefaultToolkit().getSystemClipboard(); this.editor = editor; }
/** * Called to enable editing Responsible for loading the duplicate copy into the editor * * @param enable */ @SuppressWarnings("unchecked") protected void enableEditing(boolean enable) { propertiesTable.setEditable(enable); // show/hide our buttons editEntitySave.setEnabled(true); editEntityCancel.setEnabled(true); editEntitySave.setVisible(enable); editEntityCancel.setVisible(enable); if (currentEntity == null) { editEntityText.setText(null); } else { editEntityText.setFont(editEntityText.getFont().deriveFont(Font.BOLD)); editEntityText.setText( enable ? I18n.getText("metadata.currentlyEditingThis") + " " + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase() : I18n.getText("metadata.clickLockToEdit") + " " + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase()); } editEntity.setSelected(enable); if (enable) { if (currentEntity == null) return; if (currentEntity instanceof ITridasSeries) temporaryEditingEntity = TridasCloner.cloneSeriesRefValues( (ITridasSeries) currentEntity, (Class<? extends ITridasSeries>) currentEntity.getClass()); else temporaryEditingEntity = TridasCloner.clone(currentEntity, currentEntity.getClass()); if (temporaryEditingEntity != null) propertiesPanel.readFromObject(temporaryEditingEntity); } else { temporaryEditingEntity = null; // don't display anything if we have nothingk! if (currentEntity != null) { propertiesPanel.readFromObject(currentEntity); } else { return; } } }
/** @return true if the user wants to lose changes, false otherwise */ private boolean warnLosingChanges() { if (!hasChanged) return true; if (this.currentEntity == null) return true; int ret = JOptionPane.showConfirmDialog( this, I18n.getText("question.confirmChangeForm"), I18n.getText("question.continue"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (ret == JOptionPane.YES_OPTION) { hasChanged = false; } return (ret == JOptionPane.YES_OPTION); }
/** Save changes to the current entity */ private void doSave() { Class<? extends ITridas> type; if (temporaryEditingEntity == null) throw new IllegalStateException(); // if nothing actually changed, just ignore it like a cancel if (!hasChanged) { editEntityCancel.doClick(); return; } propertiesPanel.writeToObject(temporaryEditingEntity); // the resource we'll use EntityResource<? extends ITridas> resource; if (temporaryEditingEntity instanceof TridasObject) { resource = new EntityResource<TridasObject>( temporaryEditingEntity, TellervoRequestType.UPDATE, TridasObject.class); type = TridasObject.class; } else if (temporaryEditingEntity instanceof TridasElement) { resource = new EntityResource<TridasElement>( temporaryEditingEntity, TellervoRequestType.UPDATE, TridasElement.class); type = TridasElement.class; } else if (temporaryEditingEntity instanceof TridasSample) { resource = new EntityResource<TridasSample>( temporaryEditingEntity, TellervoRequestType.UPDATE, TridasSample.class); type = TridasSample.class; } else if (temporaryEditingEntity instanceof TridasRadius) { resource = new EntityResource<TridasRadius>( temporaryEditingEntity, TellervoRequestType.UPDATE, TridasRadius.class); type = TridasRadius.class; } else if (temporaryEditingEntity instanceof TridasMeasurementSeries) { resource = new EntityResource<TridasMeasurementSeries>( temporaryEditingEntity, TellervoRequestType.UPDATE, TridasMeasurementSeries.class); type = TridasMeasurementSeries.class; } else { log.debug("Can't save entity. Unsupported entity class."); return; } // set up a dialog... Window parentWindow = SwingUtilities.getWindowAncestor(this); TellervoResourceAccessDialog dialog = TellervoResourceAccessDialog.forWindow(parentWindow, resource); // query the resource resource.query(); dialog.setVisible(true); // on failure, just return if (!dialog.isSuccessful()) { JOptionPane.showMessageDialog( this, I18n.getText("error.savingChanges") + "\r\n" + I18n.getText("error") + ": " + dialog.getFailException().getLocalizedMessage(), I18n.getText("error"), JOptionPane.ERROR_MESSAGE); return; } // replace the saved result temporaryEditingEntity = resource.getAssociatedResult(); // sanity check the result if (temporaryEditingEntity == null) { new BugDialog(new IllegalStateException("CREATE or UPDATE entity returned null")); return; } setEntity(temporaryEditingEntity, type, true); // Inform the tree to update itself if (nodeSelected != null) { if (nodeSelected.getParent() == null) { } else if (nodeSelected.getParent().equals(nodeSelected.getRoot())) { ((TridasTreeViewPanel) treepanel).refreshNode(nodeSelected); } else { ((TridasTreeViewPanel) treepanel) .refreshNode((DefaultMutableTreeNode) nodeSelected.getParent()); } } hasChanged = false; }
/** Set up the button bar */ private void setupButtonBar() { bottombar = new JPanel(); bottombar.setLayout(new BoxLayout(bottombar, BoxLayout.X_AXIS)); editEntity = new JToggleButton(); editEntity.setIcon(Builder.getIcon("lock.png", Builder.ICONS, 22)); editEntity.setSelectedIcon(Builder.getIcon("unlock.png", Builder.ICONS, 22)); editEntity.setBorderPainted(false); editEntity.setContentAreaFilled(false); editEntity.setFocusable(false); editEntity.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!editEntity.isSelected() && hasChanged) { /*if(!warnLosingChanges()) { editEntity.setSelected(true); return; } else { editEntity.setSelected(false); hasChanged = false; }*/ doSave(); } enableEditing(editEntity.isSelected()); } }); bottombar.add(editEntity); editEntityText = new JLabel(I18n.getText("general.initializing").toLowerCase()); editEntityText.setLabelFor(editEntity); bottombar.add(editEntityText); editEntitySave = new JButton(I18n.getText("general.saveChanges")); editEntityCancel = new JButton(I18n.getText("general.cancel")); // don't let an errant enter key fire these buttons! editEntitySave.setDefaultCapable(false); editEntityCancel.setDefaultCapable(false); editEntitySave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doSave(); } }); editEntityCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hasChanged = false; editEntity.setSelected(false); enableEditing(false); } }); bottombar.add(Box.createHorizontalGlue()); bottombar.add(editEntitySave); bottombar.add(Box.createHorizontalStrut(6)); bottombar.add(editEntityCancel); bottombar.add(Box.createHorizontalStrut(6)); }