/** This is called by the multiview elements whenever they are created * (and given a observer knowing their multiview TopComponent). It is * important during deserialization and clonig the multiview - i.e. during * the operations we have no control over. But anytime a multiview is * created, this method gets called. */ private void setTopComponent(TopComponent topComp) { multiviewTC = (CloneableTopComponent)topComp; updateMVTCName(); if (topComponentsListener == null) { topComponentsListener = new TopComponentsListener(); TopComponent.getRegistry().addPropertyChangeListener(topComponentsListener); } opened.add(this); try { addStatusListener(getDataObject().getPrimaryFile().getFileSystem()); } catch (FileStateInvalidException fsiex) { Exceptions.printStackTrace(fsiex); } }
/** * Updates settings used by this generator. It should be called outside locks. * @param file a file where the generated content will be added */ public void updateSettings(FileObject file) { DataObject dobj = null; DataFolder folder = null; try { dobj = DataObject.find(file); folder = dobj.getFolder(); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } if (dobj == null || folder == null) { return; } for (CreateFromTemplateAttributesProvider provider : Lookup.getDefault().lookupAll(CreateFromTemplateAttributesProvider.class)) { Map<String, ?> attrs = provider.attributesFor(dobj, folder, "XXX"); // NOI18N if (attrs == null) { continue; } Object aName = attrs.get("user"); // NOI18N if (aName != null) { author = aName.toString(); break; } } }
private void hideInfo() { watcherLogger.finer("hideInfo()"); //NOI18N txtComp.setEnabled(true); try { ignoreFileNamePatternChanges = true; if (doc.getText(0, doc.getLength()).equals(getInfoText())) { doc.remove(0, doc.getLength()); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } finally { ignoreFileNamePatternChanges = false; txtComp.setForeground(foregroundColor); infoDisplayed = false; } }
private TextDetail createMockTextDetail(String line, String match) { FileSystem fs = FileUtil.createMemoryFileSystem(); try { FileObject fo = fs.getRoot().createData("mockMatch.txt"); SearchPattern sp = SearchPattern.create(match, false, false, false); DataObject dob = DataObject.find(fo); TextDetail td = new TextDetail(dob, sp); td.setLine(1); int col0 = line.indexOf(match) + 1; td.setColumn(col0); td.setMatchedText(match); td.setMarkLength(match.length()); td.setStartOffset(col0); td.setEndOffset(col0 + match.length()); td.setLineText(line); return td; } catch (Exception e) { Exceptions.printStackTrace(e); return null; } }
public boolean loadForm() { if (!formLoaded) { Runnable r = new Runnable() { @Override public void run() { loadFormData(); } }; if (java.awt.EventQueue.isDispatchThread()) { r.run(); } else { // loading must be done in AWT event dispatch thread try { java.awt.EventQueue.invokeAndWait(r); } catch (Exception ex) { Exceptions.printStackTrace(ex); } } } return formLoaded; }
void focused(FileObject fo, JTextComponent target) { Project project = FileOwnerQuery.getOwner(fo); if (project != null) { CoverageProvider provider = getProvider(project); if (provider != null && provider.isEnabled()) { try { EditorCookie ec = DataLoadersBridge.getDefault().getCookie(fo, EditorCookie.class); if (ec != null) { Document doc = ec.getDocument(); if (doc == null) { return; } doc.putProperty(COVERAGE_DOC_PROPERTY, null); CoverageHighlightsContainer container = CoverageHighlightsLayerFactory.getContainer(target); if (container != null) { container.refresh(); } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } }
private void postCloseCleanup() { try { // try to close the dataobject DataObject d = DataObject.find(getConsoleFile()); EditorCookie cake = d.getLookup().lookup(EditorCookie.class); cake.close(); // discard the dataobject synchronized (this) { if (document == null) { return; } document = null; } } catch (IOException ex) { Exceptions.printStackTrace(ex); } if (controlsIO) { inputOutput.closeInputOutput(); } ShellRegistry.get().closed(this); }
/** reade codenamebase + revision */ private void resolveModuleElm (String codeName) { if (codeName != null) { int slash = codeName.indexOf ("/"); // NOI18N if (slash == -1) { codeNameBase = codeName; codeNameRelease = -1; } else { codeNameBase = codeName.substring (0, slash); try { codeNameRelease = Integer.parseInt(codeName.substring(slash + 1)); } catch (NumberFormatException ex) { Exceptions.attachLocalizedMessage(ex, "Content: \n" + getFileContent(source)); // NOI18N Exceptions.attachLocalizedMessage(ex, "Source: " + source); // NOI18N Logger.getLogger(XMLSettingsSupport.class.getName()).log(Level.WARNING, null, ex); codeNameRelease = -1; } } } else { codeNameBase = null; codeNameRelease = -1; } }
@CheckForNull private static URL findRtJar() { final String boot = System.getProperty("sun.boot.class.path"); //NOI18N if (boot != null) { for (String part : boot.split(File.pathSeparator)) { if (part.contains("rt.jar")) { //NOI18N final File rtJar = FileUtil.normalizeFile(new File(part)); try { return FileUtil.getArchiveRoot(BaseUtilities.toURI(rtJar).toURL()); } catch (MalformedURLException e) { Exceptions.printStackTrace(e); } } } } return null; }
/** * Propagate text of the first region into all other regions. */ public void sync() { String firstRegionText = getFirstRegionText(); if (firstRegionText != null) { int regionCount = getRegionCount(); for (int i = 1; i < regionCount; i++) { MutablePositionRegion region = getRegion(i); int offset = region.getStartOffset(); int length = region.getEndOffset() - offset; try { if (!CharSequenceUtilities.textEquals(firstRegionText, DocumentUtilities.getText(doc, offset, length))) { if (firstRegionText.length() > 0) { doc.insertString(offset, firstRegionText, null); } doc.remove(offset + firstRegionText.length(), length); } } catch (BadLocationException e) { Exceptions.printStackTrace(e); } } } }
private ElementJavadoc getJavaDocFor( @NonNull final ElementNode node, @NullAllowed final Callable<Boolean> cancel) { ElementNode root = getRootNode(); if ( root == null ) { return null; } final ElementHandle<? extends Element> eh = node.getDescritption().getElementHandle(); if (eh == null) { return null; } final JavaSource js = JavaSource.forFileObject( root.getDescritption().fileObject ); if (js == null) { return null; } final JavaDocCalculator calculator = new JavaDocCalculator(eh, cancel); try { js.runUserActionTask( calculator, true ); } catch( IOException ioE ) { Exceptions.printStackTrace( ioE ); return null; } return calculator.doc; }
/** * Shuts down the connection, may be called for local or remote close. */ void shutDown() { try { LOG.log(Level.FINE, "notifyShutdown: closing control socket: {0}", controlSocket); if (controlSocket != null) { // assumes both input and output terminate controlSocket.close(); } ostm.close(); istm.close(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } finally { synchronized (this) { closed = true; notify(); } } }
private void generate(final Document doc, final Descriptor desc, final JTextComponent jtc) throws BadLocationException { final Indent ie = Indent.get(doc); try { ie.lock(); NbDocument.runAtomicAsUser((StyledDocument) doc, new Runnable() { public void run() { try { int caretPos = jtc.getCaretPosition(); generateJavadoc(doc, desc, ie); // move caret jtc.setCaretPosition(caretPos); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); } finally { ie.unlock(); } }
@Override public void open() { FileObject fo = getFileObject(); SpringConfigModel model = SpringConfigModel.forFileObject(fo); if (model == null) { return; } try { model.runReadAction(new Action<SpringBeans>() { public void run(SpringBeans beans) { SpringBean bean = beans.findBean(getSimpleName()); if (bean == null) { return; } SpringBeansUIs.createGoToBeanAction(bean).invoke(); } }); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
private void stopDebuggerRemoteService(JPDADebugger d) { ClassObjectReference serviceClass = RemoteServices.getServiceClass(d, RemoteServices.ServiceType.AWT); if (serviceClass == null) { return ; } try { ReferenceType serviceType = serviceClass.reflectedType(); Field awtAccessLoop = serviceType.fieldByName("awtAccessLoop"); // NOI18N if (awtAccessLoop != null) { ((ClassType) serviceType).setValue(awtAccessLoop, serviceClass.virtualMachine().mirrorOf(false)); } serviceClass.enableCollection(); } catch (VMDisconnectedException vdex) { // Ignore } catch (Exception ex) { Exceptions.printStackTrace(ex); } }
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed try { FileObject tempFO = FileUtil.getConfigFile(DECLARATIVE_HINT_TEMPLATE_LOCATION); // NOI18N FileObject folderFO = FileUtil.getConfigFile("rules"); if (folderFO == null) { folderFO = FileUtil.getConfigRoot().createFolder("rules"); } DataFolder folder = (DataFolder) DataObject.find(folderFO); DataObject template = DataObject.find(tempFO); DataObject newIfcDO = template.createFromTemplate(folder, null); RulesManager.getInstance().reload(); cpBased.reset(); errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false); setModel(errorTreeModel); logic.errorTreeModel = errorTreeModel; HintMetadata newHint = getHintByName(newIfcDO.getPrimaryFile().getNameExt()); logic.writableSettings.setEnabled(newHint, true); select(newHint); hasNewHints = true; } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
private void fire() { LOG.log(Level.FINEST, "Request to fire an event"); //NOI18N synchronized (this) { if (task == null) { LOG.log(Level.FINEST, "Scheduled firer task"); //NOI18N final Future<Project[]> becomeProjects = OpenProjects.getDefault().openProjects(); task = RP.create(new Runnable() { @Override public void run() { try { becomeProjects.get(); support.firePropertyChange(PROP_RESOURCES,null,null); LOG.log(Level.FINEST, "Fired an event"); //NOI18N } catch (InterruptedException | ExecutionException ex) { Exceptions.printStackTrace(ex); } finally { task = null; //Write barrier } } }); task.schedule(0); } } }
public void save() { try { SaasUtil.saveSaas(this, getSaasFile()); if (getProperties().size() > 0) { java.io.OutputStream out = null; try { out = getPropFile(true).getOutputStream(); getProperties().store(out, getDisplayName() + " : " + getUrl()); } finally { if (out != null) { out.close(); } } } } catch (Exception e) { Exceptions.printStackTrace(e); } }
@Override public void openEditor(PrimitiveData metadata) { String javaFilePath = metadata.classFQN.replace('.', '/') + ".java"; for (FileObject curRoot : GlobalPathRegistry.getDefault().getSourceRoots()) { FileObject fileObject = curRoot.getFileObject(javaFilePath); if (fileObject != null) { DataObject dobj = null; try { dobj = DataObject.find(fileObject); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } if (dobj != null) { EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); if (ec != null) { ec.open(); } } } } }
public boolean verificarCaracteristicasEscenarioSeleccionado ( File ficheroSeleccionado,String orgModelo,int numRobots ){ try { escenarioSimulComp = itfPersistenciaSimul.obtenerInfoEscenarioSimulacion(ficheroSeleccionado.getName()); } catch (Exception ex) { Exceptions.printStackTrace(ex); } if(escenarioSimulComp == null ) return false; identEquipoActual=escenarioSimulComp.getIdentEscenario(); numeroRobots = escenarioSimulComp.getNumRobots(); modeloOrganizativo= escenarioSimulComp.getmodeloOrganizativo(); if(this.numeroRobots==numRobots &&this.modeloOrganizativo.equalsIgnoreCase(orgModelo)){ // se envia notificacion al agente controlador con el computacional obtenido escenarioSimulComp.setGestorEscenarios(gestionEscComp); escenarioValidoObtenido = true; return true; }else { visorControlSim.visualizarConsejo("Fichero seleccionado No valido ", "El modelo organizativo del fichero seleccionado: "+orgModelo + " o el numero de Robots = : "+ numRobots + " No coinciden ", "Seleccione otro fichero o cree uno nuevo "); return false; } }
private PersistenceUnit getPersistenceUnit(FileObject target) { PersistenceScope persistenceScope = PersistenceScope.getPersistenceScope(target); if (persistenceScope == null) { return null; } try { // TODO: fix ASAP! 1st PU is taken, needs to find the one which realy owns given file Persistence persistence = PersistenceMetadata.getDefault().getRoot(persistenceScope.getPersistenceXml()); if (persistence != null) { return persistence.getPersistenceUnit(0); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } return null; }
@Override public String getPrefix(ParserResult info, int caretOffset, boolean upToOffset) { if (caretOffset > 0) { try { Document doc = ((YamlParserResult) info).getSnapshot().getSource().getDocument(false); if (doc != null) { return doc.getText(caretOffset - 1, 1); } else { return null; } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } return null; }
public PropertyEditor getPropertyEditor() { if (mdl.getPropertyEditorClass() != null) { try { //System.err.println("ModelProperty creating a " //+ mdl.getPropertyEditorClass()); Constructor c = mdl.getPropertyEditorClass().getConstructor(); c.setAccessible(true); return (PropertyEditor) c.newInstance(new Object[0]); } catch (Exception e) { Exceptions.printStackTrace(e); return new PropUtils.NoPropertyEditorEditor(); } } return super.getPropertyEditor(); }
private void redoClosure() { Set<String> allEntities = new HashSet<String>(availableEntities); allEntities.addAll(selectedEntities); referencedEntities.clear(); try{ referencedEntities.addAll(getReferencedEntitiesTransitively(wantedEntities)); }catch (IOException ioe){ Exceptions.printStackTrace(ioe); } selectedEntities.clear(); selectedEntities.addAll(wantedEntities); selectedEntities.addAll(referencedEntities); availableEntities.clear(); availableEntities.addAll(allEntities); availableEntities.removeAll(selectedEntities); }
private static String getReflectionMethodValue(String methodName) { try { return (String) getContext().getClass().getMethod(methodName).invoke(getContext()); } catch (java.lang.reflect.InvocationTargetException itex) { Throwable tex = itex.getTargetException(); if (tex instanceof RuntimeException) { throw (RuntimeException) tex; } else { ErrorManager.getDefault().notify(tex); return null; } } catch (Exception ex) { Exceptions.printStackTrace(ex); return null; } }
/** Checks whether subclass overrides a method */ private boolean overridesAMethod(String name, Class[] arguments) { // we are subclass of AbstractNode try { java.lang.reflect.Method m = getClass().getMethod(name, arguments); if (m.getDeclaringClass() != AbstractNode.class) { // ok somebody overriden the method return true; } } catch (NoSuchMethodException ex) { Exceptions.printStackTrace(ex); } return false; }
@Override public String[] children(String f) { if ("".equals(f)) { return new String[] {"content"}; } else if ("content".equals(f)) { try { if (contentSemaphore.tryAcquire(1, 10, TimeUnit.SECONDS)) { return new String[] {"a.txt", "b.txt", "c.txt"}; } else { return new String[0]; } } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); return new String[0]; } } else { return new String[0]; } }
@Override public Void visitMemberSelect(MemberSelectTree node, Void p) { Element el = info.getTrees().getElement(getCurrentPath()); if (toFind.equals(el)) { try { int[] span = treeUtils.findNameSpan(node); if(span != null) { MutablePositionRegion region = createRegion(doc, span[0], span[1]); usages.add(region); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } return super.visitMemberSelect(node, p); }
/** * * @param keyName * @param value * @return returns a collection of files which contains the keyName key and the * value matches the value regular expression */ public Collection<FileObject> find(String keyName, String value) { try { String searchExpression = ".*(" + value + ")[,;].*"; //NOI18N Collection<FileObject> matchedFiles = new LinkedList<>(); Collection<? extends IndexResult> results = querySupport.query(keyName, searchExpression, QuerySupport.Kind.REGEXP, keyName); for (IndexResult result : filterDeletedFiles(results)) { matchedFiles.add(result.getFile()); } return matchedFiles; } catch (IOException ex) { Exceptions.printStackTrace(ex); } return Collections.emptyList(); }
protected synchronized String getRemoteTmpDir() { if (remoteTmpDir == null) { final ExecutionEnvironment local = ExecutionEnvironmentFactory.getLocal(); MacroExpander expander = MacroExpanderFactory.getExpander(local); String id; try { id = expander.expandPredefinedMacros("${hostname}-${osname}-${platform}${_isa}"); // NOI18N } catch (ParseException ex) { id = local.getHost(); Exceptions.printStackTrace(ex); } remoteTmpDir = "/tmp/" + id + "-" + System.getProperty("user.name") + "-" + getTestExecutionEnvironment().getUser(); if (POSTFIX != null) { remoteTmpDir += '-' + POSTFIX; } } return remoteTmpDir; }
private static boolean isInstanceOf(JPDAClassType ct, String className) { if (ct == null) return false; try { java.lang.reflect.Method isInstanceOfMethod = ct.getClass().getMethod("isInstanceOf", String.class); return (Boolean) isInstanceOfMethod.invoke(ct, className); } catch (Exception ex) { Exceptions.printStackTrace(ex); return false; } }
private void refreshKeys() { try { if (first_run) { //postpone the initialization until scanning finishes as we need to wait for some data //to be properly initialized. If CssIndex.create() is called to soon during //the startup then it won't obtain proper source roots first_run = false; ParserManager.parseWhenScanFinished("text/css", refreshKeysTask); //NOI18N } else { ParserManager.parse("text/css", refreshKeysTask); //NOI18N } } catch (ParseException ex) { Exceptions.printStackTrace(ex); } }
public void unmarkModified() { unmarkModifiedStarted.countDown(); try { Thread.sleep(500); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } modified = false; unmarkModifiedFinished.countDown(); }
private URL getOwnerRoot (final javax.tools.FileObject sibling) { try { return siblings.hasSibling() ? getOwnerRootSib(siblings.getSibling()) : (sibling == null ? getOwnerRootNoSib() : getOwnerRootSib(sibling.toUri().toURL())); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); return null; } }
private void openSelected() { PopupUtil.hidePopup(); Candidate cand = (Candidate) jList1.getSelectedValue(); if (cand != null) { try { cand.fix.implement(); } catch (Exception ex) { Exceptions.printStackTrace(ex); } } }
public void markModified() throws IOException { if (cannotBeModified != null) { final String notify = cannotBeModified; IOException e = new IOException () { @Override public String getLocalizedMessage () { return notify; } }; Exceptions.attachLocalizedMessage(e, cannotBeModified); throw e; } modified = true; }
@Override public void actionPerformed(ActionEvent e) { FixVersionConflictPanel.ExclusionTargets et = new FixVersionConflictPanel.ExclusionTargets(node, findNewest(node, true)); Set<Artifact> exclTargets = et.getAll(); if (!model.startTransaction()) { return; } try { excludeDepFromModel(node.getImpl(), exclTargets); } finally { try { model.endTransaction(); } catch (IllegalStateException ex) { StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(DependencyGraphScene.class, "ERR_UpdateModel", Exceptions.findLocalizedMessage(ex)), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT); return; } } HashSet<MavenDependencyNode> conflictParents = new HashSet<MavenDependencyNode>(); for (Artifact artif : exclTargets) { conflictParents.addAll(et.getConflictParents(artif)); } updateGraphAfterExclusion(node, exclTargets, conflictParents); save(); }
private void delay(int millis) { try { Thread.sleep(millis); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } }
@Override public boolean matches(InputStream encoded, AtomicBoolean cancel, BulkPattern patternIn) { try { return !matchesImpl(encoded, cancel, patternIn, false).isEmpty(); } catch (IOException ex) { Exceptions.printStackTrace(ex); return false; } }
private void restore() { for (Handle handle : handles) { try { handle.restore(); } catch (IOException e) { Exceptions.printStackTrace(e); } } }