/** * This notifies the user that they are about to lose entered data (i.e. they've made changes and * are about to a) change classes or b) go to another entry), and allows them to save their data * if they so choose... */ public void checkForUnsavedChanges() { if (dataSource == null || dataSource.isActive() == false) return; // no point prompting - nothing to save with! /* * Only ever check the entry once (sometimes promptForSave can be called * multiple time - remember that the 'save' function gets called by a * separate thread). */ if (tableData.changedByUser()) { String save = CBIntText.get("Save"); String discard = CBIntText.get("Discard"); int result = JOptionPane.showOptionDialog( owner, CBIntText.get("Submit changes to the Directory?"), CBIntText.get("Save Data"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {save, discard}, save); if (result == 0) { writeTableData(); // nb - this queues a request to the directory } } }
/** * Normally called by the 'Yes' button listener of the virtual entry dialog. This method opens the * New Entry dialog in simple mode (or Change Classes dialog). If the user selects one or more * object classes they are added to the entry and displayed in the table editor. */ public void processVirtualEntry() { ChangeObjectClassWin userData = null; if (dataSource.getSchemaOps() == null) { JOptionPane.showMessageDialog( owner, CBIntText.get( "Because there is no schema currently published by the\ndirectory, changing an entry's object class is unavailable."), CBIntText.get("No Schema"), JOptionPane.INFORMATION_MESSAGE); return; } else { shutVirtualEntryDialog(); // TE: kill the prompt window. userData = new ChangeObjectClassWin(dataSource, currentEntry.getDN(), null, this, owner, true); userData.setSize(400, 250); CBUtility.center(userData, owner); // TE: centres window. userData.setVisible(true); while (userData.isVisible()) // TE: don't do anything until the New Entry window is closed. { try { wait(); } catch (Exception e) { userData.dispose(); } } } if (userData.newObjectClasses != null) // TE: if the user has selected one or more object classes - add them to the entry // in the directory. { try { DXOps dxOps = new DXOps(dataSource.getLdapContext()); dxOps.addAttribute(currentEntry.getDN(), userData.newObjectClasses); dataSource.getEntry( currentEntry .getDN()); // TE: hack?? forces the entry to be read again - otherwise we don't // display the naming value. } catch (NamingException e) { CBUtility.error( TableAttributeEditor.this, CBIntText.get( "Unable to add new object classes to {0}.", new String[] {currentEntry.getDN().toString()}), e); } } }
/** Opens the change class dialog. */ public void changeClass() { // JPanel mainPanel /* * MINOR MAGIC * * This code reuses the 'new entry window'. In order to make things * sane, we prompt the user to save any serious changes before continuing. * (Things can get really wierd if the user changes the name and then * tries to change the objectclass - best to avoid the whole issue.) */ myEditor.stopCellEditing(); if (virtualEntry) { doVirtualEntryDisplay(); return; } /* * classChangedOriginalEntry saves the original state of the entry * between visits to NewEntryWin. (- I wonder if it would be neater * to just reset the 'oldEntry' state of the table every time? ). * Check it's not been set already (i.e. Pathological User is paying * multiple visits to the NewEntryWin.) */ if (classChangedOriginalEntry == null) classChangedOriginalEntry = tableData.getOldEntry(); DXEntry newEntry = tableData.getNewEntry(); DN newDN = newEntry.getDN(); /* * Pathalogical user has messed with the name, *and* wants to * change the object classes... */ if (newDN.equals(classChangedOriginalEntry.getDN()) == false) { checkForUnsavedChanges(); /* if (promptForSave() == false) // we may need to reset the 'newEntry' data { // if the user discards their changes. tableData.reset(); // resets the table before going on. newEntry = tableData.getNewEntry(); newDN = newEntry.getDN(); } else // user has saved data - so now we need to reset the 'classChangedOriginalEntry' { */ // to the changed (and hopefully saved!) data. // NB: If the directory write fails, then the change classes will also fail... classChangedOriginalEntry = tableData.getNewEntry(); } /* * Open NewEntryWin, allowing the user to reset the objectclass attribute. */ /* NewEntryWin userData = new NewEntryWin(newDN.parentDN(), newDN, dataSource, newEntry.getAsNonNullAttributes(), newDN.getLowestRDN().toString(), TableAttributeEditor.this, CBUtility.getParentFrame(mainPanel)); */ if (dataSource.getSchemaOps() == null) { JOptionPane.showMessageDialog( owner, CBIntText.get( "Because there is no schema currently published by the\ndirectory, changing an entry's object class is unavailable."), CBIntText.get("No Schema"), JOptionPane.INFORMATION_MESSAGE); return; } else { ChangeObjectClassWin userData = new ChangeObjectClassWin( dataSource, newDN, newEntry.getAsNonNullAttributes(), this, CBUtility.getParentFrame(this), false); userData.setSize(400, 250); CBUtility.center(userData, owner); // TE: centres window. userData.setVisible(true); } }