Author: sdzmitrovich
Date: 2009-02-11 04:54:55 -0500 (Wed, 11 Feb 2009)
New Revision: 13578
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3726
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-02-11
09:44:49 UTC (rev 13577)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-02-11
09:54:55 UTC (rev 13578)
@@ -20,17 +20,25 @@
import java.util.Set;
import java.util.Map.Entry;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IFileBuffer;
+import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet;
+import org.eclipse.wst.css.core.internal.text.StructuredTextPartitionerForCSS;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.w3c.dom.css.CSSRuleList;
@@ -54,9 +62,9 @@
private CSSStyleSheet styleSheet = null;
private ICSSStyleSheet eclipseStyleSheet = null;
+ private String COPY_SUFFIX = "_copy";
-
/**
* Constructor.
*
@@ -76,9 +84,30 @@
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getExistingModelForEdit(styleFile);
+
if (model == null)
model = modelManager.getModelForEdit(styleFile);
- if (model instanceof ICSSModel) {
+ else {
+
+ // copy the model
+ model = modelManager.copyModelForEdit(model.getId(), model
+ .getId()
+ + COPY_SUFFIX);
+
+ // set the correct location
+ model.setBaseLocation(styleFile.getLocation().toString());
+
+ // some steps to prepare document ( it is necessary to correct
+ // work of highlight in preview tab )
+ IDocumentPartitioner partitioner = new StructuredTextPartitionerForCSS();
+ ((IDocumentExtension3) model.getStructuredDocument())
+ .setDocumentPartitioner(
+ IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING,
+ partitioner);
+ partitioner.connect(model.getStructuredDocument());
+
+ }
+ if (model instanceof ICSSModel) {
ICSSModel cssModel = (ICSSModel) model;
ICSSDocument document = cssModel.getDocument();
if (document instanceof CSSStyleSheet) {
@@ -94,7 +123,9 @@
JspEditorPlugin.getPluginLog().logError(e.getMessage());
} catch (CoreException e) {
JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
+ } catch (ResourceInUse e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
}
/**
@@ -301,8 +332,8 @@
*/
public void releaseModel() {
IModelManager modelManager = StructuredModelManager.getModelManager();
- if(!modelManager.isShared(model.getId()))
- model.releaseFromEdit();
+ if (!modelManager.isShared(model.getId()))
+ model.releaseFromEdit();
}
/**
@@ -310,7 +341,15 @@
*/
public void saveModel() {
try {
- model.save();
+
+ // it is necessary not to dialog appears when "dirty" css file is
+ // being saved
+ IFileBuffer buffer = FileBuffers.getTextFileBufferManager()
+ .getFileBuffer(styleFile.getFullPath(),
+ LocationKind.NORMALIZE);
+ buffer.setDirty(false);
+
+ model.save();
} catch (IOException e) {
JspEditorPlugin.getPluginLog().logError(e.getMessage());
} catch (CoreException e) {
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java 2009-02-11
09:44:49 UTC (rev 13577)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java 2009-02-11
09:54:55 UTC (rev 13578)
@@ -11,9 +11,7 @@
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
@@ -23,10 +21,8 @@
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSModel;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
@@ -39,12 +35,6 @@
/** Editor in which we open visual page. */
protected final static String EDITOR_ID =
"org.eclipse.wst.css.core.csssource.source"; //$NON-NLS-1$
-
- /**
- * TODO remove the field
- * @deprecated
- */
- private StructuredTextEditor editor = null;
SourceViewer viewer = null;
private CSSModel cssModel = null;
@@ -67,71 +57,32 @@
* @param cssFile CSS file to be displayed in preview area
*/
public void initPreview(CSSModel cssModel) {
- this.cssModel = cssModel;
- if (cssModel != null) {
- IEditorInput input = new FileEditorInput(cssModel.getStyleFile());
-// try {
-// WorkbenchWindow workbenchWindow =
(WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-// EditorAreaHelper editorPresentation = new EditorAreaHelper((WorkbenchPage)
workbenchWindow.getActivePage());
-// EditorManager editorManager = new EditorManager(workbenchWindow, (WorkbenchPage)
workbenchWindow.getActivePage(), editorPresentation);
+ this.cssModel = cssModel;
+ if (cssModel != null) {
+ IEditorInput input = new FileEditorInput(cssModel.getStyleFile());
+ for (Control control : getChildren()) {
+ control.dispose();
+ }
-// IEditorReference ref = editorManager.openEditor(EDITOR_ID, input, true, null);
-// if (ref != null) {
- // all preview tab editors should be disposed before adding new editor compoment
- for (Control control : getChildren()) {
- control.dispose();
- }
-// if (editor != null) {
-// editor.doRevertToSaved();
-// editor.close(false);
-// }
-// editor = (StructuredTextEditor)ref.getEditor(true);
-// editor.createPartControl(this);
-// editor.getTextViewer().setEditable(false);
-
- SourceViewerConfiguration sourceViewerConfiguration = new
StructuredTextViewerConfiguration() {
- StructuredTextViewerConfiguration baseConfiguration = new
StructuredTextViewerConfigurationCSS();
+ StructuredTextViewerConfiguration baseConfiguration = new
StructuredTextViewerConfigurationCSS();
- public String[] getConfiguredContentTypes(
- ISourceViewer sourceViewer) {
- return baseConfiguration
- .getConfiguredContentTypes(sourceViewer);
- }
-
- public LineStyleProvider[] getLineStyleProviders(
- ISourceViewer sourceViewer, String partitionType) {
- return baseConfiguration.getLineStyleProviders(
- sourceViewer, partitionType);
- }
- };
- viewer = new StructuredTextViewer(this, null, null,
- false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ viewer = new StructuredTextViewer(this, null, null, false,
+ SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
((StructuredTextViewer) viewer).getTextWidget().setFont(
JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
-
- // IStructuredModel scratchModel =
- //
StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForCSS.ContentTypeID_CSS);
- // IDocument document = scratchModel.getStructuredDocument();
- viewer.configure(sourceViewerConfiguration);
+
+ viewer.configure(baseConfiguration);
viewer.setDocument(cssModel.getStructuredDocument());
viewer.setEditable(false);
-// }
- layout();
-// } catch (PartInitException e) {
-// e.printStackTrace();
-// }
- }
- }
+ layout();
+ }
+ }
public void doRevertToSaved() {
cssModel.reload();
-// if (editor != null) {
-// editor.doRevertToSaved();
-// }
-
}
/**
@@ -169,14 +120,11 @@
* @param save true if close editor with closure operation; false - otherwise
*/
public void closeEditor(boolean save) {
-// if (editor != null) {
-// editor.doRevertToSaved();
-// editor.close(save);
-// editor = null;
-// }
- if(!save)
- doRevertToSaved();
+ // TODO if copy of model is used then reverting will not be required
+ if (!save)
+ doRevertToSaved();
+
if (cssModel != null) {
cssModel.releaseModel();
}