本文整理汇总了Java中org.netbeans.modules.editor.NbEditorUtilities类的典型用法代码示例。如果您正苦于以下问题:Java NbEditorUtilities类的具体用法?Java NbEditorUtilities怎么用?Java NbEditorUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NbEditorUtilities类属于org.netbeans.modules.editor包,在下文中一共展示了NbEditorUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCompletion
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public List<JPACompletionItem> doCompletion(CompletionContext context) {
List<JPACompletionItem> results = new ArrayList<JPACompletionItem>();
int caretOffset = context.getCaretOffset();
String typedChars = context.getTypedPrefix();
Project project = FileOwnerQuery.getOwner(
NbEditorUtilities.getFileObject(context.getDocument()));
JPADataSourceProvider dsProvider = project.getLookup().lookup(JPADataSourceProvider.class);
if(dsProvider != null){
for (JPADataSource val : dsProvider.getDataSources()) {
if(val.getDisplayName().toLowerCase().startsWith(typedChars.trim().toLowerCase())){
JPACompletionItem item = JPACompletionItem.createAttribValueItem(caretOffset - typedChars.length(),
val.getDisplayName());
results.add(item);
}
}
}
setAnchorOffset(context.getCurrentTokenOffset() + 1);
return results;
}
示例2: getJavaSource
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
public static JavaSource getJavaSource(Document doc) {
FileObject fileObject = NbEditorUtilities.getFileObject(doc);
if (fileObject == null) {
return null;
}
Project project = FileOwnerQuery.getOwner(fileObject);
if (project == null) {
return null;
}
// XXX this only works correctly with projects with a single sourcepath,
// but we don't plan to support another kind of projects anyway (what about Maven?).
// mkleint: Maven has just one sourceroot for java sources, the config files are placed under
// different source root though. JavaProjectConstants.SOURCES_TYPE_RESOURCES
SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (SourceGroup sourceGroup : sourceGroups) {
return JavaSource.create(ClasspathInfo.create(sourceGroup.getRootFolder()));
}
return null;
}
示例3: parse
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
/**
* Parses the given document.
* Currently the implementation expects it to be a {@link BaseDocument} or null.
*
* @param document the document to parse.
*/
public void parse(BaseDocument document) throws IOException {
FileObject fo = NbEditorUtilities.getFileObject(document);
if (fo == null) {
LOGGER.log(Level.WARNING, "Could not get a FileObject for document {0}", document);
return;
}
LOGGER.log(Level.FINE, "Parsing {0}", fo);
File file = FileUtil.toFile(fo);
if (file == null) {
LOGGER.log(Level.WARNING, "{0} resolves to a null File, aborting", fo);
return;
}
new DocumentParser(file, document).run();
LOGGER.log(Level.FINE, "Parsed {0}", fo);
}
示例4: propertyChange
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
public void propertyChange (PropertyChangeEvent evt) {
if (evt.getPropertyName () == null ||
evt.getPropertyName ().equals (EditorRegistry.FOCUSED_DOCUMENT_PROPERTY) ||
evt.getPropertyName ().equals (EditorRegistry.FOCUS_GAINED_PROPERTY)
) {
JTextComponent editor = EditorRegistry.focusedComponent ();
if (editor == currentEditor) return;
currentEditor = editor;
if (currentEditor != null) {
Document document = currentEditor.getDocument ();
FileObject fileObject = NbEditorUtilities.getFileObject(document);
if (fileObject == null) {
// System.out.println("no file object for " + document);
return;
}
}
setEditor (currentEditor);
}
else if (evt.getPropertyName().equals(EditorRegistry.LAST_FOCUSED_REMOVED_PROPERTY)) {
currentEditor = null;
setEditor(null);
}
}
示例5: runTaskWithinContext
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public void runTaskWithinContext(Lookup context, Task task) {
JTextComponent component = context.lookup(JTextComponent.class);
if (component != null) {
DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
if (dobj != null) {
FileObject fo = dobj.getPrimaryFile();
ModelSource ms = Utilities.createModelSource(fo);
SettingsModel model = SettingsModelFactory.getDefault().getModel(ms);
if (model != null) {
Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
task.run(newContext);
return;
}
}
}
task.run(context);
}
示例6: runTaskWithinContext
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public void runTaskWithinContext(Lookup context, Task task) {
JTextComponent component = context.lookup(JTextComponent.class);
if (component != null) {
DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
if (dobj != null) {
FileObject fo = dobj.getPrimaryFile();
ModelSource ms = Utilities.createModelSource(fo);
if (ms.isEditable()) {
POMModel model = POMModelFactory.getDefault().getModel(ms);
if (model != null) {
Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
task.run(newContext);
return;
}
}
}
}
task.run(context);
}
示例7: propertyChange
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
public void propertyChange (PropertyChangeEvent evt) {
if (evt.getPropertyName () == null ||
evt.getPropertyName ().equals (EditorRegistry.FOCUSED_DOCUMENT_PROPERTY) ||
evt.getPropertyName ().equals (EditorRegistry.FOCUS_GAINED_PROPERTY)
) {
JTextComponent editor = EditorRegistry.focusedComponent ();
if (editor == currentEditor) return;
currentEditor = editor;
if (currentEditor != null) {
Document document = currentEditor.getDocument ();
FileObject fileObject = NbEditorUtilities.getFileObject (document);
if (fileObject == null) {
// System.out.println("no file object for " + document);
return;
}
}
setEditor (currentEditor);
}
else if (evt.getPropertyName().equals(EditorRegistry.LAST_FOCUSED_REMOVED_PROPERTY)) {
currentEditor = null;
setEditor(null);
}
}
示例8: actionPerformed
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
BaseDocument bdoc = Utilities.getDocument(target);
if(bdoc == null) {
return ; //no document?!?!
}
DataObject csso = NbEditorUtilities.getDataObject(bdoc);
if(csso == null) {
return ; //document not backuped by DataObject
}
String pi = createText(csso);
StringSelection ss = new StringSelection(pi);
ExClipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
clipboard.setContents(ss, null);
StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(CopyStyleAction.class, "MSG_Style_tag_in_clipboard")); // NOI18N
}
示例9: canAccept
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public boolean canAccept(SaasMethod method, Document doc) {
if (SaasBean.canAccept(method, WsdlSaasMethod.class, getDropFileType()) &&
Util.isJava(doc)) {
try {
WsdlSaasMethod wsm = (WsdlSaasMethod) method;
Project p = FileOwnerQuery.getOwner(NbEditorUtilities.getFileObject(doc));
new SoapClientSaasBean(wsm, p, JavaUtil.toJaxwsOperationInfos(wsm, p));
return true;
} catch (Exception e) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, null,
NbBundle.getMessage(CodeSetupPanel.class, "WARN_UnsupportedDropTarget")
);
}
}
return false;
}
示例10: checkPluginList
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
private void checkPluginList(List<Plugin> plugins, POMModel model, List<ErrorDescription> toRet, Map<String, String> managed) {
if (plugins != null) {
for (Plugin plg : plugins) {
String ver = plg.getVersion();
if (ver != null) {
String art = plg.getArtifactId();
String gr = plg.getGroupId();
gr = gr != null ? gr : Constants.GROUP_APACHE_PLUGINS;
String key = gr + ":" + art; //NOI18N
if (managed.keySet().contains(key)) {
int position = plg.findChildElementPosition(model.getPOMQNames().VERSION.getQName());
Line line = NbEditorUtilities.getLine(model.getBaseDocument(), position, false);
String managedver = managed.get(key);
toRet.add(ErrorDescriptionFactory.createErrorDescription(
configuration.getSeverity(configuration.getPreferences()).toEditorSeverity(),
NbBundle.getMessage(OverridePluginManagementError.class, "TXT_OverridePluginManagementError", managedver),
Collections.<Fix>singletonList(new OverrideFix(plg)),
model.getBaseDocument(), line.getLineNumber() + 1));
}
}
}
}
}
示例11: checkPluginList
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
private void checkPluginList(List<Plugin> plugins, POMModel model, List<ErrorDescription> toRet, boolean release, boolean latest, boolean snapshot) {
if (plugins != null) {
for (Plugin plg : plugins) {
String ver = plg.getVersion();
if (ver != null && ((release && "RELEASE".equals(ver)) || //NOI18N
(latest &&"LATEST".equals(ver)) || //NOI18N
(snapshot && ver.endsWith("SNAPSHOT")) //NOI18N
)) {
int position = plg.findChildElementPosition(model.getPOMQNames().VERSION.getQName());
Line line = NbEditorUtilities.getLine(model.getBaseDocument(), position, false);
toRet.add(ErrorDescriptionFactory.createErrorDescription(
configuration.getSeverity(configuration.getPreferences()).toEditorSeverity(),
NbBundle.getMessage(ReleaseVersionError.class, "DESC_RELEASE_VERSION"),
Collections.<Fix>emptyList(), //Collections.<Fix>singletonList(new ReleaseFix(plg)),
model.getBaseDocument(), line.getLineNumber() + 1));
}
}
}
}
示例12: getFullMimePath
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
private static MimePath getFullMimePath(Document document, int offset) {
String langPath = null;
if (document instanceof AbstractDocument) {
AbstractDocument adoc = (AbstractDocument)document;
adoc.readLock();
try {
List<TokenSequence<?>> list = TokenHierarchy.get(document).embeddedTokenSequences(offset, true);
if (list.size() > 1) {
langPath = list.get(list.size() - 1).languagePath().mimePath();
}
} finally {
adoc.readUnlock();
}
}
if (langPath == null) {
langPath = NbEditorUtilities.getMimeType(document);
}
if (langPath != null) {
return MimePath.parse(langPath);
} else {
return null;
}
}
示例13: analyseSource
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
private void analyseSource(JTextComponent comp) {
DataObject dataObject = NbEditorUtilities.getDataObject(comp.getDocument());
if (dataObject == null) {
return;
}
FileObject fileObject = dataObject.getPrimaryFile();
if (fileObject == null) {
return;
}
String currentDocPath = defaultString(fileObject.getPath());
FileType.logger.log(Level.INFO, "Path corrente: {0}\nPath anterior: {1}", new Object[]{currentDocPath, this.lastDocPath});
if (!this.lastDocPath.equals(currentDocPath)) {
showLineEnd(comp.getDocument());
}
this.lastDocPath = currentDocPath;
}
示例14: performTask
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
@Override
public void performTask() {
try {
Document document = context.getDocument();
FileObject fileObject = NbEditorUtilities.getFileObject(document);
String name = fileObject.getName();
if (name.equals("build")) {
String docText = document.getText(0, document.getLength());
Optional<PlayProject> playProjectOptional = PlayProjectUtil.getPlayProject(fileObject);
if (playProjectOptional.isPresent()) {
PlayProject playProject = playProjectOptional.get();
playProject.getSbtDependenciesParentNode().reloadChildrens(docText);
StatusDisplayer.getDefault().setStatusText("build.sbt reload");
}
}
} catch (BadLocationException ex) {
ExceptionManager.logException(ex);
}
}
示例15: lint
import org.netbeans.modules.editor.NbEditorUtilities; //导入依赖的package包/类
public LinkedList<JSHintError> lint(Document d) {
Context cx = Context.enter();
LinkedList<JSHintError> result = new LinkedList<>();
FileObject fo = NbEditorUtilities.getFileObject(d);
try {
Scriptable config = getConfig(cx, fo);
String code = d.getText(0, d.getLength());
result = lint(cx, code, config);
} catch (IOException | ParseException | BadLocationException ex) {
Exceptions.printStackTrace(ex);
} finally {
Context.exit();
}
return result;
}