Java Code Examples for org.openide.loaders.DataObject#addPropertyChangeListener()

The following examples show how to use org.openide.loaders.DataObject#addPropertyChangeListener() . 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: FileMoveBreakpointsHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
    Object source = e.getSource();
    if (source instanceof Collection) {
        FileObject bfo = this.fo;
        if (bfo == null) {
            return ;
        }
        for (Object obj : ((Collection) source)) {
            DataObject dobj = (DataObject) obj;
            FileObject primary = dobj.getPrimaryFile();
            if (bfo.equals(primary)) {
                synchronized (this) {
                    dobjRef = new WeakReference<DataObject>(dobj);
                    dobjwl = WeakListeners.propertyChange(this, dobj);
                    dobj.addPropertyChangeListener(dobjwl);
                    if (registryListener != null) {
                        DataObject.getRegistry().removeChangeListener(registryListener);
                        registryListener = null;
                    }
                }
                break;
            }
        }
    }
}
 
Example 2
Source File: WarDeploymentConfiguration.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of WarDeploymentConfiguration 
 */
public WarDeploymentConfiguration(J2eeModule j2eeModule, Version serverVersion) {

    super(j2eeModule, serverVersion);
    this.j2eeModule = j2eeModule;
    this.serverVersion = serverVersion;
    file = j2eeModule.getDeploymentConfigurationFile("WEB-INF/weblogic.xml"); // NOI18N
    FileUtil.addFileChangeListener(weblogicXmlListener, file);

    getWeblogicWebApp();
    DataObject dataObject = null;
    try {
        dataObject = DataObject.find(FileUtil.toFileObject(file));
        dataObject.addPropertyChangeListener(this);
    } catch(DataObjectNotFoundException donfe) {
        Exceptions.printStackTrace(donfe);
    }
    this.dataObject = dataObject;
}
 
Example 3
Source File: EjbDeploymentConfiguration.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of EjbDeploymentConfiguration 
 */
public EjbDeploymentConfiguration(J2eeModule j2eeModule, Version serverVersion) {

    super(j2eeModule, serverVersion);
    this.j2eeModule = j2eeModule;
    this.serverVersion = serverVersion;
    file = j2eeModule.getDeploymentConfigurationFile("META-INF/weblogic-ejb-jar.xml"); // NOI18N
    getWeblogicEjbJar();
    DataObject dataObject = null;
    try {
        dataObject = DataObject.find(FileUtil.toFileObject(file));
        dataObject.addPropertyChangeListener(this);
    } catch(DataObjectNotFoundException donfe) {
        Exceptions.printStackTrace(donfe);
    }
    this.dataObject = dataObject;
}
 
Example 4
Source File: GsfDataObjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSetModifiedNestedChange() throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject f = fs.getRoot().createData("index.test");
    DataObject dob = DataObject.find(f);
    assertEquals("The right object", GsfDataObject.class, dob.getClass());
    dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
            "modified", null);
    assertTrue("Should be modified.", dob.isModified());
    dob.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String s = evt.getPropertyName();
            if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
                dob.setModified(true);
            }
        }
    });
    dob.setModified(false);
    assertTrue("Should be still modified.", dob.isModified());
    assertNotNull("Still should have save cookie.",
            dob.getLookup().lookup(SaveCookie.class));
}
 
Example 5
Source File: HtmlDataObjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSetModifiedNestedChange() throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject f = fs.getRoot().createData("modify.html");
    final DataObject dob = DataObject.find(f);
    assertEquals("The right object", HtmlDataObject.class, dob.getClass());
    dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
            "modified", null);
    assertTrue("Should be modified.", dob.isModified());
    dob.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String s = evt.getPropertyName();
            if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
                dob.setModified(true);
            }
        }
    });
    dob.setModified(false);
    assertTrue("Should be still modified.", dob.isModified());
    assertNotNull("Still should have save cookie.",
            dob.getLookup().lookup(SaveCookie.class));
}
 
Example 6
Source File: ResourceExplorerTopComponent.java    From syncope with Apache License 2.0 6 votes vote down vote up
private void openScriptEditor(final String name, final String type) throws IOException {
    ImplementationTO node = implementationManagerService.read(type, name);
    String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + node.getType() + '/';
    File groovyScriptsDir = new File(groovyScriptsDirName);
    if (!groovyScriptsDir.exists()) {
        groovyScriptsDir.mkdirs();
    }
    File file = new File(groovyScriptsDirName + name + ".groovy");
    FileWriter fw = new FileWriter(file, StandardCharsets.UTF_8);
    fw.write(node.getBody());
    fw.flush();
    FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile());
    DataObject data = DataObject.find(fob);
    data.getLookup().lookup(OpenCookie.class).open();
    data.addPropertyChangeListener(event -> {
        if (DataObject.PROP_MODIFIED.equals(event.getPropertyName())) {
            //save item remotely
            LOG.info(String.format("Saving Groovy template [%s]", name));
            saveContent();
        }
    });
}
 
Example 7
Source File: TreeRootNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override protected boolean createKeys(List<DataObject> keys) {
    List<DataObject> files = new ArrayList<DataObject>();
    for (DataObject f : folder.getChildren()) {
        if (!filter.acceptDataObject(f)) {
            continue;
        }
        if (f instanceof DataFolder) {
            while (true) {
                DataObject candidate = null;
                f.addPropertyChangeListener(WeakListeners.propertyChange(this, f));
                for (DataObject kid : ((DataFolder) f).getChildren()) {
                    if (!filter.acceptDataObject(kid)) {
                        continue;
                    }
                    if (kid instanceof DataFolder) {
                        if (candidate == null) {
                            candidate = kid;
                        } else {
                            candidate = null;
                            break;
                        }
                    } else {
                        candidate = null;
                        break;
                    }
                }
                if (candidate != null) {
                    f = candidate;
                } else {
                    break;
                }
            }
            keys.add(f);
        } else {
            files.add(f);
        }
    }
    keys.addAll(files);
    return true;
}
 
Example 8
Source File: JPQLEditorTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void fillPersistenceConfigurations(Node[] activatedNodes) {
    Node node = activatedNodes[0];
    DataObject dO = node.getLookup().lookup(DataObject.class);
    puObject = null;
    if (dO instanceof PUDataObject) {
        puObject = (PUDataObject) dO;
        dO.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (DataObject.PROP_VALID.equals(evt.getPropertyName()) && Boolean.FALSE.equals(evt.getNewValue())) {
                    if (SwingUtilities.isEventDispatchThread()) {
                        close();//need to close if corresponding dataobject was invalidated (deleted)
                    } else {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                close();//need to close if corresponding dataobject was invalidated (deleted)
                            }
                        });
                    }
                }
            }
        });

        Persistence persistence = puObject.getPersistence();
        if (persistence == null) {
            logger.warning("corrupted persistence.xml in enclosing project.");
        } else if (persistence.getPersistenceUnit().length > 0) {
            for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
                String configName = unit.getName(); //NOI18N
                puConfigMap.put(configName, unit);
            }
            puComboBox.setModel(new DefaultComboBoxModel(puConfigMap.keySet().toArray()));
            puComboBox.setSelectedIndex(0);
        }
    } else {
        //TODO Don't know whether this case will actually arise..
    }

}
 
Example 9
Source File: JavaNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Create a node for the Java data object using the default children.
* @param jdo the data object to represent
*/
public JavaNode (final DataObject jdo, boolean isJavaSource) {
    super (jdo, Children.LEAF);
    this.isJavaSource = isJavaSource;
    this.isCompiled = new AtomicReference<>();
    this.isExecutable = new AtomicReference<>();
    this.computedIcon = new AtomicReference<>();
    this.computedIconListener = new AtomicReference<>();
    this.setIconBaseWithExtension(isJavaSource ? JAVA_ICON_BASE : CLASS_ICON_BASE);
    Logger.getLogger("TIMER").log(Level.FINE, "JavaNode", new Object[] {jdo.getPrimaryFile(), this});
    if (!jdo.isTemplate()) {
        WORKER.post(IconTask.create(this));
        if (isJavaSource) {
            WORKER.post(new BuildStatusTask(this));
            WORKER.post(new ExecutableTask(this));
            jdo.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (DataObject.PROP_PRIMARY_FILE.equals(evt.getPropertyName())) {
                        Logger.getLogger("TIMER").log(Level.FINE, "JavaNode", new Object[]{jdo.getPrimaryFile(), this});
                        WORKER.post(new Runnable() {
                            public void run() {
                                computedIconListener.set(null);
                                synchronized (JavaNode.this) {
                                    status = null;
                                    executableListener = null;
                                    WORKER.post(new BuildStatusTask(JavaNode.this));
                                    WORKER.post(new ExecutableTask(JavaNode.this));
                                }
                            }
                        });
                    }
                }
            });
        }
    }
}
 
Example 10
Source File: DataEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private DOEnvLookup (DataObject dobj, InstanceContent ic) {
    super (ic);
    this.ic = ic;
    this.dobj = dobj;
	dobj.addPropertyChangeListener(WeakListeners.propertyChange(this, dobj));
     
    updateLookup ();
}
 
Example 11
Source File: LayerHints.java    From netbeans with Apache License 2.0 5 votes vote down vote up
Prov(Document doc, DataObject xml, LayerHandle handle) {
    this.doc = doc;
    this.xml = xml;
    this.handle = handle;
    xml.getPrimaryFile().addFileChangeListener(FileUtil.weakFileChangeListener(listener, xml.getPrimaryFile()));
    xml.addPropertyChangeListener(WeakListeners.propertyChange(pcl, xml));
    task = RP.post(this);
}
 
Example 12
Source File: IDEServicesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DataObjectSource(DataObject data) {
    this.data = data;
    support = new PropertyChangeSupport(this);
    propertyChangeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if(DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                support.firePropertyChange(PROP_MODIFIED, evt.getOldValue(), evt.getNewValue());
            }
        }
    };
    data.addPropertyChangeListener(WeakListeners.propertyChange(propertyChangeListener, this.data));
}
 
Example 13
Source File: PropertiesDataNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates data node for a given data object.
 * The provided children object will be used to hold all child nodes.
 * @param dataObject  object to work with
 * @param children container for the node
 */
public PropertiesDataNode(DataObject dataObject, Children children, Lookup lookup) {
    super(dataObject, children, lookup);
    setIconBaseWithExtension("org/netbeans/modules/properties/propertiesObject.png"); // NOI18N
    dataObjectListener = new NameUpdater();
    dataObject.addPropertyChangeListener(
            WeakListeners.propertyChange(dataObjectListener, dataObject));
}