Open recent files in NBP. Why 2 times messages ?

"jacobKM1" <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
Dear List

Following to Geert-Jan, I did some coding relate to Opening recent *txt files in NB Platform, as followed by:
http://wiki.netbeans.org/DevFaqListenForOpenEvents [Or see the last part].

It works, but , when I used a System.out.println("Opened " + fe.getFile()... to show the details of the process,
I understood that, it works for two time!

Similarly, when I opened a non *txt file like *jpg it also shows ERROR messages (JOptionPane.showMessageDialog(null, "Unsupported format: Please . . .) for two times!!

Hope someone can answer this behaviour.

Thanks in advance

K


//==== The installer class & its use in MainTopComponent.... ======

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.myorg.googletoolbar;

/**
 *
 * @author user
 */
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
import javax.swing.JOptionPane;
import org.openide.awt.StatusDisplayer;
import org.openide.filesystems.FileChangeAdapter;
import org.openide.filesystems.FileEvent;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.windows.OnShowing;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

@OnShowing
public class Installer implements Runnable {
    @Override
    public void run() {
WindowManager.getDefault().getRegistry().addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("opened")) {
                    HashSet<TopComponent> newHashSet = (HashSet<TopComponent>) evt.getNewValue();
                    HashSet<TopComponent> oldHashSet = (HashSet<TopComponent>) evt.getOldValue();
                    for (TopComponent topComponent : newHashSet) {
                        if (!oldHashSet.contains(topComponent)) {
                            DataObject dObj = topComponent.getLookup().lookup(DataObject.class);
                            if (dObj != null) {
                                FileObject currentFile = dObj.getPrimaryFile();
                                if (currentFile != null && currentFile.getNameExt().endsWith(".xyz") /*&& currentFile.getMIMEType().equals("text/x-java")*/ ) {
StatusDisplayer.getDefault().setStatusText("Hurray 111! " + "Opened " + currentFile.getPath().toString(), 1);
System.out.println("Opened " + currentFile.getNameExt());

 //if(currentFile.getNameExt().endsWith(".xyz") || currentFile.getNameExt().endsWith(".gen"))
 //   { JOptionPane.showMessageDialog(null, "Unsupported format: Please use *.xyz , *.gen , or dftb_in.hsd", "Error", JOptionPane.ERROR_MESSAGE);}

currentFile.addFileChangeListener(new FileChangeAdapter() {
                                        @Override
                                        public void fileChanged(FileEvent fe) {
StatusDisplayer.getDefault().setStatusText("Hurray! 222 " + "Saved " + fe.getFile().getNameExt(), 1);
System.out.println("Opened " + fe.getFile().getNameExt());
                                        }
                                    });
                                } else { JOptionPane.showMessageDialog(null, "Unsupported format: Please use *.xyz , *.gen , or dftb_in.hsd", "Error", JOptionPane.ERROR_MESSAGE);}

                            }
                        }
                    }
                }
            }
        });
    }

} 
====================  in the <TopComponent.Java>  =======

...

// get open file info
        Installer pp = new Installer();
        pp.run();
...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.