use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StandardEditorActionsAction method delete.
private void delete(IAction action) {
JsJfaceNode[] nodes = parseSelection();
if (nodes == null || nodes.length == 0) {
return;
}
IStructuredDocument lastDoc = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = null;
try {
int start;
int length;
for (int i = 0; i < nodes.length; i++) {
JsJfaceNode currentNode = nodes[i];
start = currentNode.getStartOffset();
length = currentNode.getLength();
IStructuredDocument doc = currentNode.getStructuredDocument();
if (doc != lastDoc) {
lastDoc = doc;
if (model != null) {
model.endRecording(action);
model.changedModel();
model.releaseFromEdit();
}
if (modelManager != null) {
model = modelManager.getExistingModelForEdit(doc);
model.aboutToChangeModel();
model.beginRecording(action, "Delete JavaScript Element", "Delete JavaScript Element");
}
}
// $NON-NLS-1$
doc.replaceText(action, start, length, "");
}
model.endRecording(action);
} catch (Exception e) {
// $NON-NLS-1$
System.out.println(Messages.getString("StandardEditorActionsAction.8") + e);
} finally {
if (model != null) {
model.changedModel();
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StandardEditorActionsAction method paste.
private void paste(IAction action, boolean atEnd) {
JsJfaceNode[] nodes = parseSelection();
if (nodes == null || nodes.length == 0) {
return;
}
int startOfPaste = -1;
IStructuredDocument doc = null;
/* Figure out where to paste the content */
if (atEnd) {
for (int i = 0; i < nodes.length; i++) {
if ((nodes[i].getStartOffset() + nodes[i].getLength()) > startOfPaste) {
startOfPaste = (nodes[i].getStartOffset() + nodes[i].getLength());
doc = nodes[i].getStructuredDocument();
}
}
} else {
for (int i = 0; i < nodes.length; i++) {
if ((nodes[i].getStartOffset() < startOfPaste || startOfPaste < 0)) {
startOfPaste = nodes[i].getStartOffset();
doc = nodes[i].getStructuredDocument();
}
}
}
Clipboard clipboard = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IStructuredModel model = null;
try {
clipboard = new Clipboard(Display.getCurrent());
String pasteString = (String) clipboard.getContents(TextTransfer.getInstance());
model = modelManager.getExistingModelForEdit(doc);
model.aboutToChangeModel();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
model.beginRecording(action, Messages.getString("StandardEditorActionsAction.9") + (atEnd ? Messages.getString("StandardEditorActionsAction.10") : Messages.getString("StandardEditorActionsAction.11")) + Messages.getString("StandardEditorActionsAction.12"), Messages.getString("StandardEditorActionsAction.13") + (atEnd ? Messages.getString("StandardEditorActionsAction.14") : Messages.getString("StandardEditorActionsAction.15")) + Messages.getString("StandardEditorActionsAction.16"));
doc.replaceText(action, startOfPaste, 0, pasteString);
} finally {
if (clipboard != null) {
clipboard.dispose();
}
if (model != null) {
model.endRecording(action);
model.changedModel();
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StandardEditorActionsAction method copy.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
* org.eclipse.jface.viewers.ISelection)
*/
private void copy(IAction action) {
JsJfaceNode[] nodes = parseSelection();
if (nodes == null || nodes.length == 0) {
return;
}
Clipboard clipboard = null;
StringBuffer text = new StringBuffer();
if (StandardEditorActionsAction.APPEND_NEW_LINES_TO_COPY) {
text.append(StandardEditorActionsAction.NEW_LINE);
}
try {
for (int i = 0; i < nodes.length; i++) {
JsJfaceNode currentNode = nodes[i];
int start = currentNode.getStartOffset();
int length = currentNode.getLength();
IStructuredDocument doc = currentNode.getStructuredDocument();
try {
String elementText = doc.get(start, length);
text.append(elementText);
} catch (BadLocationException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
if (StandardEditorActionsAction.APPEND_NEW_LINES_TO_COPY) {
text.append(StandardEditorActionsAction.NEW_LINE);
}
clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { text.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
} finally {
if (clipboard != null) {
clipboard.dispose();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class CSSFontFamilyTest method testFontFamilies.
public void testFontFamilies() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList rules = sheet.getCssRules();
assertEquals(4, rules.getLength());
// Rule 1: No whitespace
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
// Rule 1: No whitespace
rule = rules.item(0);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
// Rule 2: Single whitespace
rule = rules.item(1);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier New"));
// Rule 3: In quotes
rule = rules.item(2);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Courier New"));
// Rule 4: Tabs and spaces all over
rule = rules.item(3);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Comic Sans"));
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class CSSPageRuleTest method testInsertText4.
public void testInsertText4() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList ruleList = sheet.getCssRules();
assertEquals(6, ruleList.getLength());
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
// rule 4
rule = ruleList.item(3);
assertEquals(CSSRule.PAGE_RULE, rule.getType());
assertTrue(rule instanceof CSSPageRule);
assertEquals(":right", ((CSSPageRule) rule).getSelectorText());
declaration = ((CSSPageRule) rule).getStyle();
assertEquals(2, declaration.getLength());
value = declaration.getPropertyCSSValue("margin-left");
checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 3));
value = declaration.getPropertyCSSValue("margin-right");
checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 4));
}
Aggregations