use of org.eclipse.wst.sse.core.internal.provisional.IModelManager 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.IModelManager 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.IModelManager in project webtools.sourceediting by eclipse.
the class JsSearchDocument method getJSTranslation.
/**
* It's not recommended for clients to hold on to this JSPTranslation
* since it's kind of large. If possible, hold on to the
* JSPSearchDocument, which is more of a lightweight proxy.
*
* @return the JSPTranslation for the jsp file, or null if it's an
* unsupported file.
*/
public final IJsTranslation getJSTranslation() {
IJsTranslation translation = null;
IFile jspFile = getFile();
if (!JsSearchSupport.isJsp(jspFile)) {
return translation;
}
IStructuredModel model = null;
try {
// get existing model for read, then get document from it
IModelManager modelManager = getModelManager();
if (modelManager != null) {
model = modelManager.getModelForRead(jspFile);
}
// handle unsupported
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
JsTranslationAdapterFactory.setupAdapterFactory(xmlModel);
IDOMDocument doc = xmlModel.getDocument();
JsTranslationAdapter adapter = (JsTranslationAdapter) doc.getAdapterFor(IJsTranslation.class);
translation = adapter.getJsTranslation(false);
}
} catch (IOException e) {
Logger.logException(e);
} catch (CoreException e) {
Logger.logException(e);
} catch (UnsupportedCharsetExceptionWithDetail e) {
// no need to log this. Just consider it an invalid file for our
// purposes.
// Logger.logException(e);
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return translation;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class TestFormatProcessorCSS method getModelForEdit.
/**
* must release model (from edit) after
*
* @param filename
* relative to this class (TestFormatProcessorCSS)
*/
private IStructuredModel getModelForEdit(final String filename) {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
InputStream inStream = getClass().getResourceAsStream(filename);
if (inStream == null)
throw new FileNotFoundException("Can't file resource stream " + filename);
final String baseFile = getClass().getResource(filename).toString();
model = modelManager.getModelForEdit(baseFile, inStream, null);
} catch (IOException ex) {
ex.printStackTrace();
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.
the class ModelTest method createHTMLModel.
public static IDOMModel createHTMLModel() {
// return new XMLModelImpl();
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForEdit("test.html", new NullInputStream(), null);
// always use the same line delimiter for these tests, regardless
// of
// plaform or preference settings
model.getStructuredDocument().setLineDelimiter(TestWriter.commonEOL);
} catch (Exception e) {
e.printStackTrace();
}
// null);
return (IDOMModel) model;
}
Aggregations