org.openide.text.DataEditorSupport Java Examples

The following examples show how to use org.openide.text.DataEditorSupport. 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: GsfDataObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public GsfDataObject(FileObject pf, MultiFileLoader loader, Language language) throws DataObjectExistsException {
    super(pf, loader);

    // If the user creates a file with a filename where we can't figure out the language
    // (e.g. the PHP New File wizard doesn't enforce a file extension, so if you create
    // a file named "pie.class" (issue 124044) the data loader doesn't know which language
    // to associate this with since it isn't a GSF file extension or mimetype). However
    // during template creation we know the language anyway so we can use it. On subsequent
    // IDE restarts the file won't be recognized so the user will have to rename or
    // add a new file extension to file type mapping.
    if (language == null) {
        language = templateLanguage;
    }
    this.language = language;
    getCookieSet().add(new Class[]{
            GenericEditorSupport.class, // NOI18N
            SaveAsCapable.class, Openable.class, EditorCookie.Observable.class, 
            PrintCookie.class, CloseCookie.class, Editable.class, LineCookie.class,
            DataEditorSupport.class, CloneableEditorSupport.class,
            CloneableOpenSupport.class
        }, new EditorSupportFactory());
}
 
Example #2
Source File: GsfDataObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends Cookie> T createCookie(Class<T> klass) {
        if (
        klass.isAssignableFrom(DataEditorSupport.class) || 
        DataEditorSupport.class.isAssignableFrom(klass) || 
        klass.isAssignableFrom(Openable.class) || 
        klass.isAssignableFrom(Editable.class) || 
        klass.isAssignableFrom(EditorCookie.Observable.class) || 
        klass.isAssignableFrom(PrintCookie.class) || 
        klass.isAssignableFrom(CloseCookie.class) || 
        klass.isAssignableFrom(LineCookie.class)
    ) {
        return klass.cast(createEditorSupport());
    }
    return null;
}
 
Example #3
Source File: XmlMultiViewEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the display name of the associated top component.
 */
public void updateDisplayName() {
    if (mvtc != null) {
        Utils.runInAwtDispatchThread(new Runnable() {
            public void run() {
                String displayName = messageName();
                if (!displayName.equals(mvtc.getDisplayName())) {
                    mvtc.setDisplayName(displayName);
                }
                String htmlDisplayName = messageHtmlName();
                if (!Utilities.compareObjects(htmlDisplayName, mvtc.getHtmlDisplayName())) {
                    mvtc.setHtmlDisplayName(htmlDisplayName);
                }
                mvtc.setToolTipText(DataEditorSupport.toolTip(
                        dObj.getPrimaryFile(), getDataObject().isModified(), !getDataObject().getPrimaryFile().canWrite()));
            }
        });
    }
}
 
Example #4
Source File: BIEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit)
        throws IOException, BadLocationException {
    
    if (guardedEditor == null) {
        guardedEditor = new BIGES();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find(((DataEditorSupport.Env) env).getMimeType());
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }
    
    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
Example #5
Source File: GlslGeometryShaderDataObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public GlslGeometryShaderDataObject(FileObject pf, GlslGeometryShaderDataLoader loader) throws DataObjectExistsException, IOException {

        super(pf, loader);

        CookieSet cookies = getCookieSet();
        observer = new GlslShaderFileObserver(this);

        final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
        support.addPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if ("document".equals(event.getPropertyName())) {
                    if (event.getNewValue() != null) {
                        support.getDocument().addDocumentListener(observer);
                        observer.runCompileTask();
                    } else if (event.getOldValue() != null) {
                        // cylab: I think this is never called.
                        // But I don't know if unregistering the observer makes any difference...
                        ((Document) event.getOldValue()).removeDocumentListener(observer);
                    }
                }
            }
        });
        cookies.add((Node.Cookie) support);
    }
 
Example #6
Source File: PropertiesOpen.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a HTML display name for this component.
 *
 * @return  the created display name
 * @see  #displayName()
 */
private String htmlDisplayName() {
    if (bundleStructure.getNthEntry(0)==null) {
        bundleStructure.updateEntries();
    }
    final Node node = bundleStructure.getNthEntry(0).getDataObject().getNodeDelegate();
    String displayName = node.getHtmlDisplayName();
    if (displayName != null) {
        if (!displayName.startsWith("<html>")) {                //NOI18N
            displayName = "<html>" + displayName;               //NOI18N
        }
    } else {
        displayName = node.getDisplayName();
    }
    return DataEditorSupport.annotateName(displayName, true, isModified(), false);
}
 
Example #7
Source File: ToolTipAnnotation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getShortDescription () {
    DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager ().
        getCurrentEngine ();
    if (currentEngine == null) return null;
    AntDebugger d = currentEngine.lookupFirst(null, AntDebugger.class);
    if (d == null) return null;

    Part lp = (Part)
        getAttachedAnnotatable();
    if (lp == null) return null;
    Line line = lp.getLine ();
    DataObject dob = DataEditorSupport.findDataObject (line);
    if (dob == null) return null;
    EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);

    if (ec == null) return null;
    this.lp = lp;
    this.ec = ec;
    RequestProcessor.getDefault ().post (this);
    return null;
}
 
Example #8
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find(((DataEditorSupport.Env) env).getMimeType());
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }
    
    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
 
Example #9
Source File: NavigatorContent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if(evt.getPropertyName() == EditorCookie.Observable.PROP_DOCUMENT) {
        if(evt.getNewValue() == null) {
            final DataObject dobj = ((DataEditorSupport)evt.getSource()).getDataObject();
            if(dobj != null) {
                //document is being closed
                if(DEBUG) System.out.println("document has been closed for DO: " + dobj.hashCode());
                
                //remove the property change listener from the DataObject's EditorSupport
                attachDataObject(null);
                //and navigate the document again (must be called asynchronously
                //otherwise the ClonableEditorSupport locks itself (new call to CES from CES.propertyChange))
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        if(dobj.isValid()) navigate(dobj);
                    }
                });
            }
        }
    }
    if (EditorRegistry.FOCUS_GAINED_PROPERTY.equals(evt.getPropertyName())) {
        SwingUtilities.invokeLater(this);
    }
}
 
Example #10
Source File: ToolTipAnnotation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void evaluate(Line.Part part) {
    Line line = part.getLine();
    if (line == null) {
        return;
    }
    DataObject dataObject = DataEditorSupport.findDataObject(line);
    if (!isPhpDataObject(dataObject)) {
        return;
    }
    EditorCookie editorCookie = (EditorCookie) dataObject.getLookup().lookup(EditorCookie.class);
    StyledDocument document = editorCookie.getDocument();
    if (document == null) {
        return;
    }
    final int offset = NbDocument.findLineOffset(document, part.getLine().getLineNumber()) + part.getColumn();
    JEditorPane ep = EditorContextDispatcher.getDefault().getCurrentEditor();
    String selectedText = getSelectedText(ep, offset);
    if (selectedText != null) {
        if (isPHPIdentifier(selectedText)) {
            sendPropertyGetCommand(selectedText);
        } else if (PhpOptions.getInstance().isDebuggerWatchesAndEval()) {
            sendEvalCommand(selectedText);
        }
    } else {
        final String identifier = ep != null ? getIdentifier(document, ep, offset) : null;
        if (identifier != null) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    sendPropertyGetCommand(identifier);
                }
            };
            RP.post(runnable);
        }
    }
    //TODO: review, replace the code depending on lexer.model - part I
}
 
Example #11
Source File: PropertiesOpen.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a display name for this component.
 *
 * @return  the created display name
 * @see  #htmlDisplayName
 */
private String displayName() {
    //PENDING change to avoid call getNthEntry, in some cases it will throw an exception
    if (bundleStructure.getNthEntry(0)==null) {
        bundleStructure.updateEntries();
    }
    String nameBase = bundleStructure.getNthEntry(0).getDataObject().getNodeDelegate().getDisplayName();
    return DataEditorSupport.annotateName(nameBase, false, isModified(), false);
}
 
Example #12
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 
 * Overrides superclass abstract method. 
 * Constructs message that should be used to name the editor component.
 * @return name of the editor
 */
protected String messageName () {
    if (!myEntry.getDataObject().isValid()) {
        return "";                                                  //NOI18N       
    }
    return DataEditorSupport.annotateName(getFileLabel(), false, isModified(), !myEntry.getFile().canWrite());
}
 
Example #13
Source File: DefaultDataObjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
    MultiDataObject obj = new MultiDataObject(primaryFile, this);
    cnt++;
    obj.getCookieSet().assign(EditorCookie.class, DataEditorSupport.create(obj, obj.getPrimaryEntry(), obj.getCookieSet()));

    if (nodeListener != null) {
        nodeListener.nodeDestroyed(null);
    }
    
    return obj;
}
 
Example #14
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** */
@Override
protected String messageHtmlName () {
    if (!myEntry.getDataObject().isValid()) {
        return null;
    }

    String rawName = getFileLabel();
    
    String annotatedName = null;
    final FileObject entry = myEntry.getFile();
    try {
        StatusDecorator status = entry.getFileSystem().getDecorator();
        if (status != null) {
            Set<FileObject> files = Collections.singleton(entry);
            annotatedName = status.annotateNameHtml(rawName, files);
            if (rawName.equals(annotatedName)) {
                annotatedName = null;
            }
            if ((annotatedName != null)
                    && (!annotatedName.startsWith("<html>"))) { //NOI18N
                annotatedName = "<html>" + annotatedName;       //NOI18N
            }
            if (annotatedName == null) {
                annotatedName = status.annotateName(rawName, files);
            }
        }
    } catch (FileStateInvalidException ex) {
        //do nothing and fall through
    }
    
    String name = (annotatedName != null) ? annotatedName : /*XXX escape HTML content*/rawName;
    return DataEditorSupport.annotateName(name, true, isModified(), !myEntry.getFile().canWrite());
}
 
Example #15
Source File: MultiDOEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Cookie> T createCookie(Class<T> klass) {
    if (klass.isAssignableFrom(SimpleES.class)) {
        synchronized (this) {
            if (support == null) {
                support = DataEditorSupport.create(
                    outer, outer.getPrimaryEntry(),
                    outer.getCookieSet(), useMultiview ? this : null
                );
            }
        }
        return klass.cast(support);
    }
    return null;
}
 
Example #16
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns display name of the multiview top component.
 * The first item of the array is normal display name,
 * the second item of the array is HTML display name.
 *
 * @param formDataObject form data object representing the multiview tc.
 * @return display names of the MVTC. The second item can be <code>null</code>.
 */
private static String[] getMVTCDisplayName(FormDataObject formDataObject) {
    Node node = formDataObject.getNodeDelegate();
    String title = node.getDisplayName();
    String htmlTitle = node.getHtmlDisplayName();
    if (htmlTitle == null) {
        try {
            htmlTitle = XMLUtil.toElementContent(title);
        } catch (CharConversionException x) {
            htmlTitle = "???";
        }
    }
    FormEditorSupport fes = (FormEditorSupport)formDataObject.getFormEditorSupport();
    if (fes != null) {
        FormDesignerTC designerTC = fes.getFormDesignerTC();
        if (designerTC != null && designerTC.isShowing()) {
            FormModel fm = fes.getFormModel();
            if (fm != null) {
                FormDesigner fd = FormEditor.getFormDesigner(fes.getFormModel());
                if (fd != null && fd.getFormModel() != null
                        && !fd.isTopRADComponent() && fd.getTopDesignComponent() != null) {
                    title = FormUtils.getFormattedBundleString(
                            "FMT_FormTitleWithContainerName", // NOI18N
                            new Object[] {title, fd.getTopDesignComponent().getName()});
                    htmlTitle = FormUtils.getFormattedBundleString(
                            "FMT_FormTitleWithContainerName", // NOI18N
                            new Object[] {htmlTitle, fd.getTopDesignComponent().getName()});
                }
            }
        }
    }
    boolean modified = formDataObject.isModified();
    boolean readOnly = readOnly(formDataObject);
    return new String[] {
        DataEditorSupport.annotateName(title, false, modified, readOnly),
        DataEditorSupport.annotateName(htmlTitle, true, modified, readOnly)
    };
}
 
Example #17
Source File: ToolTipAnnotation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getShortDescription () {
    Session session = DebuggerManager.getDebuggerManager ().getCurrentSession();
    if (session == null) {
        return null;
    }
    DebuggerEngine engine = session.getCurrentEngine();
    if (engine != session.getEngineForLanguage(TruffleStrataProvider.TRUFFLE_STRATUM)) {
        return null;
    }
    JPDADebugger d = engine.lookupFirst(null, JPDADebugger.class);
    if (d == null) {
        return null;
    }

    Line.Part lp = (Line.Part) getAttachedAnnotatable();
    if (lp == null) {
        return null;
    }
    Line line = lp.getLine ();
    DataObject dob = DataEditorSupport.findDataObject (line);
    if (dob == null) {
        return null;
    }
    EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);
    if (ec == null) {
        return null;
        // Only for editable dataobjects
    }

    this.lp = lp;
    this.ec = ec;
    RP.post(this);
    return null;
}
 
Example #18
Source File: GlslVertexShaderDataObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GlslVertexShaderDataObject(FileObject pf, GlslVertexShaderDataLoader loader) throws DataObjectExistsException, IOException {
    
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    observer= new GlslShaderFileObserver(this);
    
    final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies);
    support.addPropertyChangeListener(
        new PropertyChangeListener(){
            public void propertyChange(PropertyChangeEvent event) {
                if("document".equals(event.getPropertyName())){
                    if(event.getNewValue()!=null)
                    {
                        support.getDocument().addDocumentListener(observer);
                        observer.runCompileTask();
                    }
                    else if(event.getOldValue()!=null)
                    {
                        // cylab: I think this is never called.
                        // But I don't know if unregistering the observer makes any difference...
                        ((Document)event.getOldValue()).removeDocumentListener(observer);
                    }
                }
            }
        }
    );
    cookies.add((Node.Cookie) support);
}
 
Example #19
Source File: LineTranslations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void destroy() {
    detach();
    DataEditorSupport des = dataObject.getLookup().lookup(DataEditorSupport.class);
    if (des != null) {
        des.removePropertyChangeListener(this);
    }
}
 
Example #20
Source File: LineTranslations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BreakpointLineUpdater(LineBreakpoint lb, DataObject dataObject) {
    this.lb = lb;
    this.dataObject = dataObject;
    lineChangePostProcess.setRepeats(false);
    DataEditorSupport des = dataObject.getLookup().lookup(DataEditorSupport.class);
    if (des != null) {
        des.addPropertyChangeListener(this);
    }
}
 
Example #21
Source File: GlslFragmentShaderDataObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GlslFragmentShaderDataObject(FileObject pf, GlslFragmentShaderDataLoader loader) throws DataObjectExistsException, IOException {
    
    super(pf, loader);
    
    CookieSet cookies = getCookieSet();
    observer= new GlslShaderFileObserver(this);
    
    final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies);
    support.addPropertyChangeListener(
        new PropertyChangeListener(){
            public void propertyChange(PropertyChangeEvent event) {
                if("document".equals(event.getPropertyName())){
                    if(event.getNewValue()!=null)
                    {
                        support.getDocument().addDocumentListener(observer);
                        observer.runCompileTask();
                    }
                    else if(event.getOldValue()!=null)
                    {
                        // cylab: I think this is never called.
                        // But I don't know if unregistering the observer makes any difference...
                        ((Document)event.getOldValue()).removeDocumentListener(observer);
                    }
                }
            }
        }
    );
    cookies.add((Node.Cookie) support);
}
 
Example #22
Source File: AbstractJSToolTipAnnotation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String getShortDescription () {
    final Session session = DebuggerManager.getDebuggerManager ().getCurrentSession();
    if (session == null) {
        return null;
    }
    final DebuggerEngine engine = session.getCurrentEngine();
    if (engine == null) {
        return null;
    }

    final Line.Part lp = (Line.Part) getAttachedAnnotatable();
    if (lp == null) {
        return null;
    }
    Line line = lp.getLine ();
    DataObject dob = DataEditorSupport.findDataObject (line);
    if (dob == null) {
        return null;
    }
    final EditorCookie ec = dob.getLookup().lookup(EditorCookie.class);
    if (ec == null) {
        return null;
        // Only for editable dataobjects
    }

    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            evaluate(session, engine/*, dbg*/, lp, ec);
        }
    };
    RequestProcessor rp = engine.lookupFirst(null, RequestProcessor.class);
    if (rp == null) {
        // Debugger is likely finishing...
        rp = RP;
    }
    rp.post(runnable);
    return null;
}
 
Example #23
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 
 * Overrides superclass abstract method.
 * Text to use as tooltip for component.
 * @return text to show to the user
 */
protected String messageToolTip () {
    // copied from DataEditorSupport, more or less
    FileObject fo = myEntry.getFile();
    return DataEditorSupport.toolTip(fo, isModified(), !myEntry.getFile().canWrite());
}
 
Example #24
Source File: OgreMaterialDataObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public OgreMaterialDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
Example #25
Source File: PropertiesOpen.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Gets string for tooltip. */
private String messageToolTip() {
    FileObject fo = bundleStructure.getNthEntry(0).getFile();
    return DataEditorSupport.toolTip(fo, isModified(), false);
}
 
Example #26
Source File: JMEMaterialDefinitionDataObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JMEMaterialDefinitionDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
Example #27
Source File: DiffDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DiffDataObject (FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super (pf, loader);
    CookieSet cookies = getCookieSet ();
    cookies.add ((Node.Cookie) DataEditorSupport.create (this, getPrimaryEntry (), cookies));
}
 
Example #28
Source File: LanguagesDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public LanguagesDataObject(FileObject pf, LanguagesDataLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
Example #29
Source File: PreviewMultiViewElement.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public PreviewMultiViewElement(DataEditorSupport des) {
    super(des);
    this.des = des;
    this.dataObject = this.des.getDataObject();
    initialize();
}
 
Example #30
Source File: FileObjectInLookupTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public OwnDataObject(FileObject pf, OwnDataLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}