/** 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; }