/** Returns the root class of all objects. * Supposed to be overriden in subclasses. * * @return Object.class * @exception IOException an I/O error occured * @exception ClassNotFoundException the class has not been found */ public Class instanceClass () throws java.io.IOException, ClassNotFoundException { return cookie.instanceClass (); }
public Class instanceClass () throws java.io.IOException, ClassNotFoundException { return ic.instanceClass (); }
/** Accepts only cookies that can provide a <code>Component</code> * or a <code>Presenter.Toolbar</code>. * @param cookie the instance cookie to test * @return true if the cookie is accepted. */ protected InstanceCookie acceptCookie(InstanceCookie cookie) throws IOException, ClassNotFoundException { Class cls = cookie.instanceClass(); boolean is = Component.class.isAssignableFrom(cls) || Presenter.Toolbar.class.isAssignableFrom(cls) || Action.class.isAssignableFrom(cls); return is ? cookie : null; }
/** * Accepts only cookies that can provide <code>Configuration</code>. * @param cookie the instance cookie to test * @return true if the cookie can provide <code>Configuration</code> */ protected InstanceCookie acceptCookie (InstanceCookie cookie) throws java.io.IOException, ClassNotFoundException { Class cls = cookie.instanceClass(); if (ToolbarPool.Configuration.class.isAssignableFrom (cls)) { return cookie; } if (Component.class.isAssignableFrom (cls)) { return cookie; } return null; }
/** * Accepts only cookies that can provide <code>Menu</code>. * @param cookie an <code>InstanceCookie</code> to test * @return true if the cookie can provide accepted instances */ protected InstanceCookie acceptCookie(InstanceCookie cookie) throws IOException, ClassNotFoundException { // [pnejedly] Don't try to optimize this by InstanceCookie.Of // It will load the classes few ms later from instanceCreate // anyway and more instanceOf calls take longer Class c = cookie.instanceClass(); boolean is = Presenter.Menu.class.isAssignableFrom (c) || JMenuItem.class.isAssignableFrom (c) || JSeparator.class.isAssignableFrom (c) || Action.class.isAssignableFrom (c); return is ? cookie : null; }
public Class instanceClass () throws java.io.IOException, ClassNotFoundException { InstanceCookie delegateIC = delegateIC (); if (delegateIC == null) return this.getClass(); return delegateIC.instanceClass (); }
/** test if instance cookie is instance of clazz*/ private static boolean instanceOf(InstanceCookie inst, Class clazz) { if (inst instanceof InstanceCookie.Of) { return ((InstanceCookie.Of) inst).instanceOf(clazz); } else { try { return clazz.isAssignableFrom(inst.instanceClass()); } catch (Exception ex) { Logger.getLogger(Services.class.getName()).log(Level.WARNING, null, ex); return false; } } }
/** The class of this item. * @return the correct class */ public Class getType() { init (); try { return ic.instanceClass (); } catch (IOException ex) { // ok, no class available } catch (ClassNotFoundException ex) { // ok, no class available } return Object.class; }
/** try to find setter setName/setDisplayName, if none declared return null */ private Method getDeclaredSetter() { Method nameSetter = null; try { InstanceCookie ic = ic(); if (ic == null) return null; Class clazz = ic.instanceClass(); Class[] param = new Class[] {String.class}; // find the setter for the name try { nameSetter = clazz.getMethod ("setName", param); // NOI18N } catch (NoSuchMethodException e) { nameSetter = clazz.getMethod ("setDisplayName", param); // NOI18N } } catch (Exception ex) { } return nameSetter; }
/** Paste. */ public final Transferable paste () throws IOException { try { Class clazz = cookie.instanceClass (); // create the instance InstanceDataObject.create(getTargetFolder(), null, clazz); } catch (ClassNotFoundException ex) { throw new IOException (ex.getMessage ()); } // preserve clipboard return null; }
private static Children getChildren(DataObject dobj, boolean noBeanInfo) { if (noBeanInfo) { return Children.LEAF; } InstanceCookie inst = (InstanceCookie)dobj.getCookie(InstanceCookie.class); if (inst == null) return Children.LEAF; try { Class clazz = inst.instanceClass(); if (BeanContext.class.isAssignableFrom(clazz) || BeanContextProxy.class.isAssignableFrom(clazz)) { return new InstanceChildren ((InstanceDataObject) dobj); } else { return Children.LEAF; } } catch (Exception ex) { return Children.LEAF; } }
/** The class of the result item. * @return the class of the item */ protected boolean instanceOf (Class clazz) { init (); if (ic instanceof InstanceCookie.Of) { // special handling for special cookies InstanceCookie.Of of = (InstanceCookie.Of)ic; return of.instanceOf (clazz); } // handling of normal instance cookies try { return clazz.isAssignableFrom (ic.instanceClass ()); } catch (ClassNotFoundException ex) { exception(ex, fo); } catch (IOException ex) { exception(ex, fo); } return false; }
/** * Accepts only cookies that can provide <code>Toolbar</code>. * @param cookie an <code>InstanceCookie</code> to test * @return true if the cookie can provide accepted instances */ protected InstanceCookie acceptCookie (InstanceCookie cookie) throws java.io.IOException, ClassNotFoundException { boolean is; if (cookie instanceof InstanceCookie.Of) { InstanceCookie.Of of = (InstanceCookie.Of)cookie; is = of.instanceOf (Component.class) || of.instanceOf (Presenter.Toolbar.class) || of.instanceOf (Action.class); } else { Class c = cookie.instanceClass(); is = Component.class.isAssignableFrom(c) || Presenter.Toolbar.class.isAssignableFrom(c) || Action.class.isAssignableFrom (c); } return is ? cookie : null; }
protected void handleCreatePasteTypes (Transferable t, java.util.List s) { // These should only accept single-node transfers, since they require dialogs. Node node = NodeTransfer.node (t, NodeTransfer.CLIPBOARD_COPY); // lastly try special cookies if (node != null) { try { InstanceCookie cookie = (InstanceCookie)node.getCookie (InstanceCookie.class); if (cookie != null && java.io.Serializable.class.isAssignableFrom (cookie.instanceClass ())) { s.add (new DataTransferSupport.SerializePaste (DataFolder.this, cookie)); s.add (new DataTransferSupport.InstantiatePaste (DataFolder.this, cookie)); } } catch (IOException e) { } catch (ClassNotFoundException e) { } } } }
/** Overrides superclass method. It returns instance * for <code>DataObject</code>&<code>InstanceCookie</code> 'pair'. * If the instance is of <code>FolderLookup.Lkp</code> class it is created otherwise * new <code>Lkp.ICItem</code> created and returned. * * @param dobj the data object that is the source of the cookie * @param cookie the instance cookie to read the instance from * @exception IOException when there I/O error * @exception ClassNotFoundException if the class cannot be found */ protected Object instanceForCookie(DataObject dobj, InstanceCookie cookie) throws IOException, ClassNotFoundException { boolean isLookup; if(cookie instanceof InstanceCookie.Of) { isLookup = ((InstanceCookie.Of)cookie).instanceOf(Lookup.class); } else { isLookup = Lookup.class.isAssignableFrom(cookie.instanceClass ()); } if(isLookup) { // Is underlying FolderLookup create it. return cookie.instanceCreate(); } else { return new ICItem(dobj, rootName, cookie); } }
public boolean canCopy() { if (!getDataObject().getPrimaryFile().hasExt(XML_EXT)) return super.canCopy(); try { InstanceCookie ic = ic(); if (ic == null) return false; Class clazz = ic.instanceClass(); //XXX if (XMLSettingsSupport.BrokenSettings.class.isAssignableFrom(clazz)) // return false; return (!SharedClassObject.class.isAssignableFrom(clazz)); } catch (Exception ex) { return false; } }
public boolean canCut() { if (!getDataObject().getPrimaryFile().hasExt(XML_EXT)) return super.canCut(); try { InstanceCookie ic = ic(); if (ic == null) return false; Class clazz = ic.instanceClass(); return (!SharedClassObject.class.isAssignableFrom(clazz)); } catch (Exception ex) { return false; } }
/** Indicate whether the node may be destroyed. * @return tests {@link DataObject#isDeleteAllowed} */ public boolean canDestroy() { if (!getDataObject().getPrimaryFile().hasExt(XML_EXT)) return super.canDestroy(); try { InstanceCookie ic = ic(); if (ic == null) return true; Class clazz = ic.instanceClass(); return (!SharedClassObject.class.isAssignableFrom(clazz)); } catch (Exception ex) { return false; } }
/** try to register PropertyChangeListener to instance to fire its changes.*/ private void initPList () { try { InstanceCookie ic = ic(); if (ic == null) return; BeanInfo info = Utilities.getBeanInfo(ic.instanceClass()); java.beans.EventSetDescriptor[] descs = info.getEventSetDescriptors(); Method setter = null; for (int i = 0; descs != null && i < descs.length; i++) { setter = descs[i].getAddListenerMethod(); if (setter != null && setter.getName().equals("addPropertyChangeListener")) { // NOI18N Object bean = ic.instanceCreate(); propertyChangeListener = new PropL(); setter.invoke(bean, new Object[] {org.openide.util.WeakListeners.propertyChange(propertyChangeListener, bean)}); } } } catch (Exception ex) { } catch (LinkageError ex) { // #30650 - catch also LinkageError. // Ignoring exception the same way as the Exception handler above. } }
/** Gets the short description of this feature. */ public String getShortDescription() { if (noBeanInfo) return super.getShortDescription(); try { InstanceCookie ic = ic(); if (ic == null) { // it must be unrecognized instance return getDataObject().getPrimaryFile().toString(); } Class clazz = ic.instanceClass(); java.beans.BeanDescriptor bd = Utilities.getBeanInfo(clazz).getBeanDescriptor(); String desc = bd.getShortDescription(); return (desc.equals(bd.getName()))? getDisplayName(): desc; } catch (Exception ex) { return super.getShortDescription(); } catch (LinkageError ex) { // #30650 - catch also LinkageError. return super.getShortDescription(); } }