/** Refreshes the currently visible editor with new info. */ public void refreshEditors(DXEntry entry, DataBrokerQueryInterface ds) { if (currentEditor != null) { this.entry = entry; // TE: make sure everything is in sink. dataSource = ds; currentEditor.getDataSink().displayEntry(entry, ds); // checks for unsaved changes... // check that the editor hasn't changed display component JComponent display = currentEditor.getDisplayComponent(); // XXX hack alert - some editor writers change their display component // XXX mid-flight, and expect JX to magically notice, and change the // XXX the display. This code attempts to do this. if (indexOfComponent(display) == -1) // we have a problem - the display component has changed { String title = currentEditor.getName(); ImageIcon icon = currentEditor.getIcon(); String toolTip = currentEditor.getToolTip(); int index = getSelectedIndex(); // find the index of the editor (XXX - this relies on the // activeEditor vector tracking the inherent tab pane order) super.remove(index); super.insertTab(title, icon, display, toolTip, index); super.setSelectedIndex(index); } } else log.warning("internal error - no editor available in AttributeDisplay"); }
public void remove(int index) { if (activeEditors.size() == 0) return; // it can get a bit excitable about removing element 0 ... PluggableEditor ed = (PluggableEditor) activeEditors.remove(index); ed.unload(); super.remove(index); }
/** * This is a 'get out of jail free' method that allows an external class to force the display of a * particular editor. (e.g. for a pluggable editor system that wants to be started on an empty * directory). * * @param entry the entry to display (may be null) * @param ds the data source to use for directory info. * @param editorName the name to display in the editor tab. */ public void displaySpecialEntry(DXEntry entry, DataBrokerQueryInterface ds, String editorName) { PluggableEditor ed = getEditor(editorName); if (ed != null) { if (ed.isUnique() == false) { setCurrentEditor(ed); } else { if (currentEditor != ed) addUniqueEditor(ed); refreshEditors(entry, ds); oldOCSig = null; } } }
/** Adds an editor to the current collection of active editors, and makes it a tab pane. */ void addEditor(PluggableEditor ed) { if (activeEditors.contains(ed) == false) // don't add editors twice! { add(ed); ed.registerComponents( registerMenu, registerButtons, registerTree, registerTreeMenu, registerJX); } }
/** * This looks through a list of object classes in an attribute until it finds a unique editor * corresponding to a particular value. If no editor is found 'null' is returned. Note that If * multiple unique editors exist, which one is returned is undefined. * * <p> * * @param oc the objectClass attribute; a list of object classes * @return the unique pluggable editor corresponding to one particular object class value, or null * if none is found. */ public PluggableEditor getUniqueEditor(Attribute oc) { try { Enumeration values = oc.getAll(); while (values.hasMoreElements()) { String objectClassName = (String) values.nextElement(); PluggableEditor editor = getEditor(objectClassName); if (editor != null) { if (editor.isUnique()) return editor; } } return null; } catch (Exception e) { log.log(Level.FINE, "Unable to find unique pluggable editor: ", e); return null; } }
/** * Sets the current editor to the specified editor, loads the current entry, and makes sure that * it is visible to the user. * * @param makeCurrent the editor to select. */ protected void setCurrentEditor(PluggableEditor makeCurrent) { currentEditor = makeCurrent; if (currentEditor != null && currentEditor.getDataSink() != null) currentEditor.getDataSink().displayEntry(entry, dataSource); int index = activeEditors.indexOf(makeCurrent); if (index == -1) { clearPluggableEditors(); addEditor(makeCurrent); setSelectedIndex(activeEditors.indexOf(makeCurrent)); } else if (index != getSelectedIndex()) { setSelectedIndex(index); } }
public void add(PluggableEditor ed, int index) { // add(ed.getName(), ed.getDisplayComponent()); // wierd array bounds error thrown here? insertTab(ed.getName(), ed.getIcon(), ed.getDisplayComponent(), ed.getToolTip(), index); activeEditors.add(index, ed); }
/** Return the thingumy that should be printed. */ public Component getPrintComponent() { return currentEditor.getPrintComponent(); }
/** * Clear out all the old editors, and get new editors corresponding to the new object classes. * * @param entry the entry to be displayed by all the editors * @param ds the datasource the editors may use for more info * @param ocs the object classes (in order) to find editors for. */ protected void setEditors(DXEntry entry, DataBrokerQueryInterface ds, Vector ocs) { try { clearPluggableEditors(); // clear all extra editors // search for unique structural editors... if ("false".equalsIgnoreCase(JXConfig.getProperty("plugins.ignoreUniqueness"))) { if (ocs == null) // TE: may happen if virtual entry. return; int size = ocs.size(); for (int i = 0; i < size; i++) { Object objectClass = ocs.get(i); if (objectClass != null) { PluggableEditor ed = getEditor(objectClass.toString()); if (ed != null && ed.isUnique() == true) // found a unique editor { // so clear old ones, addUniqueEditor(ed); // and use the unique one refreshEditors(entry, ds); // to display the data setCurrentEditor(ed); return; // ... and exit. } } } } else log.warning("skipping uniqueness test for pluggable editors"); boolean newEdSet = false; // search for non-unique structural editors for (int i = 0; i < ocs.size(); i++) { Object objectClass = ocs.get(i); if (objectClass != null) { PluggableEditor ed = getEditor(objectClass.toString()); if (ed != null) { addEditor(ed); // Force the displayed editor to be the first pluggable one... if (newEdSet == false) { setCurrentEditor(ed); newEdSet = true; } } } } // search for non-structural editors try { Attribute allOCs = entry.getAllObjectClasses(); if (allOCs != null) { Enumeration vals = allOCs.getAll(); while (vals.hasMoreElements()) { Object oc = vals.nextElement(); if (oc != null) { String ocName = oc.toString(); if (ocs.contains(ocName) == false) // don't bother with struct objectclasses dealt with above { PluggableEditor ed = getEditor(ocName); if (ed != null) { addEditor(ed); if (ed.isUnique()) // a special service to users... log.warning( "WARNING: Illegal unique editor defined for oc: " + ocName + " not allowed - (oc not in primary structural inheritance chain)"); } } } } } } catch (NamingException e) { log.log( Level.WARNING, "WARNING: non-fatal exception getting object classes for plugin editors. ", e); } addEditor(templateDisplay); // and always add old faithfulls... // XXX if (entry.getStatus() != DXEntry.NEW) // well, almost always... addEditor(tableDisplay); } catch (Exception e) { log.warning("Unexpected Exception in AttributeDisplay\n" + e); e.printStackTrace(); } }
public void displayEntry(DXEntry dxentry, DataBrokerQueryInterface ds) { // Set the local data variables. dataSource = ds; entry = dxentry; // check that the default editors have been initialised. if (tableDisplay == null) initTableEditor(); if (templateDisplay == null) initHTMLEditor(); // check for a 'no data' display - if there is no data, revert // to the default html 'no data' template. if (entry == null) // || entry.size() == 0) //TE: This is commented out to allow virtual nodes to be // edited. { if (oldOCSig != null) { clearPluggableEditors(); if (activeEditors.size() == 0) { addEditor(templateDisplay); } oldOCSig = null; } refreshEditors(null, ds); } else { dataSource = ds; // may be null... Vector ocs = entry.getOrderedOCs(); // try to create a unique 'signature' for a group of object classes // This relies on them being delivered in the same order though. (Less // efficient if they aren't, but otherwise shouldn't be a big problem). String newOCSig = new String(); if (ocs != null) for (int i = 0; i < ocs.size(); i++) { Object ocSig = ocs.get(i); if (ocSig != null) newOCSig += ocSig.toString(); } // Check if signiture hasn't changed. If it *has* changed, // reset the editors using 'setEditors', and update // the 'old object class signiture' variable. if (newOCSig.equals(oldOCSig) == false) { setEditors(entry, ds, ocs); oldOCSig = newOCSig; } // Some quick sanity checks... if (entry.getStatus() == DXEntry.NEW) // check for new entries (but *not* NEW_WRITTEN)... { // don't allow editors to appear that can't edit a new entry trimNonNewEntryEditors(); suggestPluggableEditor(); } else { // make sure that the html template display is around... // XXX (a bit of a hack - this should really check that *all* // XXX editor that can't handle new entries have been added back... // XXX (maybe set flag?) // TE: added '&& !currentEditor.isUnique()' b/c this code always made sure the HTML // TE: editor is visible, whereas with a unique plugin we only want that one visible... // TE: unless of course I am totally confused! See bug 674. if (activeEditors.contains(templateDisplay) == false && !currentEditor.isUnique()) { add((PluggableEditor) templateDisplay, 0); if (currentEditor != null) // XXX hack hack. setCurrentEditor(currentEditor); } } if (activeEditors.contains(currentEditor) == false) { suggestPluggableEditor(); } // now that the editor set we're using has been sorted out, // actually go and update the editors! (Nb. this triggers an usaved changes check) refreshEditors(entry, ds); } }