Skip to content
This repository was archived by the owner on Apr 10, 2021. It is now read-only.

Plugin Development

Benny Neugebauer edited this page Feb 6, 2015 · 2 revisions

Where does NetBeans install itself?

C:\Program Files\glassfish-4.1
C:\Program Files\NetBeans 8.0.1
C:\Users\Benny\.nbi
C:\Users\Benny\.netbeans-derby
C:\Users\Benny\AppData\Roaming\NetBeans

Read file attributes

import org.openide.filesystems.FileObject;

...

FileObject fo ...
Object value = fo.getAttribute("myKey");

if (value != null) {
  ...
}

Handle file locks

  DataObject dataObject = ...;
  FileObject fo = dataObject.getPrimaryFile();

  FileLock lock = FileLock.NONE;

  try {
    if (!fo.isLocked()) {
      BufferedOutputStream os = new BufferedOutputStream(fo.getOutputStream(lock));
      os.write("Hello World".getBytes("ASCII"));
      os.flush();
      os.close();
    }
  } catch (IOException ex) {
    Exceptions.printStackTrace(ex);
    return false;
  } finally {
    lock.releaseLock();
  }

Reformat code

Reformat reformat = Reformat.get(document);
reformat.lock();
reformat.reformat(0, document.getLength());
reformat.unlock();

Change preferences in Editor

Preferences codeStyle = CodeStylePreferences.get(file, file.getMIMEType()).getPreferences();
codeStyle.putInt(SimpleValueNames.INDENT_SHIFT_WIDTH, 2);
codeStyle.flush();

Clone this wiki locally