org.openide.cookies.InstanceCookie Java Examples

The following examples show how to use org.openide.cookies.InstanceCookie. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tutorials.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Action extractAction( DataObject dob ) {
    OpenCookie oc = dob.getCookie( OpenCookie.class );
    if( null != oc )
        return new LinkAction( dob );

    InstanceCookie.Of instCookie = dob.getCookie(InstanceCookie.Of.class);
    if( null != instCookie && instCookie.instanceOf( Action.class ) ) {
        try {
            Action res = (Action) instCookie.instanceCreate();
            if( null != res ) {
                res.putValue(Action.NAME, dob.getNodeDelegate().getDisplayName() );
            }
            return res;
        } catch( Exception e ) {
            Logger.getLogger(SampleProjectAction.class.getName()).log( Level.INFO, null, e );
        }
    }
    return null;
}
 
Example #2
Source File: SerialDataNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void init() {
    try {
        InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
        if (ic == null) {
            bean = null;
            return;
        }
        Class<?> clazz = ic.instanceClass();
        if (BeanContext.class.isAssignableFrom(clazz)) {
            bean = ic.instanceCreate();
        } else if (BeanContextProxy.class.isAssignableFrom(clazz)) {
            bean = ((BeanContextProxy) ic.instanceCreate()).getBeanContextProxy();
        } else {
            bean = null;
        }
    } catch (Exception ex) {
        bean = null;
        Exceptions.printStackTrace(ex);
    }
    if (bean != null) {
        // attaches a listener to the bean
        ((BeanContext) bean).addBeanContextMembershipListener (contextL);
    }
    updateKeys();
}
 
Example #3
Source File: FolderLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Initializes the item
 */
public void init () {
    if (ic != null) return;

    ICItem prev = DANGEROUS.get ();
    try {
        DANGEROUS.set (this);
        if (obj == null) {
            try {
                obj = DataObject.find(fo);
            } catch (DataObjectNotFoundException donfe) {
                ic = new BrokenInstance("No DataObject for " + fo.getPath(), donfe); // NOI18N
                return;
            }
        }

        ic = obj.getCookie(InstanceCookie.class);
        if (ic == null) {
            ic = new BrokenInstance("No cookie for " + fo.getPath(), null); // NOI18N
        }
    } finally {
        DANGEROUS.set (prev);
    }
}
 
Example #4
Source File: InstanceNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Children getChildren(DataObject dobj, boolean noBeanInfo) {
    if (noBeanInfo) {
        return Children.LEAF;
    }
    InstanceCookie inst = 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;
    }
}
 
Example #5
Source File: XMLPropertiesConvertorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // if Thread.sleep is commented out
public void testUpgradeSetting() throws Exception {
    String res = "Settings/org-netbeans-modules-settings-convertors-FooSettingSerialData.settings";
    FileObject fo = FileUtil.getConfigFile(res);
    assertNotNull(res, fo);
    long last = fo.lastModified().getTime();
    
    DataObject dobj = DataObject.find (fo);
    InstanceCookie.Of ic = (InstanceCookie.Of) dobj.getCookie(InstanceCookie.Of.class);
    assertNotNull (dobj + " does not contain instance cookie", ic);
    assertTrue("instanceOf failed", ic.instanceOf(FooSetting.class));
    assertEquals("instanceClass failed", FooSetting.class, ic.instanceClass());
    
    FooSetting foo = (FooSetting) ic.instanceCreate();
    assertEquals("too early upgrade", last, fo.lastModified().getTime());
    
    foo.setProperty1("A");
    Thread.sleep(3000);
    assertTrue("upgrade failed", last != fo.lastModified().getTime());
}
 
Example #6
Source File: Toolbar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 */
@Override
protected InstanceCookie acceptCookie (InstanceCookie cookie)
    throws IOException, ClassNotFoundException {
    boolean is;
    boolean action;
    
    if (cookie instanceof InstanceCookie.Of) {
        InstanceCookie.Of of = (InstanceCookie.Of)cookie;
        action = of.instanceOf (Action.class);
        is = of.instanceOf (Component.class) ||
             of.instanceOf (Presenter.Toolbar.class) ||
             action;
    } else {
        Class c = cookie.instanceClass();
        action = Action.class.isAssignableFrom (c);
        is = Component.class.isAssignableFrom(c) ||
             Presenter.Toolbar.class.isAssignableFrom(c) ||
             action;
    }
    if (action) {
        cookie.instanceCreate();
    }
    
    return is ? cookie : null;
}
 
Example #7
Source File: XMLPropertiesConvertorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // NB-Core-Build #8238
public void testUpgradeSetting2() throws Exception {
    String res = "Settings/testUpgradeSetting2/ObsoleteClass.settings";
    FileObject fo = FileUtil.getConfigFile(res);
    assertNotNull(res, fo);
    long last = fo.lastModified().getTime();
    
    DataObject dobj = DataObject.find(fo);
    InstanceCookie.Of ic = (InstanceCookie.Of) dobj.getCookie(InstanceCookie.Of.class);
    assertNotNull (dobj + " does not contain instance cookie", ic);
    assertTrue("instanceOf failed", ic.instanceOf(FooSetting.class));
    assertEquals("instanceClass failed", FooSetting.class, ic.instanceClass());
    
    FooSetting foo = (FooSetting) ic.instanceCreate();
    assertEquals("too early upgrade", last, fo.lastModified().getTime());
    
    foo.setProperty1("A");
    Thread.sleep(3000);
    assertTrue("upgrade failed", last != fo.lastModified().getTime());
}
 
Example #8
Source File: InstanceDataObjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tests instanceOf attribute.
 */
public void testInstanceOfAttribute () throws Exception {
    FileObject fo = FileUtil.createData (lfs.getRoot (), "BB/AAA/X.instance");
    fo.setAttribute ("instanceClass", "java.lang.Number");
    fo.setAttribute ("instanceCreate", new Long (1L));
    fo.setAttribute ("instanceOf", "java.lang.Object,java.lang.Long");
    
    DataObject obj = DataObject.find (fo);
    assertNotNull("Object found", obj);
    
    InstanceCookie.Of c = (InstanceCookie.Of)getCookie(obj, InstanceCookie.Of.class);
    assertNotNull ("Cookie found", c);
    
    assertTrue("Instance of object", c.instanceOf(Object.class));
    assertTrue("Not declared to be Serializable", !c.instanceOf(Serializable.class));
    assertTrue("Declared to be also Long", c.instanceOf(Long.class));
    assertTrue("Nobody knows about it being number", !c.instanceOf(Number.class));
    
    assertEquals ("Class is defined to be Number", Number.class, c.instanceClass());
    Object o = c.instanceCreate ();
    assertTrue ("It is a long", o instanceof Long);
    assertEquals ("It is 1", 1, ((Long)o).intValue());
}
 
Example #9
Source File: MenuBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
           * 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 @Override 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 action = Action.class.isAssignableFrom (c);
              if (action) {
                  cookie.instanceCreate();
              }
          	boolean is =
              	Presenter.Menu.class.isAssignableFrom (c) ||
              	JMenuItem.class.isAssignableFrom (c) ||
              	JSeparator.class.isAssignableFrom (c) ||
                  action;
          	return is ? cookie : null;
  	    }
 
Example #10
Source File: FolderLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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);
    }
}
 
Example #11
Source File: InstanceDataObjectLookupWarningTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** #28118, win sys relies that instance data object fires cookie 
 * changes when its settings file removed, it gets into corruped state otherwise. */
public void testNoWarnings() throws Exception {
    CharSequence log = Log.enable("org.openide.loaders", Level.WARNING);
    
    FileObject fo = FileUtil.createData(lfs.getRoot(), "x.instance");
    fo.setAttribute("instanceClass", "javax.swing.JButton");
    DataObject obj = DataObject.find(fo);
    assertEquals("IDO", InstanceDataObject.class, obj.getClass());
    
    InstanceCookie ic = obj.getLookup().lookup(InstanceCookie.class);
    assertNotNull("We have cookie", ic);
    
    Object o = ic.instanceCreate();
    assertNotNull("Obj created", o);
    
    assertEquals("button", JButton.class, o.getClass());
    
    if (log.length() > 0) {
        fail("No warnings, but: " + log);
    }
}
 
Example #12
Source File: InstanceNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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();
        // find the setter for the name
        try {
            nameSetter = clazz.getMethod ("setName", String.class); // NOI18N
        } catch (NoSuchMethodException e) {
            nameSetter = clazz.getMethod ("setDisplayName", String.class); // NOI18N
        }
    } catch (Exception ex) {
    }
    return nameSetter;
}
 
Example #13
Source File: GsfDataNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void loadActions(List<Action> actions, DataFolder df) throws IOException, ClassNotFoundException {
    DataObject[] dob = df.getChildren();
    int i;
    int k = dob.length;

    for (i = 0; i < k; i++) {
        InstanceCookie ic = dob[i].getCookie(InstanceCookie.class);
        if (ic == null) {
            LOG.log(Level.WARNING, "Not an action instance, or broken action: {0}", dob[i].getPrimaryFile());
            continue;
        }
        Class<?> clazz = ic.instanceClass();

        if (JSeparator.class.isAssignableFrom(clazz)) {
            actions.add(null);
        } else {
            actions.add((Action)ic.instanceCreate());
        }
    }
}
 
Example #14
Source File: ConvertAsBeanTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testReadWriteOnSubclass() throws Exception {
    HooFoo foo = new HooFoo();
    foo.setName("xxx");

    DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
    DataObject obj = InstanceDataObject.create(test, null, foo, null);
    final FileObject pf = obj.getPrimaryFile();
    final String content = pf.asText();
    if (content.indexOf("<string>xxx</string>") == -1) {
        fail(content);
    }
    obj.setValid(false);
    DataObject newObj = DataObject.find(pf);
    if (newObj == obj) {
        fail("Strange, objects shall differ");
    }
    InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
    assertNotNull("Instance cookie found", ic);

    Object read = ic.instanceCreate();
    assertNotNull("Instance created", read);
    assertEquals("Correct class", HooFoo.class, read.getClass());
    HooFoo readFoo = (HooFoo)read;
    assertEquals("property changed", "xxx", readFoo.getName());
}
 
Example #15
Source File: SerialDataNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 ();
        } else {
            return Children.LEAF;
        }
    } catch (Exception ex) {
        return Children.LEAF;
    }
}
 
Example #16
Source File: InstanceNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
    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;
        }
    }
 
Example #17
Source File: ConvertAsBeanTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testReadWrite() throws Exception {
    AnnoFoo foo = new AnnoFoo();
    foo.setName("xxx");

    DataFolder test = DataFolder.findFolder(FileUtil.getConfigRoot());
    DataObject obj = InstanceDataObject.create(test, null, foo, null);
    final FileObject pf = obj.getPrimaryFile();
    final String content = pf.asText();
    if (content.indexOf("<string>xxx</string>") == -1) {
        fail(content);
    }
    obj.setValid(false);
    DataObject newObj = DataObject.find(pf);
    if (newObj == obj) {
        fail("Strange, objects shall differ");
    }
    InstanceCookie ic = newObj.getLookup().lookup(InstanceCookie.class);
    assertNotNull("Instance cookie found", ic);

    Object read = ic.instanceCreate();
    assertNotNull("Instance created", read);
    assertEquals("Correct class", AnnoFoo.class, read.getClass());
    AnnoFoo readFoo = (AnnoFoo)read;
    assertEquals("property changed", "xxx", readFoo.getName());
}
 
Example #18
Source File: PersistenceManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void removeTopComponentForDataObject(DataObject dob) {
    //System.out.println("PM.removeTopComponentForDataObject ENTER"
    //+ " dob:" + dob.getName());
    InstanceCookie ic = dob.getCookie(InstanceCookie.class);
    //Remove corresponding tc from cache because its module was disabled
    if (ic == null) {
        synchronized(LOCK_IDS) {
            String tc_id = dataobjectToTopComponentMap.remove(dob);
            if (tc_id != null) {
                /*System.out.println("- - - - - - - - - - - - - - - - - - - - -");
                System.out.println("-- -- PM.removeTopComponentForDataObject"
                + " tc_id:" + tc_id);
                System.out.println("-- -- dob:" + dob.getClass().getName()
                + " isValid:" + dob.isValid());*/
                //Thread.dumpStack();
                Reference<TopComponent> result = id2TopComponentMap.remove(tc_id);
                if (result != null) {
                    TopComponent tc = result.get();
                    if (tc != null) {
                        topComponent2IDMap.remove(tc);
                    }
                }
            }
        }
    }
}
 
Example #19
Source File: InstanceNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Indicate whether the node may be destroyed.
 * @return tests {@link DataObject#isDeleteAllowed}
 */
@Override
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;
    }
}
 
Example #20
Source File: InstanceDataObjectModuleTest3.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testReloadChangesInstance() throws Exception {
    twiddle(m1, TWIDDLE_ENABLE);
    try {
        DataObject obj1 = findIt("Services/Misc/inst-1.instance");
        InstanceCookie inst1 = (InstanceCookie)obj1.getCookie(InstanceCookie.class);
        assertNotNull("Had an instance", inst1);
        Action a1 = (Action)inst1.instanceCreate();
        twiddle(m1, TWIDDLE_RELOAD);
        // Make sure the changes take effect?
        Thread.sleep(2000);
        DataObject obj2 = findIt("Services/Misc/inst-1.instance");
        //System.err.println("obj1 == obj2: " + (obj1 == obj2)); // OK either way
        InstanceCookie inst2 = (InstanceCookie)obj2.getCookie(InstanceCookie.class);
        assertNotNull("Had an instance", inst2);
        assertTrue("InstanceCookie changed", inst1 != inst2);
        Action a2 = (Action)inst2.instanceCreate();
        assertTrue("Action changed", a1 != a2);
        assertTrue("Correct action", "SomeAction".equals(a2.getValue(Action.NAME)));
        assertTrue("Old obj invalid or has no instance",
            !obj1.isValid() || obj1.getCookie(InstanceCookie.class) == null);
    } finally {
        twiddle(m1, TWIDDLE_DISABLE);
    }
}
 
Example #21
Source File: MainWindow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to find custom menu bar component on system file system.
 * @return menu bar component or <code>null</code> if no menu bar
 *         component is found on system file system.
 */
private static JMenuBar getCustomMenuBar() {
    try {
        String fileName = Constants.CUSTOM_MENU_BAR_PATH;
        if (fileName == null) {
            return null;
        }
        FileObject fo = FileUtil.getConfigFile(fileName);
        if (fo != null) {
            DataObject dobj = DataObject.find(fo);
            InstanceCookie ic = (InstanceCookie)dobj.getCookie(InstanceCookie.class);
            if (ic != null) {
                return (JMenuBar)ic.instanceCreate();
            }
        }
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
    }
    return null;
}
 
Example #22
Source File: AnnotationTypeActionsFolder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isAction(InstanceCookie ic) {
    if (ic instanceof InstanceCookie.Of) {
        return ((InstanceCookie.Of) ic).instanceOf(Action.class);
    } else {
        return Action.class.isAssignableFrom(ic.getClass());
    }
}
 
Example #23
Source File: FolderLookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Constructs new item. */
public ICItem (DataObject obj, String rootName, InstanceCookie ic) {
    this.ic = ic;
    this.obj = obj;
    this.rootName = rootName;
    this.fo = obj.getPrimaryFile();
    
    if (ERR.isLoggable(Level.FINE)) ERR.fine("New ICItem: " + obj); // NOI18N
}
 
Example #24
Source File: InstanceSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Find context help for some instance.
* Helper method useful in nodes or data objects that provide an instance cookie;
* they may choose to supply their own help context based on this.
* All API classes which can provide help contexts will be tested for
* (including <code>HelpCtx</code> instances themselves).
* <code>JComponent</code>s are checked for an attached help ID property,
* as with {@link HelpCtx#findHelp(java.awt.Component)} (but not traversing parents).
* <p>Also, partial compliance with the JavaHelp section on JavaBeans help is implemented--i.e.,
* if a Bean in its <code>BeanInfo</code> provides a <code>BeanDescriptor</code> which
* has the attribute <code>helpID</code>, this will be returned. The value is not
* defaulted (because it would usually be nonsense and would mask a useful default
* help for the instance container), nor is the help set specification checked,
* since someone should have installed the proper help set anyway, and the APIs
* cannot add a new reference to a help set automatically.
* See <code>javax.help.HelpUtilities.getIDStringFromBean</code> for details.
* <p>Special IDs are added, corresponding to the class name, for all standard visual components.
* @param instance the instance to check for help (it is permissible for the {@link InstanceCookie#instanceCreate} to return <code>null</code>)
* @return the help context found on the instance or inferred from a Bean,
* or <code>null</code> if none was found (or it was {@link HelpCtx#DEFAULT_HELP})
 *
 *
 * @deprecated use org.openide.util.HelpCtx.findHelp (Object)
*/
@Deprecated
public static HelpCtx findHelp (InstanceCookie instance) {
    try {
        Class<?> clazz = instance.instanceClass();
        // [a.n] I have moved the code here as those components's BeanInfo do not contain helpID
        // - it is faster
        // Help on some standard components. Note that borders/layout managers do not really work here.
        if (java.awt.Component.class.isAssignableFrom (clazz) || java.awt.MenuComponent.class.isAssignableFrom (clazz)) {
            String name = clazz.getName ();
            String[] pkgs = new String[] { "java.awt.", "javax.swing.", "javax.swing.border." }; // NOI18N
            for (int i = 0; i < pkgs.length; i++) {
                if (name.startsWith (pkgs[i]) && name.substring (pkgs[i].length ()).indexOf ('.') == -1)
                    return new HelpCtx (name);
            }
        }
        Object o = instance.instanceCreate();
        if (o != null && o != instance) {
            HelpCtx h = HelpCtx.findHelp(o);
            if (h != HelpCtx.DEFAULT_HELP) {
                return h;
            }
        }
    } catch (Exception e) {
        // #63238: Ignore - generally not important context for us to be checking errors.
    }
    return null;
}
 
Example #25
Source File: FolderInstance.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HoldInstance (DataObject source, InstanceCookie cookie) {
    this.cookie = cookie;
    this.source = source;

    if (cookie instanceof Task) {
        // for example FolderInstance ;-) attach itself for changes
        // in the cookie
        Task t = (Task)cookie;
        t.addTaskListener(WeakListeners.create(TaskListener.class, this, t));
    }
}
 
Example #26
Source File: WebBrowsersOptionsModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void findPropertyPanel() {
    
    try {
        
        InstanceCookie cookie = browserSettings.getCookie(InstanceCookie.class);
        PropertyDescriptor[] propDesc = Introspector.getBeanInfo(cookie.instanceClass()).getPropertyDescriptors();
        
        PropertyDescriptor fallbackProp = null;
        
        for (PropertyDescriptor pd : propDesc ) {
            
            if (fallbackProp == null && !pd.isExpert() && !pd.isHidden()) {
                fallbackProp = pd;
            }
            
            if (pd.isPreferred() && !pd.isExpert() && !pd.isHidden()) {
                propertyPanel = new PropertyPanel(cookie.instanceCreate(), 
                        pd.getName(), PropertyPanel.PREF_CUSTOM_EDITOR);
                propertyPanelID = "PROPERTY_PANEL_" + propertyPanelIDCounter++;
                propertyPanel.setChangeImmediate(false);
                break;
            }
            
        }
        
        if (propertyPanel == null) {
            propertyPanel = new PropertyPanel(cookie.instanceCreate(),
                    fallbackProp.getName(), PropertyPanel.PREF_CUSTOM_EDITOR);
            propertyPanelID = "PROPERTY_PANEL_" + propertyPanelIDCounter++;
        }
        
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
    
}
 
Example #27
Source File: SerialDataNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDisplayName() throws Exception {
    String res = "Settings/org-netbeans-modules-settings-convertors-testDisplayName.settings";
    FileObject fo = FileUtil.getConfigFile(res);
    assertNotNull(res, fo);
    assertNull("name", fo.getAttribute("name"));
    
    DataObject dobj = DataObject.find (fo);
    Node n = dobj.getNodeDelegate();
    assertNotNull(n);
    assertEquals("I18N", n.getDisplayName());
    
    // property sets have to be initialized otherwise the change name would be
    // propagated to the node after some delay (~2s)
    Object garbage = n.getPropertySets();
    
    InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
    assertNotNull (dobj + " does not contain instance cookie", ic);
    
    FooSetting foo = (FooSetting) ic.instanceCreate();
    String newName = "newName";
    foo.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    
    newName = "newNameViaNode";
    n.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    assertEquals(n.toString(), newName, foo.getName());
}
 
Example #28
Source File: ModuleChangeHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addTCRef (final String modeName, String tcRefName) {
    if (DEBUG) Debug.log(ModuleChangeHandler.class, "addTCRef modeName:" + modeName + " tcRefName:" + tcRefName);
    WindowManagerParser wmParser = PersistenceManager.getDefault().getWindowManagerParser();
    List<String> tcRefNameList = new ArrayList<String>(10);
    final TCRefConfig tcRefConfig = wmParser.addTCRef(modeName, tcRefName, tcRefNameList);
    try {
        //xml file system warmup to avoid blocking of EDT when deserializing the component
        if( null != tcRefConfig ) {
            DataObject dob = PersistenceManager.getDefault().findTopComponentDataObject(tcRefConfig.tc_id);
            if( null != dob ) {
                dob.getCookie(InstanceCookie.class);
            }
        }
    } catch( IOException ioE ) {
        //ignore, the exception will be reported later on anyway
        Logger.getLogger(ModuleChangeHandler.class.getName()).log(Level.FINER, null, ioE);
    }
    if (tcRefConfig != null) {
        final String [] tcRefNameArray = tcRefNameList.toArray(new String[tcRefNameList.size()]);
        // #37529 WindowsAPI to be called from AWT thread only.
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                WindowManagerImpl.getInstance().getPersistenceObserver().topComponentRefConfigAdded(modeName, tcRefConfig, tcRefNameArray);
            }
        });
    }
}
 
Example #29
Source File: ActionPasteType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isAction(DataObject dataObject) {
    boolean retVal = false;
    InstanceCookie.Of ic = (InstanceCookie.Of)dataObject.getCookie(InstanceCookie.Of.class);            
    if (ic != null && ic.instanceOf(Action.class)) {
        retVal = true;    
    }
    return retVal;
}
 
Example #30
Source File: InstanceDataObjectRefreshesOnFileChangeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSwitchRefreshesIDO() throws Exception {
    FileObject fo = FileUtil.getConfigFile("Folder/MyInstance.instance");
    assertNotNull("File visible in SFS", fo);
    DataObject ido = DataObject.find(fo);
    Lookup lkp = ido.getLookup();
    Result<InstanceCookie> res = lkp.lookupResult(InstanceCookie.class);
    assertEquals("One cookie", 1, res.allItems().size());
    res.addLookupListener(this);
    ido.addPropertyChangeListener(this);

    assertInstance(lkp, "OldOne");

    assertEquals("no lookup change yet", 0, cnt);
    assertEquals("no pcl change yet", 0, pcl);

    DynamicFS dfs = Lookup.getDefault().lookup(DynamicFS.class);
    dfs.setDelegate(mem2);

    assertEquals("one pcl change now", 1, pcl);
    if (cnt == 0) {
        fail("At least one change in lookup shall be notified");
    }

    FileObject fo2 = FileUtil.getConfigFile("Folder/MyInstance.instance");
    assertNotNull("File is still visible in SFS", fo);
    DataObject ido2 = DataObject.find(fo2);

    assertSame("Data object remains", ido, ido2);

    assertInstance(lkp, "NewOne");
}