public boolean openHyperLink() { String localiz = getLocalization(); if (localiz == null) { return false; } else if (fBase.getUnderlyingResource() == null) { return false; } else if (fElement.length() == 0 || fElement.charAt(0) != '%') { return false; } IProject proj = fBase.getUnderlyingResource().getProject(); IFile file = proj.getFile(localiz + ".properties"); // $NON-NLS-1$ if (!file.exists()) return false; try { IEditorPart editor = IDE.openEditor(PDEPlugin.getActivePage(), file); if (!(editor instanceof TextEditor)) return false; TextEditor tEditor = (TextEditor) editor; IDocument doc = tEditor.getDocumentProvider().getDocument(tEditor.getEditorInput()); if (doc == null) return false; try { String key = fElement.substring(1); int keyLen = key.length(); int length = doc.getLength(); int start = 0; IRegion region = null; FindReplaceDocumentAdapter docSearch = new FindReplaceDocumentAdapter(doc); while ((region = docSearch.find(start, key, true, false, false, false)) != null) { int offset = region.getOffset(); if (offset > 0) { // check for newline before char c = doc.getChar(offset - 1); if (c != '\n' && c != '\r') { start += keyLen; continue; } } if (offset + keyLen < length) { // check for whitespace / assign symbol after char c = doc.getChar(offset + keyLen); if (!Character.isWhitespace(c) && c != '=' && c != ':') { start += keyLen; continue; } } tEditor.selectAndReveal(offset, keyLen); break; } } catch (BadLocationException e) { PDEPlugin.log(e); } } catch (PartInitException e) { return false; } return true; }
/** Converts the text in editor to HTML text to be displayed in preview page. */ void markdownToHtml() { String editorText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(); String htmlText = "<p>Error processing the input.</p>"; try { htmlText = markdownProcessor.process(editorText); } catch (IOException e) { } browser.setText(htmlText); }
/** Sorts the words in page 0, and shows them in page 2. */ void sortWords() { String editorText = editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(); StringTokenizer tokenizer = new StringTokenizer(editorText, " \t\n\r\f!@#\u0024%^&*()-_=+`~[]{};:'\",.<>/?|\\"); ArrayList editorWords = new ArrayList(); while (tokenizer.hasMoreTokens()) { editorWords.add(tokenizer.nextToken()); } Collections.sort(editorWords, Collator.getInstance()); StringWriter displayText = new StringWriter(); for (int i = 0; i < editorWords.size(); i++) { displayText.write(((String) editorWords.get(i))); displayText.write(System.getProperty("line.separator")); } text.setText(displayText.toString()); }