Java源码示例:org.openide.text.DataEditorSupport

示例1
@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);
    }
}
 
示例2
@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;
}
 
示例3
@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);
    }
}
 
示例4
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());
}
 
示例5
@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;
}
 
示例6
/**
 * 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()));
            }
        });
    }
}
 
示例7
/**
 * 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);
}
 
示例8
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);
    }
}
 
示例9
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);
    }
 
示例10
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);
    }
}
 
示例11
public void destroy() {
    detach();
    DataEditorSupport des = dataObject.getLookup().lookup(DataEditorSupport.class);
    if (des != null) {
        des.removePropertyChangeListener(this);
    }
}
 
示例12
@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;
}
 
示例13
/**
 * 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)
    };
}
 
示例14
@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;
}
 
示例15
@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;
}
 
示例16
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
}
 
示例17
/**
 * 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);
}
 
示例18
/** 
 * 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());
}
 
示例19
/** */
@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());
}
 
示例20
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);
}
 
示例21
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);
}
 
示例22
public HintDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
示例23
public DeclarativeHintsTestDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
示例24
@Override
public String getShortDescription () {
    // [TODO] hack for org.netbeans.modules.debugger.jpda.actions.MethodChooser that disables tooltips
    if ("true".equals(System.getProperty("org.netbeans.modules.debugger.jpda.doNotShowTooltips"))) { // NOI18N
        return null;
    }
    DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager ().
        getCurrentEngine ();
    if (currentEngine == null) {
        return null;
    }
    JPDADebugger d = currentEngine.lookupFirst(null, JPDADebugger.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;
        // Only for editable dataobjects
    }

    this.lp = lp;
    this.ec = ec;
    RequestProcessor rp = currentEngine.lookupFirst(null, RequestProcessor.class);
    if (rp == null) {
        // Debugger is likely finishing...
        rp = RequestProcessor.getDefault();
    }
    rp.post (this);
    return null;
}
 
示例25
public JavaElement(Lookup context) {
    super(context.lookup(DataEditorSupport.class));
    DataObject dataObject = context.lookup(DataObject.class);
    setActivatedNodes(new Node[]{dataObject.getNodeDelegate()});
}
 
示例26
public void save() throws java.io.IOException {
    DataObject dobj = getDataObject();
    ((DataEditorSupport) findCloneableOpenSupport()).saveDocument();
    dobj.setModified(false);
}
 
示例27
private static String getMVTCToolTipText(FormDataObject formDataObject) {
    return DataEditorSupport.toolTip(formDataObject.getPrimaryFile(), formDataObject.isModified(), readOnly(formDataObject));
}
 
示例28
private void registerEditor() {
    // register provided cookies
    // EditorCookie must be for back compatability consulted with subclasses
    //
    // In new model subclasses should directly provide its CookieSet.Factory that
    // uses last prevails order instead of old CookieSet first prevails order.
    // It completely prevails over this factory :-)

    CookieSet.Factory factory = new CookieSet.Factory() {
        public <T extends Node.Cookie> T createCookie(Class<T> klass) {
            if (klass.isAssignableFrom(EditorCookie.class)
               || klass.isAssignableFrom(OpenCookie.class)
               || klass.isAssignableFrom(CloseCookie.class)
               || klass.isAssignableFrom(PrintCookie.class) ) {

                if (editor == null) editor = createEditorCookie();  // the first pass
                if (editor == null) return null;                    //??? gc unfriendly

                return klass.isAssignableFrom(editor.getClass()) ? klass.cast(editor) : null;
            } else {
                return null;
            }
        }
    };

    CookieSet cookies = getCookieSet();
    // EditorCookie.class must be synchronized with
    // XMLEditor.Env->findCloneableOpenSupport
    cookies.add(EditorCookie.class, factory);
    cookies.add(OpenCookie.class, factory);
    cookies.add(CloseCookie.class, factory);
    cookies.add(PrintCookie.class, factory);

    // set info for this file
    //getIP ().resolveInfo ();        #16045
    cookies.assign( SaveAsCapable.class, new SaveAsCapable() {
        public void saveAs( FileObject folder, String fileName ) throws IOException {
            EditorCookie ec = getCookieSet().getCookie( EditorCookie.class );
            if( ec instanceof DataEditorSupport ) {
                ((DataEditorSupport)ec).saveAs( folder, fileName );
            } else {
                Logger.getLogger( XMLDataObject.class.getName() ).log( Level.FINE, "'Save As' requires DataEditorSupport" ); //NOI18N
            }
        }
    });
}
 
示例29
public Sample60M6DataObject(FileObject pf, Sample60M6DataLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet cookies = getCookieSet();
    cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
}
 
示例30
protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
         MultiDataObject m = new MultiDataObject (primaryFile, this);
m.getCookieSet().add((Node.Cookie)DataEditorSupport.create(m, m.getPrimaryEntry(), m.getCookieSet()));
return m;
     }