Author: izhukov
Date: 2008-11-21 08:53:11 -0500 (Fri, 21 Nov 2008)
New Revision: 11945
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Selector.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ManualChangeStyleListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogEvent.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSStyleDialog.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/StyleComposite.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSConstants.java
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/Constants.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Util.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleEvent.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/TabPropertySheetMouseAdapter.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPropertySheetControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
Log:
CSS Style Dialog refactoring
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -46,6 +46,7 @@
public static String CSS_CLASS_DIALOG_FILE_LABEL;
public static String CSS_BROWSE_BUTTON_TOOLTIP;
public static String CSS_CLASS_DIALOG_STYLE_CLASS_LABEL;
+ public static String CSS_CLEAR_STYLE_SHEET;
public static String ADD_FONT_FAMILY_TIP;
public static String REMOVE_FONT_FAMILY_TIP;
public static String FONT_SIZE;
@@ -86,4 +87,6 @@
public static String COLOR_TIP;
public static String TEXT_DECORATION;
public static String TEXT_ALIGN;
+ public static String BUTTON_CLEAR;
+ public static String PREVIEW_SHEET_TAB_NAME;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2008-11-21
13:53:11 UTC (rev 11945)
@@ -8,10 +8,13 @@
CSS_CLASS_DIALOG_STYLE_CLASS_LABEL=Style class:
CSS_BROWSE_BUTTON_TOOLTIP=Browse
+CSS_CLEAR_STYLE_SHEET=Clear style sheet
+
ADD_FONT_FAMILY_TIP=Add font family
REMOVE_FONT_FAMILY_TIP=Remove font family
FONT_FAMILY_DIALOG_TITLE=Choose font family
+BUTTON_CLEAR=Clear
IMAGE_COMBO_TABLE_TOOL_TIP=Double click to select color
@@ -35,6 +38,7 @@
BOXES_TAB_NAME=Boxes
PROPERTY_SHEET_TAB_NAME=Property Sheet
QUICK_EDIT_TAB_NAME=Quick Edit
+PREVIEW_SHEET_TAB_NAME=Preview
TEXT_DECORATION=Text Decoration:
TEXT_ALIGN=Text Align:
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -28,129 +28,158 @@
import org.jboss.tools.jst.jsp.drop.treeviewer.model.RootElement;
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSStyleDialog;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
/**
* @author Kabanovich Cell Editor for JSP attributes, of which values can be
* provided by prompting knoledgebase.
*/
+public class JSPDialogCellEditor extends DialogCellEditorEx implements
ExtendedCellEditorProvider.StoppableCellEditor {
+ Properties context;
-public class JSPDialogCellEditor extends DialogCellEditorEx implements
- ExtendedCellEditorProvider.StoppableCellEditor {
- Properties context;
// ValueHelper valueHelper;
JSPDialogCellEditorContentAssistProcessor contentAssistentProcessor;
ContentAssistHandler handler = null;
-
boolean hasProposals = false;
-
+ /**
+ * Constructor.
+ * @param parent
+ * @param context
+ */
public JSPDialogCellEditor(Composite parent, Properties context) {
- super(parent);
- this.context = context;
- ValueHelper valueHelper = (ValueHelper) context.get("valueHelper");
+ super(parent);
+ this.context = context;
- contentAssistentProcessor = new JSPDialogCellEditorContentAssistProcessor();
- if (valueHelper != null)
- contentAssistentProcessor.setContext(context);
- handler = ContentAssistHandler.createHandlerForText(getTextField(),
- ControlContentAssistHelper
- .createJavaContentAssistant(contentAssistentProcessor));
+ ValueHelper valueHelper = (ValueHelper) context.get("valueHelper");
+
+ contentAssistentProcessor = new JSPDialogCellEditorContentAssistProcessor();
+
+ if (valueHelper != null) {
+ contentAssistentProcessor.setContext(context);
+ }
+
+ handler = ContentAssistHandler.createHandlerForText(getTextField(),
+
ControlContentAssistHelper.createJavaContentAssistant(contentAssistentProcessor));
}
public void activate() {
- checkHasProposals();
- checkButtonEnablement();
- super.activate();
+ checkHasProposals();
+ checkButtonEnablement();
+ super.activate();
}
- void checkHasProposals() {
- hasProposals = false;
- if (context == null)
- return;
- // valueHelper = (ValueHelper)context.get("valueHelper");
- // if(valueHelper == null) return;
- ValueHelper valueHelper = new ValueHelper();
- String attributeName = "" + context.getProperty("attributeName");
- String nodeName = "" + context.getProperty("nodeName");
- String query = "/";
- if (valueHelper.isFacetets() && nodeName.indexOf(':') < 0) {
- query += FaceletsHtmlContentAssistProcessor.faceletHtmlPrefixStart;
- }
- query += nodeName + "@" + attributeName;
- RootElement root = (RootElement) valueHelper.getInitalInput(query);
- hasProposals = (root != null && root.getChildren().length > 0) ||
attributeName.equals("style");
+ private void checkHasProposals() {
+ hasProposals = false;
+
+ if (context == null) {
+ return;
+ }
+
+ // valueHelper = (ValueHelper)context.get("valueHelper");
+ // if(valueHelper == null) return;
+ ValueHelper valueHelper = new ValueHelper();
+ String attributeName = Constants.EMPTY +
context.getProperty("attributeName");
+ String nodeName = Constants.EMPTY + context.getProperty("nodeName");
+ String query = Constants.SLASH;
+
+ if (valueHelper.isFacetets() && (nodeName.indexOf(':') < 0))
{
+ query += FaceletsHtmlContentAssistProcessor.faceletHtmlPrefixStart;
+ }
+
+ query += (nodeName + "@" + attributeName);
+
+ RootElement root = (RootElement) valueHelper.getInitalInput(query);
+ hasProposals = ((root != null) && (root.getChildren().length > 0))
+ || attributeName.equalsIgnoreCase(CSSConstants.STYLE)
+ || attributeName.equalsIgnoreCase(CSSConstants.CLASS);
}
private void checkButtonEnablement() {
- if (context == null)
- return;
- // valueHelper = (ValueHelper)context.get("valueHelper");
- // if(valueHelper == null) return;
- ValueHelper valueHelper = new ValueHelper();
- Button button = getButtonControl();
- if (button == null || button.isDisposed())
- return;
- button.setVisible(hasProposals);
- handler.setEnabled(hasProposals);
+ if (context == null) {
+ return;
+ }
+
+// valueHelper = (ValueHelper)context.get("valueHelper");
+// if(valueHelper == null) return;
+// ValueHelper valueHelper = new ValueHelper();
+ Button button = getButtonControl();
+
+ if ((button == null) || button.isDisposed()) {
+ return;
+ }
+
+ button.setVisible(hasProposals);
+ handler.setEnabled(hasProposals);
}
protected Object openDialogBox(Control cellEditorWindow) {
- externalEditing = true;
- String attributeName = "" + context.getProperty("attributeName");
- String nodeName = "" + context.getProperty("nodeName");
- String query = "/";
- ValueHelper valueHelper = new ValueHelper();
- if (valueHelper != null && valueHelper.isFacetets()
- && nodeName.indexOf(":") < 0) {
- query += FaceletsHtmlContentAssistProcessor.faceletHtmlPrefixStart;
- }
- query += nodeName + "@" + attributeName;
- context.setProperty("query", query);
- context.setProperty("help", query);
- context.setProperty("title", "Edit "
- + WizardKeys.toDisplayName(attributeName));
- context.setProperty("subtitle", "<" +
context.getProperty("nodeName")
- + ">");
+ externalEditing = true;
- String value = (getValue() instanceof String) ? getValue().toString()
- : getValue() instanceof AttributeWrapper ? ((AttributeWrapper) getValue()).value
- : "";
+ String attributeName = Constants.EMPTY +
context.getProperty("attributeName");
+ String nodeName = Constants.EMPTY + context.getProperty("nodeName");
+ String query = Constants.SLASH;
+ ValueHelper valueHelper = new ValueHelper();
- context.put("value", value);
- if (attributeName.equals("style") ||
attributeName.endsWith("Style")) {
- CSSStyleDialog dialog = new CSSStyleDialog(cellEditorWindow.getShell(), (value ==
null ? ""
- : value));
- if (dialog.open() == Window.OK) {
- externalEditing = false;
- return dialog.getNewStyle();
-
- }
- } else if (attributeName.endsWith("Class") ||
attributeName.endsWith("class") ) {
- CSSClassDialog dialog = new CSSClassDialog(cellEditorWindow.getShell(),false);
- if (dialog.open() == Window.OK) {
- externalEditing = false;
- return dialog.getSelectorName();
- }
- }
- else {
+ if ((valueHelper != null) && valueHelper.isFacetets() &&
(nodeName.indexOf(Constants.COLON) < 0)) {
+ query += FaceletsHtmlContentAssistProcessor.faceletHtmlPrefixStart;
+ }
- JSPTreeDialog dialog = new JSPTreeDialog();
- dialog.setObject(context);
- if (dialog.execute() != 0) {
- externalEditing = false;
- return null;
- }
- }
- externalEditing = false;
- value = context.getProperty("value");
- return value;
+ query += (nodeName + "@" + attributeName);
+ context.setProperty("query", query);
+ context.setProperty("help", query);
+ context.setProperty("title", "Edit " +
WizardKeys.toDisplayName(attributeName));
+ context.setProperty("subtitle", "<" +
context.getProperty("nodeName") + ">");
+
+ String value = (getValue() instanceof String) ? getValue().toString()
+ : ((getValue() instanceof
AttributeWrapper)
+ ? ((AttributeWrapper) getValue()).value : Constants.EMPTY);
+
+ context.put("value", value);
+
+ if (attributeName.equalsIgnoreCase(CSSConstants.STYLE)
+ || attributeName.endsWith(CSSConstants.STYLE.toLowerCase())) {
+ CSSStyleDialog dialog = new CSSStyleDialog(cellEditorWindow.getShell(),
+ ((value == null) ? Constants.EMPTY : value));
+
+ if (dialog.open() == Window.OK) {
+ externalEditing = false;
+
+ return dialog.getNewStyle();
+ }
+ } else if (attributeName.equalsIgnoreCase(CSSConstants.CLASS)
+ || attributeName.endsWith(CSSConstants.CLASS.toLowerCase())) {
+ CSSClassDialog dialog = new CSSClassDialog(cellEditorWindow.getShell(), null,
false);
+ dialog.setCurrentStyleClass(value);
+
+ if (dialog.open() == Window.OK) {
+ externalEditing = false;
+
+ return dialog.getSelectorName();
+ }
+ } else {
+ JSPTreeDialog dialog = new JSPTreeDialog();
+ dialog.setObject(context);
+
+ if (dialog.execute() != 0) {
+ externalEditing = false;
+
+ return null;
+ }
+ }
+
+ externalEditing = false;
+ value = context.getProperty("value");
+
+ return value;
}
public void stopEditing() {
- super.fireApplyEditorValue();
+ super.fireApplyEditorValue();
}
protected Text getTextField() {
- return text;
+ return text;
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPPropertySourceAdapter.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -157,7 +157,9 @@
} else {
if (namesLow.contains(attrName.toLowerCase())) continue;
}
- if(valueHelper.isAvailable(getQuery(attrName)) || attrName.equals("style"))
{
+ if(valueHelper.isAvailable(getQuery(attrName))
+ || attrName.equals("style")
+ || attrName.equals("class")) {
descriptor = createJSPPropertyDescriptor(d, attrName, false);
} else {
descriptor = createTextPropertyDescriptor(attrName, CATEGORY_ATTRIBUTES, 0);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -10,27 +10,37 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -39,69 +49,195 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.jboss.tools.common.model.ui.widgets.Split;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
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.common.Constants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.FileExtensionFilter;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Selector;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
/**
* This dialog represents CSSClass dialog.
*/
-public class CSSClassDialog extends Dialog {
+public class CSSClassDialog extends TitleAreaDialog implements MouseListener,
FocusListener {
- final static int MIN_HEIGHT_FOR_BROWSER = 60;
+ // TODO: take out to the property manager file
+ public final static String WIZARD_TITLE = "CSS Class";
+ public final static String WIZARD_DESCRIPTION = "Create New CSS Class.";
+ public final static String EMPTY_CSS_FILE_PATH_MESSAGE = "Choose any CSS
file";
+ public final static String EMPTY_STYLE_CLASS_MESSAGE = "Style class is
empty";
- final static String[] fileExtensions = { "css" }; //$NON-NLS-1$
+ private static final String CSS_FILE_EXTENTION = "css"; //$NON-NLS-1$
+ final static String[] fileExtensions = { CSS_FILE_EXTENTION };
final static String SKIP_FIRST_CHAR = "."; //$NON-NLS-1$
+ private Composite browserContainer = null;
private Browser browser = null;
+ private Text textBrowser = null;
+ private String previewBrowserValue = Constants.TEXT_FOR_PREVIEW;
+
private StyleComposite styleComposite = null;
private StyleAttributes styleAttributes = null;
+ // css file path
private Text text;
- private IFile file;
+ // css style classes
private Combo classCombo;
+
+ // model is the core of the CSS Class Dialog, it manages style attributes
private CSSModel cssModel;
- private String selectorName;
- private boolean allProject;
+ // file is "current" in case of the following priority order:
+ // 1 - this is selected css file in eclipse project tree
+ // 2 - this is opened and active css file
+ private IFile currentFile;
+ private String currentClassStyle = null;
+
+ // workbench selection when the wizard was started
+ protected IStructuredSelection selection;
+
+ private boolean styleChanged = false;
+
+ // Status variables for the possible errors on this page.
+ // 1. timeStatus holds an error if CSS file is not specified
+ private IStatus filePathStatus = null;
+ // 2. holds an error if the destination class style is empty
+ private IStatus classNameStatus = null;
+
+ // an array of subscribed message dialog listener
+ private ArrayList<MessageDialogListener> errorListeners = new
ArrayList<MessageDialogListener>();
+
+ private final boolean callFromWizard;
+
/**
* Constructor.
*
* @param parentShell Shell object
* @param allProject (if allProject is true - browse css file in all projects, else
only in current project)
+ * @param callFromWizard indicates if CSS dialog is created within Wizard page
*/
- public CSSClassDialog(Shell parentShell, boolean allProject) {
+ public CSSClassDialog(Shell parentShell, IStructuredSelection selection, boolean
callFromWizard) {
super(parentShell);
- this.allProject = allProject;
+
setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
+
+ filePathStatus = new Status(IStatus.ERROR, "not_used", 0,
EMPTY_CSS_FILE_PATH_MESSAGE, null); //$NON-NLS-1$
+ classNameStatus = new Status(IStatus.ERROR, "not_used", 0,
EMPTY_STYLE_CLASS_MESSAGE, null); //$NON-NLS-1$
+
styleAttributes = new StyleAttributes();
+ this.callFromWizard = callFromWizard;
+ this.selection = selection;
+ init();
}
/**
+ * Initialize method.
+ */
+ private void init() {
+ if (selection != null && !selection.isEmpty()) {
+ for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
+ Object element = iterator.next();
+ if (element instanceof IResource) {
+ if (element instanceof IFile) {
+ if (((IFile) element).getName().toLowerCase().endsWith(CSS_FILE_EXTENTION)) {
+ currentFile = (IFile)element;
+ }
+ }
+ }
+ }
+ }
+ // if any CSS file is currently opened and has active page status this method should
return style class
+ // within this file where cursor is located
+ if (currentFile == null) {
+ currentFile = Util.getActiveCssFile();
+ currentClassStyle = Util.getActivePageCSSSelectorIfAny();
+ }
+ }
+
+ /**
+ * Sets current style class value.
+ *
+ * @param currentClassStyle String value
+ */
+ public void setCurrentStyleClass(String currentClassStyle) {
+ if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY))
{
+ String[] styleClasses = currentClassStyle.split("\\s++"); //$NON-NLS-1$
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < styleClasses.length; i++) {
+ String value = styleClasses[i];
+ // check if first symbol doesn't specify some special CSS symbols
+ if (!value.startsWith("#")) { //$NON-NLS-1$
+ sb.append(SKIP_FIRST_CHAR);
+ }
+ sb.append(value);
+ if (i != (styleClasses.length - 1)) {
+ sb.append(Constants.WHITE_SPACE);
+ }
+ }
+ this.currentClassStyle = sb.toString().trim();
+ }
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
+ */
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ final Composite composite = (Composite) super.createDialogArea(parent);
+ return createDialogComposite(composite);
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ updateOKButtonState();
+ }
+
+ /**
* Create the dialog itself.
*
* @param composite parent window
* @return eclipse Control object
*/
public Control createDialogComposite(Composite composite) {
- GridLayout layout = new GridLayout();
+ if (!this.callFromWizard) {
+ setTitle(WIZARD_TITLE);
+ setMessage(WIZARD_DESCRIPTION);
+ }
+
+ Split split = new Split(composite, SWT.VERTICAL);
+
+ GridLayout layout = new GridLayout();
layout.numColumns = 1;
composite.setLayout(layout);
- browser = new Browser(composite, SWT.BORDER);
+ // initialize browser container
+ browserContainer = getCompositeElement(split);
+ createBrowserComponent();
+
/* ============================================= */
- Composite classComposite = new Composite(composite, SWT.BORDER);
- GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
+ Composite downSplitPane = getCompositeElement(split);
+ Color veryLightGray = new Color(null, 127, 127, 127);
+ downSplitPane.setForeground(veryLightGray);
+
+ Composite classComposite = new Composite(downSplitPane, SWT.BORDER);
+ GridData gridData = new GridData(GridData.FILL, GridData.BEGINNING, true,
false);
classComposite.setLayoutData(gridData);
final GridLayout gridLayout = new GridLayout();
@@ -112,38 +248,26 @@
label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
label.setText(JstUIMessages.CSS_CLASS_DIALOG_FILE_LABEL);
+ // Text field contains path to the CSS file
text = new Text(classComposite, SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ text.setEditable(false);
text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- IResource res = null;
- if (allProject) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- res = workspace.getRoot().findMember(text.getText());
- } else {
- IProject project = Util.getCurrentProject();
+ @Override
+ public void modifyText(ModifyEvent e) {
+ String cssFile = text.getText().trim();
+ // Initialize a variable with the no error status
+ filePathStatus = new Status(IStatus.ERROR, "not_used", 0,
EMPTY_CSS_FILE_PATH_MESSAGE, null); //$NON-NLS-1$
+ if (cssFile != null && !cssFile.equals(Constants.EMPTY)) {
+ filePathStatus = new Status(IStatus.OK, "not_used", 0,
WIZARD_DESCRIPTION, null); //$NON-NLS-1$
+ }
+ // show corresponding message
+ IStatus status = findMostSevere();
+ notifyListeners(text, status);
+ applyToStatusLine(status);
+ }
+ });
- if (project != null) {
- res = project.findMember(text.getText());
- }
- }
-
- if (res != null) {
- if (res instanceof IFile) {
- file = (IFile) res;
- cssModel = new CSSModel(file);
- classCombo.removeAll();
-
- List<String> selectors = cssModel.getSelectors();
-
- for (String selector : selectors) {
- classCombo.add(selector);
- }
- }
- }
- }
- });
-
Button button = new Button(classComposite, SWT.PUSH);
button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
@@ -159,30 +283,50 @@
});
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- IAdaptable project = ResourcesPlugin.getWorkspace();
+ IResource project = Util.getCurrentProject();
- if (!allProject) {
- project = Util.getCurrentProject();
- }
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
+ new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
+ dialog.addFilter(new FileExtensionFilter(fileExtensions));
+ dialog.setTitle(JstUIMessages.CSS_FILE_SELECT_DIALOG_TITLE);
+ dialog.setMessage(JstUIMessages.CSS_FILE_SELECT_DIALOG_LABEL);
+ dialog.setInput(project);
+ dialog.setAllowMultiple(false);
+ dialog.setDoubleClickSelects(false);
+ dialog.setEmptyListMessage(JstUIMessages.CSS_FILE_SELECT_DIALOG_EMPTY_MESSAGE);
- ElementTreeSelectionDialog dialog = new
ElementTreeSelectionDialog(getShell(),
- new WorkbenchLabelProvider(), new
BaseWorkbenchContentProvider());
- dialog.addFilter(new FileExtensionFilter(fileExtensions));
- dialog.setTitle(JstUIMessages.CSS_FILE_SELECT_DIALOG_TITLE);
- dialog.setMessage(JstUIMessages.CSS_FILE_SELECT_DIALOG_LABEL);
- dialog.setInput(project);
- dialog.setAllowMultiple(false);
-
dialog.setEmptyListMessage(JstUIMessages.CSS_FILE_SELECT_DIALOG_EMPTY_MESSAGE);
-
- if (dialog.open() == Window.OK) {
- IResource res = (IResource) dialog.getFirstResult();
-
- if (allProject) {
- text.setText(res.getFullPath().toOSString());
- } else {
- text.setText(res.getProjectRelativePath().toOSString());
- }
- }
+ if (dialog.open() == Window.OK) {
+ // make some important saving actions
+ if (styleChanged && currentFile != null) {
+ MessageBox messageBox = new MessageBox(getParentShell(), SWT.YES | SWT.NO
| SWT.ICON_QUESTION);
+ messageBox.setText("Save CSS file");
+ messageBox.setMessage("'" + currentFile + "'"
+ //$NON-NLS-1$ //$NON-NLS-2$
+ " CSS file has been changed.\nWould you like to save
changes?");
+ int result = messageBox.open();
+ if (result == SWT.YES) {
+ saveChanges();
+ } else {
+ styleComposite.closePreview(false);
+ if (cssModel != null) {
+ cssModel.releaseModel();
+ }
+ updateStyleComposite();
+ styleComposite.updatePreviewCssFile(currentFile);
+ }
+ }
+ // open new CSS file and initialize dialog
+ IResource res = (IResource) dialog.getFirstResult();
+ if (res instanceof IFile) {
+ boolean useRelativePath = true;
+ if (project instanceof IWorkspaceRoot) {
+ useRelativePath = false;
+ }
+ currentFile = (IFile)res;
+ initCSSModel(currentFile, useRelativePath);
+ updateOKButtonState();
+ }
+ styleChanged = false;
+ }
}
});
@@ -192,67 +336,319 @@
gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
gridData.horizontalSpan = 2;
+
+// classCombo = new ComboViewer(classComposite, SWT.BORDER);
classCombo = new Combo(classComposite, SWT.BORDER);
classCombo.setLayoutData(gridData);
+ classCombo.setEnabled(false);
+// classCombo.setLabelProvider(new LabelProvider() {
+// @Override
+// public String getText(Object element) {
+// return ((Selector)element).getValue();
+// }
+// });
+// classCombo.addSelectionChangedListener(new ISelectionChangedListener() {
+// public void widgetSelected(SelectionEvent e) {
+// if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
+// if (styleChanged) {
+// if (currentClassStyle != null &&
!currentClassStyle.equals(Constants.EMPTY)) {
+// String newStyle = styleComposite.updateStyle();
+// if (newStyle != null) {
+// cssModel.setCSS(currentClassStyle, newStyle);
+// // update ComboBox element list
+// int currentIndex = classCombo.indexOf(currentClassStyle);
+// if (currentIndex == -1) {
+// classCombo.add(currentClassStyle);
+// }
+// }
+// }
+// }
+// // update current class style value
+// currentClassStyle = classCombo.getText();
+// updateStyleComposite();
+// updateOKButtonState();
+// styleChanged = false;
+// } else {
+// currentClassStyle = classCombo.getText();
+// }
+// }
+// @Override
+// public void selectionChanged(SelectionChangedEvent event) {
+// if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
+// if (styleChanged) {
+// if (currentClassStyle != null &&
!currentClassStyle.equals(Constants.EMPTY)) {
+// String newStyle = styleComposite.updateStyle();
+// if (newStyle != null) {
+// cssModel.setCSS(currentClassStyle, newStyle);
+// // update ComboBox element list
+// int currentIndex = classCombo.getCombo().indexOf(currentClassStyle);
+// if (currentIndex == -1) {
+// classCombo.add(currentClassStyle);
+// }
+// }
+// }
+// }
+// // update current class style value
+// currentClassStyle = classCombo.getInput() != null ?
classCombo.getInput().toString() : null;
+// updateStyleComposite();
+// updateOKButtonState();
+// styleChanged = false;
+// } else {
+// currentClassStyle = classCombo.getInput().toString();
+// }
+// }
+// });
- classCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- String style = cssModel.getStyle(classCombo.getText());
-
classCombo.setToolTipText(cssModel.getCSSText(classCombo.getText()));
- styleComposite.recreateStyleComposite(style);
- }
- });
+ classCombo.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
+ if (styleChanged) {
+ if (currentClassStyle != null &&
!currentClassStyle.equals(Constants.EMPTY)) {
+ String newStyle = styleComposite.updateStyle();
+ if (newStyle != null) {
+ cssModel.setCSS(currentClassStyle, newStyle);
+ // update ComboBox element list
+ int currentIndex = classCombo.indexOf(currentClassStyle);
+ if (currentIndex == -1) {
+ classCombo.add(currentClassStyle);
+ }
+ }
+ }
+ }
+ // update current class style value
+ currentClassStyle = classCombo.getText();
+ updateStyleComposite();
+ updateOKButtonState();
+ styleChanged = false;
+ } else {
+ currentClassStyle = classCombo.getText();
+ }
+ }
+ });
+ classCombo.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ // update current class style value
+ currentClassStyle = classCombo.getText().trim();
+ updateOKButtonState();
+ }
+ });
+ classCombo.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ String cssClass = classCombo.getText().trim();
+ // Initialize a variable with the no error status
+ classNameStatus = new Status(IStatus.ERROR, "not_used", 0,
EMPTY_STYLE_CLASS_MESSAGE, null); //$NON-NLS-1$
+ if (cssClass != null && !cssClass.equals(Constants.EMPTY)) {
+ classNameStatus = new Status(IStatus.OK, "not_used", 0,
WIZARD_DESCRIPTION, null); //$NON-NLS-1$
+ }
+ // show corresponding message
+ IStatus status = findMostSevere();
+ notifyListeners(classCombo, status);
+ applyToStatusLine(status);
+ }
+ });
/* ============================================ */
styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
public void styleChanged(ChangeStyleEvent event) {
- String styleForSpan = Constants.EMPTY;
- String html = Constants.EMPTY;
-
- Set<String> keySet = styleAttributes.keySet();
- for (String key : keySet) {
- styleForSpan += (key + Constants.COLON +
styleAttributes.getAttribute(key) +
- Constants.SEMICOLON);
- }
-
- html = Constants.OPEN_DIV_TAG + styleForSpan +
Constants.TEXT_FOR_PREVIEW +
- Constants.CLOSE_DIV_TAG;
- browser.setText(html);
+ if (!browser.isDisposed()) {
+ browser.setText(getTextForBrowser());
+ }
+ if (cssModel != null && currentClassStyle != null) {
+
classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
+ }
}
});
- styleComposite = new StyleComposite(composite, styleAttributes,
Constants.EMPTY);
+ // create style composite component
+ styleComposite = new StyleComposite(downSplitPane, styleAttributes,
Constants.EMPTY);
+ styleComposite.addManualChangeStyleListener(new ManualChangeStyleListener() {
+ public void styleChanged(ChangeStyleEvent event) {
+ styleChanged = true;
+ if (currentClassStyle != null &&
!currentClassStyle.equals(Constants.EMPTY)
+ && currentFile != null &&
!currentFile.equals(Constants.EMPTY)) {
+ String newStyle = styleComposite.updateStyle();
+ if (newStyle != null) {
+ cssModel.setCSS(currentClassStyle, newStyle);
+ }
+ }
+ }
+ });
- gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- gridData.minimumHeight = MIN_HEIGHT_FOR_BROWSER;
- browser.setLayoutData(gridData);
+ // add clear button
+ Button clearButton = new Button(downSplitPane, SWT.PUSH);
+ clearButton.setText(JstUIMessages.BUTTON_CLEAR);
+ clearButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
false));
+ clearButton.setToolTipText(JstUIMessages.CSS_CLEAR_STYLE_SHEET);
+ clearButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ styleComposite.clearStyleComposite();
+ styleChanged = true;
+ }
+ });
+ if (currentFile != null) {
+ initCSSModel(currentFile, true);
+ } else if (currentClassStyle != null) {
+ classCombo.setText(currentClassStyle);
+ }
+
+ split.setWeights(new int[]{15, 85});
+ split.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true,
true));
+
return composite;
}
- public void saveChanges() {
- styleComposite.updateStyle();
+ /**
+ * Initialize CSS model with active opened CSS file.
+ *
+ * @param file IFile object
+ * @param useRelativePathPath
+ */
+ private void initCSSModel(IFile file, boolean useRelativePathPath) {
+ if (file != null) {
+ // create CSS Model
+ cssModel = new CSSModel(file);
+ classCombo.setEnabled(true);
+ classCombo.removeAll();
+ boolean useCurrentStyleSettings = false;
+ if (text.getText() == null || text.getText().equals(Constants.EMPTY)) {
+ useCurrentStyleSettings = true;
+ }
+ if (useRelativePathPath) {
+ text.setText(file.getProjectRelativePath().toOSString());
+ } else {
+ text.setText(file.getFullPath().toOSString());
+ }
- String newStyle = styleComposite.getNewStyle();
- cssModel.setCSS(classCombo.getText(), newStyle);
- cssModel.saveModel();
+ List<Selector> selectors = cssModel.getSelectors();
+ int selectedIndex = -1;
+ for (int i = 0; i < selectors.size(); i++) {
+ Selector value = selectors.get(i);
+ classCombo.add(value.getValue());
+ if (currentClassStyle != null &&
currentClassStyle.equals(value.getValue())) {
+ selectedIndex = i;
+ }
+ }
+// if (useCurrentStyleSettings && currentClassStyle != null &&
selectedIndex == -1) {
+// classCombo.setText(currentClassStyle);
+// } else {
+// classCombo.select(selectedIndex);
+// }
+// if (currentClassStyle != null) {
+// classCombo.setInput(currentClassStyle);
+// }
+ classCombo.select(selectedIndex);
+
+ updateStyleComposite();
+ styleComposite.updatePreviewCssFile(currentFile);
+ }
}
- public String getSelectorName() {
- return selectorName;
+ /**
+ * Method return the most serious error occurs on the page and that should be
displayed.
+ *
+ * @return IStatus object
+ */
+ private IStatus findMostSevere() {
+ if (filePathStatus.matches(IStatus.ERROR)) {
+ return filePathStatus;
+ }
+ if (classNameStatus.matches(IStatus.ERROR)) {
+ return classNameStatus;
+ }
+ if (filePathStatus.getSeverity() > classNameStatus.getSeverity()) {
+ return filePathStatus;
+ }
+ else return classNameStatus;
+ }
+
+ /**
+ * This method takes affect to OK button when dialog is opened in "dialog"
mode and not in "wizard".
+ * In case of "wizard" mode OK button is not available.
+ */
+ private void updateOKButtonState() {
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ if (okButton != null) {
+ if (currentClassStyle == null || currentClassStyle.equals(Constants.EMPTY) ||
currentFile == null) {
+ okButton.setEnabled(false);
+ } else {
+ okButton.setEnabled(true);
+ }
+ }
}
/**
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
+ * Method is used to create browser component to display preview html.
*/
- @Override
- protected Control createDialogArea(final Composite parent) {
- final Composite composite = (Composite) super.createDialogArea(parent);
- return createDialogComposite(composite);
+ private void createBrowserComponent() {
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ browser = new Browser(browserContainer, SWT.BORDER | SWT.MOZILLA);
+ browser.setText(getTextForBrowser());
+ browser.addMouseListener(this);
+ browser.setLayoutData(gridData);
}
/**
+ * Update style composite component in accordance with the attributes of selected CSS
selector.
+ */
+ private void updateStyleComposite() {
+ String style = cssModel.getStyle(currentClassStyle);
+// classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
+ styleComposite.recreateStyleComposite(style);
+ }
+
+ /**
+ * Method is used to build html body that is appropriate to browse.
+ *
+ * @return String html text representation
+ */
+ private String getTextForBrowser() {
+ String styleForSpan = Constants.EMPTY;
+ Set<String> keySet = styleAttributes.keySet();
+ for (String key : keySet) {
+ styleForSpan += (key + Constants.COLON + styleAttributes.getAttribute(key) +
Constants.SEMICOLON);
+ }
+ String html = Constants.OPEN_DIV_TAG + styleForSpan + "\">" +
previewBrowserValue + Constants.CLOSE_DIV_TAG; //$NON-NLS-1$
+
+ return html;
+ }
+
+ /**
+ * Create container that take up 2 cells and contains fontSizeCombo and
extFontSizeCombo elements.
+ */
+ private Composite getCompositeElement(Composite parent) {
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ GridLayout gridLayoutTmp = new GridLayout();
+ gridLayoutTmp.marginHeight = 0;
+ gridLayoutTmp.marginWidth = 0;
+ Composite classComposite = new Composite(parent, SWT.FILL);
+ classComposite.setLayout(gridLayoutTmp);
+ classComposite.setLayoutData(gridData);
+
+ return classComposite;
+ }
+
+ /**
+ * Method should be called in case of dialog closure operation.
+ */
+ public void saveChanges() {
+ String newStyle = styleComposite.updateStyle();
+ cssModel.setCSS(currentClassStyle, newStyle);
+ cssModel.saveModel();
+ styleComposite.closePreview(true);
+ }
+
+ /**
+ * Gets current selected style class value.
+ *
+ * @return selector name
+ */
+ public String getSelectorName() {
+ return currentClassStyle;
+ }
+
+ /**
* Method for setting title for dialog
*
* @param newShell Shell object
@@ -265,18 +661,150 @@
}
/**
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ * This method close the dialog.
+ *
+ * @return true if dialog was closed, false - otherwise
*/
- @Override
- protected void okPressed() {
- saveChanges();
+ public boolean closeDialog() {
+ setReturnCode(Window.CANCEL);
+ return close();
+ }
- String sel = classCombo.getText();
- if (sel.trim().startsWith(SKIP_FIRST_CHAR)) {
- sel = sel.substring(1);
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ */
+ public boolean close() {
+ int code = getReturnCode();
+ switch (code) {
+ case OK:
+ saveChanges();
+ super.okPressed();
+ break;
+ case CANCEL:
+ default:
+ // make some closure operation
+ styleComposite.closePreview(false);
+ if (cssModel != null) {
+ cssModel.releaseModel();
+ }
+ }
+ return super.close();
+ }
+
+ /**
+ * @see
org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
+ */
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ if (e.widget == browser) {
+ browser.removeMouseListener(this);
+ browser.dispose();
+ // create Text area component instead of HTML Browser
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ textBrowser = new Text(browserContainer, SWT.MULTI | SWT.V_SCROLL |
SWT.H_SCROLL);
+ textBrowser.setText(previewBrowserValue);
+ textBrowser.addFocusListener(this);
+ textBrowser.setLayoutData(gridData);
+ textBrowser.setEditable(true);
+ textBrowser.setFocus();
+ }
+ browserContainer.layout();
+ }
+
+ /**
+ * @see
org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
+ */
+ @Override
+ public void focusLost(FocusEvent e) {
+ if (e.widget == textBrowser) {
+ previewBrowserValue = textBrowser.getText();
+ textBrowser.removeFocusListener(this);
+ textBrowser.dispose();
+ // create Browse component instead of text area
+ createBrowserComponent();
+ }
+ browserContainer.layout();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
+ */
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
+ */
+ @Override
+ public void mouseUp(MouseEvent e) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
+ */
+ @Override
+ public void focusGained(FocusEvent e) {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * Add MessageDialogListener object.
+ *
+ * @param listener MessageDialogListener object to be added
+ */
+ public void addMessageDialogListener(MessageDialogListener listener) {
+ errorListeners.add(listener);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeMessageDialogListener(MessageDialogListener listener) {
+ errorListeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about possible any errors on the
page.
+ */
+ private void notifyListeners(Object source, IStatus operationStatus) {
+ MessageDialogEvent event = new MessageDialogEvent(source, operationStatus);
+ for (MessageDialogListener listener : errorListeners) {
+ listener.throwMessage(event);
}
+ }
- selectorName = sel;
- super.okPressed();
- }
+ /**
+ * Applies the status to the status line of a dialog page.
+ */
+ private void applyToStatusLine(IStatus status) {
+ if (!callFromWizard) {
+ String message= status.getMessage();
+ if (message.length() == 0) {
+ message = null;
+ }
+ switch (status.getSeverity()) {
+ case IStatus.OK:
+ setErrorMessage(null);
+ setMessage(message);
+ break;
+ case IStatus.WARNING:
+ setErrorMessage(null);
+ setMessage(message, WizardPage.WARNING);
+ break;
+ case IStatus.INFO:
+ setErrorMessage(null);
+ setMessage(message, WizardPage.INFORMATION);
+ break;
+ default:
+ setErrorMessage(message);
+ setMessage(null);
+ break;
+ }
+ }
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSStyleDialog.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSStyleDialog.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSStyleDialog.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -37,6 +37,8 @@
final static int MIN_HEIGHT_FOR_BROWSER = 60;
+ private String previewBrowserValue = Constants.TEXT_FOR_PREVIEW;
+
private Browser browser = null;
private StyleComposite styleComposite = null;
private StyleAttributes styleAttributes = null;
@@ -73,17 +75,7 @@
styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
public void styleChanged(ChangeStyleEvent event) {
- String styleForSpan = Constants.EMPTY;
- String html = Constants.EMPTY;
-
- Set<String> keySet = styleAttributes.keySet();
- for (String key : keySet) {
- styleForSpan += (key + Constants.COLON +
styleAttributes.getAttribute(key) +
- Constants.SEMICOLON);
- }
- html = Constants.OPEN_DIV_TAG + styleForSpan +
Constants.TEXT_FOR_PREVIEW +
- Constants.CLOSE_DIV_TAG;
- browser.setText(html);
+ browser.setText(getTextForBrowser());
}
});
styleComposite = new StyleComposite(composite, styleAttributes, oldStyle);
@@ -91,11 +83,28 @@
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
gridData.minimumHeight = MIN_HEIGHT_FOR_BROWSER;
browser.setLayoutData(gridData);
+ browser.setText(getTextForBrowser());
return composite;
}
/**
+ * Method is used to build html body that is appropriate to browse.
+ *
+ * @return String html text representation
+ */
+ private String getTextForBrowser() {
+ String styleForSpan = Constants.EMPTY;
+ Set<String> keySet = styleAttributes.keySet();
+ for (String key : keySet) {
+ styleForSpan += (key + Constants.COLON + styleAttributes.getAttribute(key) +
Constants.SEMICOLON);
+ }
+ String html = Constants.OPEN_DIV_TAG + styleForSpan + "\">" +
previewBrowserValue + Constants.CLOSE_DIV_TAG;
+
+ return html;
+ }
+
+ /**
* Method for setting title for dialog
*
* @param newShell Shell object
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/StyleComposite.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/StyleComposite.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/StyleComposite.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -16,6 +16,7 @@
import java.util.Set;
import java.util.Map.Entry;
+import org.eclipse.core.resources.IFile;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
@@ -28,6 +29,7 @@
import org.eclipse.swt.widgets.TabItem;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.BaseListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.CSSElementsParser;
@@ -36,6 +38,7 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ParserListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabBackgroundControl;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabBoxesControl;
+import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabPreviewControl;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabPropertySheetControl;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabQuickEditControl;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabTextControl;
@@ -54,23 +57,27 @@
private static String NODE_ATTRIBUTE_NAME = "name";
private static int TAB_TEXT_FONT_NUMBER = 0;
- private static int TAB_QUICK_EDIT_NUMBER = 4;
+ private static int TAB_QUICK_EDIT_NUMBER = 5;
private static int FIRST_SELECTION = 0;
private static int SIZE_NULL = 0;
private String newStyle;
private String oldStyle;
+
private TabTextControl tabTextControl;
private TabBackgroundControl tabBackgroundControl;
private TabBoxesControl tabBoxesControl;
private TabPropertySheetControl tabPropertySheetControl;
private TabQuickEditControl tabQuickEditControl;
+ private TabPreviewControl tabPreviewControl;
+
private TabFolder tabFolder;
private TabItem tabTextFont;
private TabItem tabBackground;
private TabItem tabBoxes;
private TabItem tabPropertySheet;
private TabItem tabQuickEdit;
+ private TabItem tabPreview;
private TabItem lastSelectedTab = null;
private StyleAttributes styleAttributes;
private Parser parser;
@@ -99,7 +106,12 @@
return newStyle;
}
- public void updateStyle() {
+ /**
+ * Update new style in accordance with the style attribute values.
+ *
+ * @return string representation of attribute of current CSS selector
+ */
+ public String updateStyle() {
if (lastSelectedTab == tabTextFont) {
tabTextControl.updateData(true);
} else if (lastSelectedTab == tabBackground) {
@@ -117,65 +129,12 @@
}
newStyle = buf.toString();
+ return newStyle;
}
/**
- * Method for creating text tab
- *
- * @param tabFolder
- * @return composite
+ * Method is used to create it child subtabs.
*/
- private Control createTabTextControl(TabFolder tabFolder) {
- ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
-
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
-
- tabTextControl = new TabTextControl(sc, comboMap, styleAttributes);
- sc.setContent(tabTextControl);
- sc.setMinSize(tabTextControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- return sc;
- }
-
- /**
- * Method for creating background tab
- *
- * @param tabFolder
- * @return composite
- */
- private Control createTabBackgroundControl(TabFolder tabFolder) {
- ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
-
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
-
- tabBackgroundControl = new TabBackgroundControl(sc, comboMap, styleAttributes);
- sc.setContent(tabBackgroundControl);
- sc.setMinSize(tabBackgroundControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- return sc;
- }
-
- /**
- * Method for creating boxes tab
- *
- * @param tabFolder
- * @return composite
- */
- private Control createTabBoxesControl(TabFolder tabFolder) {
- ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
-
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
-
- tabBoxesControl = new TabBoxesControl(sc, comboMap, styleAttributes);
- sc.setContent(tabBoxesControl);
- sc.setMinSize(tabBoxesControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- return sc;
- }
-
private void createTabs() {
ComboParser comboParser = new ComboParser();
comboParser.setListener(new BaseListener(comboMap) {
@@ -217,8 +176,7 @@
});
cssParser.parse();
- // HashMap<String, String> attributesMap = new HashMap<String,
- // String>();
+ // HashMap<String, String> attributesMap = new HashMap<String,
String>();
ParserListener listener = new ParserListener(styleAttributes);
parser = new Parser(elementsMap);
parser.addListener(listener);
@@ -254,6 +212,11 @@
tabPropertySheet.setToolTipText(JstUIMessages.PROPERTY_SHEET_TAB_NAME);
tabPropertySheet.setControl(createTabPropertySheetControl(tabFolder));
+ tabPreview = new TabItem(tabFolder, SWT.NONE);
+ tabPreview.setText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
+ tabPreview.setToolTipText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
+ tabPreview.setControl(createPreviewContol(tabFolder));
+
tabFolder.setSelection(TAB_TEXT_FONT_NUMBER);
if (styleAttributes.getAttributeMap().size() > SIZE_NULL) {
@@ -280,8 +243,10 @@
} else if (tabFolder.getSelection()[FIRST_SELECTION] == tabBoxes) {
tabBoxesControl.updateData(false);
lastSelectedTab = tabBoxes;
+ } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabPreview)
{
+ lastSelectedTab = tabPreview;
} else if (tabFolder.getSelection()[FIRST_SELECTION] ==
tabPropertySheet) {
- tabPropertySheetControl.updateData(false);
+// tabPropertySheetControl.updateData(false);
lastSelectedTab = tabPropertySheet;
}
}
@@ -289,19 +254,144 @@
}
/**
+ * Method for creating text tab
*
+ * @param tabFolder
+ * @return composite
+ */
+ private Control createTabTextControl(TabFolder tabFolder) {
+ ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+
+ tabTextControl = new TabTextControl(sc, comboMap, styleAttributes);
+ sc.setContent(tabTextControl);
+ sc.setMinSize(tabTextControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ return sc;
+ }
+
+ /**
+ * Method for creating background tab
+ *
+ * @param tabFolder
+ * @return composite
+ */
+ private Control createTabBackgroundControl(TabFolder tabFolder) {
+ ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+
+ tabBackgroundControl = new TabBackgroundControl(sc, comboMap, styleAttributes);
+ sc.setContent(tabBackgroundControl);
+ sc.setMinSize(tabBackgroundControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ return sc;
+ }
+
+ /**
+ * Method for creating boxes tab
+ *
+ * @param tabFolder
+ * @return composite
+ */
+ private Control createTabBoxesControl(TabFolder tabFolder) {
+ ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+
+ tabBoxesControl = new TabBoxesControl(sc, comboMap, styleAttributes);
+ sc.setContent(tabBoxesControl);
+ sc.setMinSize(tabBoxesControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ return sc;
+ }
+
+ /**
+ * Method for creating quick edit tab
+ *
+ * @param tabFolder
+ * @return
+ */
+ private Control createPreviewContol(TabFolder tabFolder) {
+ ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+
+ tabPreviewControl = new TabPreviewControl(sc, styleAttributes);
+ sc.setContent(tabPreviewControl);
+
+ sc.setMinSize(tabPreviewControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ return sc;
+ }
+
+ /**
* Method for creating property sheet tab
*
* @param tabFolder
* @return
*/
private Control createTabPropertySheetControl(TabFolder tabFolder) {
- tabPropertySheetControl = new TabPropertySheetControl(tabFolder, elementsMap,
comboMap,
- styleAttributes);
+ tabPropertySheetControl = new TabPropertySheetControl(tabFolder, elementsMap,
comboMap, styleAttributes);
return tabPropertySheetControl;
}
+ /**
+ * Method for creating quick edit tab
+ *
+ * @param tabFolder
+ * @return
+ */
+ private Control createTabQuickEditContol(TabFolder tabFolder) {
+ ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+
+ tabQuickEditControl = new TabQuickEditControl(sc, comboMap, styleAttributes);
+ sc.setContent(tabQuickEditControl);
+
+ sc.setMinSize(tabQuickEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+
+ return sc;
+ }
+
+ /**
+ * Clear whole style composite component.
+ */
+ public void clearStyleComposite() {
+ styleAttributes.clear();
+
+ tabBackgroundControl.updateData(false);
+ tabBoxesControl.updateData(false);
+ tabPropertySheetControl.updateData(false);
+ tabTextControl.updateData(false);
+
+ if (tabQuickEdit != null) {
+ tabQuickEditControl.updateData();
+ }
+ }
+
+ /**
+ * Update Preview tab with content from the passed CSS file.
+ *
+ * @param cssFile CSS file to be shown on Preview tab
+ */
+ public void updatePreviewCssFile(IFile cssFile) {
+ tabPreviewControl.updateDataFile(cssFile);
+ }
+
+ /**
+ * Recreate style composite tab widgets.
+ *
+ * @param style CSS style
+ */
public void recreateStyleComposite(String style) {
styleAttributes.clear();
parser.parse(style);
@@ -317,6 +407,10 @@
tabQuickEdit.setText(JstUIMessages.QUICK_EDIT_TAB_NAME);
tabQuickEdit.setToolTipText(JstUIMessages.QUICK_EDIT_TAB_NAME);
tabQuickEdit.setControl(createTabQuickEditContol(tabFolder));
+ ManualChangeStyleListener[] listeners =
tabBackgroundControl.getManualChangeStyleListeners();
+ if (listeners != null && listeners.length > 0) {
+ tabQuickEditControl.addManualChangeStyleListener(listeners[0]);
+ }
} else {
// update quick edit
tabQuickEditControl.updateData();
@@ -325,30 +419,36 @@
tabFolder.setSelection(TAB_QUICK_EDIT_NUMBER);
lastSelectedTab = tabQuickEdit;
} else {
- if ((tabQuickEdit != null) || !tabQuickEdit.isDisposed()) {
+ if (tabQuickEdit != null && !tabQuickEdit.isDisposed()) {
tabQuickEdit.dispose();
- tabFolder.redraw();
}
+ tabFolder.redraw();
}
}
/**
- * Method for creating quick edit tab
+ * Method is used to close preview tab correctly.
*
- * @param tabFolder
- * @return
+ * @param save close editor with saving or not
*/
- private Control createTabQuickEditContol(TabFolder tabFolder) {
- ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL |
SWT.V_SCROLL);
+ public void closePreview(boolean save) {
+ if (tabPreviewControl != null) {
+ tabPreviewControl.closeEditor(save);
+ }
+ }
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
-
- tabQuickEditControl = new TabQuickEditControl(sc, comboMap, styleAttributes);
- sc.setContent(tabQuickEditControl);
-
- sc.setMinSize(tabQuickEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- return sc;
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ tabBackgroundControl.addManualChangeStyleListener(listener);
+ tabBoxesControl.addManualChangeStyleListener(listener);
+ tabPropertySheetControl.addManualChangeStyleListener(listener);
+ tabTextControl.addManualChangeStyleListener(listener);
+ if (tabQuickEditControl != null) {
+ tabQuickEditControl.addManualChangeStyleListener(listener);
+ }
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSConstants.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSConstants.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSConstants.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -34,4 +34,7 @@
public static final String TEXT_ALIGN = "text-align"; //$NON-NLS-1$
public static final String FONT_FAMILY = "font-family"; //$NON-NLS-1$
public static final String COLOR = "color"; //$NON-NLS-1$
+
+ public static final String STYLE = "style"; //$NON-NLS-1$
+ public static final String CLASS = "class"; //$NON-NLS-1$
}
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 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -1,158 +1,196 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jst.jsp.outline.cssdialog.common;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-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.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.w3c.dom.css.CSSRuleList;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.CSSStyleRule;
-import org.w3c.dom.css.CSSStyleSheet;
-
-
-public class CSSModel {
-
- private FormatProcessorCSS formatProcessorCSS = null;
- private CSSStyleSheet styleSheet = null;
- private IStructuredModel model = null;
-
- private static String startBraces = "{";
- private static String endBraces = "}";
-
- public CSSModel(IFile styleFile) {
-
- try {
- formatProcessorCSS = new FormatProcessorCSS();
- IModelManager modelManager = StructuredModelManager
- .getModelManager();
- model = modelManager.getModelForEdit(styleFile);
- if (model instanceof ICSSModel) {
- ICSSModel cssModel = (ICSSModel) model;
- ICSSDocument document = cssModel.getDocument();
- if (document instanceof CSSStyleSheet) {
- styleSheet = (CSSStyleSheet) document;
- }
- }
-
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
-
- /**
- * Get selectors
- *
- * @return List<String>
- */
- public List<String> getSelectors() {
- List<String> selectors = new ArrayList<String>();
- if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
- if (list != null) {
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i) instanceof CSSStyleRule) {
- selectors.add(((CSSStyleRule)list.item(i)).getSelectorText());
- }
- }
- }
- }
- return selectors;
- }
-
-
- public String getCSSText(String selector) {
- if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
- if (list != null) {
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i) instanceof CSSStyleRule &&
((CSSStyleRule)list.item(i)).getSelectorText().equals(selector)) {
- return ((CSSStyleRule)list.item(i)).getCssText();
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Get style by selectorName
- *
- * @param selectorName
- * @return style
- */
- public String getStyle(String selectorName) {
- if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
- if (list != null) {
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i) instanceof CSSStyleRule &&
((CSSStyleRule)list.item(i)).getSelectorText().equals(selectorName)) {
- return ((CSSStyleRule)list.item(i)).getStyle().getCssText();
- }
- }
- }
- }
- return null;
- }
-
- /**
- *
- * @param selector
- * @param style
- */
- public void setCSS(String selector,String style) {
- if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
- if (list != null) {
- for (int i = 0; i < list.getLength(); i++) {
- if (list.item(i) instanceof CSSStyleRule &&
((CSSStyleRule)list.item(i)).getSelectorText().equals(selector)) {
- CSSStyleRule rule = (CSSStyleRule) list.item(i);
- CSSStyleDeclaration declaration = rule.getStyle();
- declaration.setCssText(style);
- return;
- }
- }
- styleSheet.insertRule(selector+startBraces+style+endBraces, list.getLength());
- }
- }
- }
-
- /**
- * Save model to file
- */
- public void saveModel() {
- if (formatProcessorCSS!=null)
- formatProcessorCSS.formatModel(model);
- try {
- model.save();
- } catch (UnsupportedEncodingException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.common;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+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.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSStyleRule;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ * CSS class model.
+ */
+public class CSSModel {
+
+ private static String startBraces = "{"; //$NON-NLS-1$
+ private static String endBraces = "}"; //$NON-NLS-1$
+ private FormatProcessorCSS formatProcessorCSS = null;
+ private CSSStyleSheet styleSheet = null;
+ private IStructuredModel model = null;
+ private IFile styleFile = null;
+
+ /**
+ * Constructor.
+ *
+ * @param styleFile CSS style class that should initialize CSS model
+ */
+ public CSSModel(IFile styleFile) {
+ try {
+ this.styleFile = styleFile;
+
+ formatProcessorCSS = new FormatProcessorCSS();
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ model = modelManager.getModelForEdit(styleFile);
+ if (model instanceof ICSSModel) {
+ ICSSModel cssModel = (ICSSModel) model;
+ ICSSDocument document = cssModel.getDocument();
+
+ if (document instanceof CSSStyleSheet) {
+ styleSheet = (CSSStyleSheet) document;
+ }
+ }
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+ }
+
+ /**
+ * Get selectors
+ *
+ * @return List<String>
+ */
+ public List<Selector> getSelectors() {
+ List<Selector> selectors = new ArrayList<Selector>();
+
+ if (styleSheet != null) {
+ CSSRuleList list = styleSheet.getCssRules();
+
+ if (list != null) {
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i) instanceof CSSStyleRule) {
+ CSSStyleRule rule = ((CSSStyleRule) list.item(i));
+ Selector selector = new Selector(rule.toString(),
rule.getSelectorText());
+// selectors.add(((CSSStyleRule)
list.item(i)).getSelectorText());
+ selectors.add(selector);
+ }
+ }
+ }
+ }
+
+ return selectors;
+ }
+
+ /**
+ *
+ * @param selector
+ * @return
+ */
+ public String getCSSText(String selector) {
+ if (styleSheet != null) {
+ CSSRuleList list = styleSheet.getCssRules();
+
+ if (list != null) {
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i) instanceof CSSStyleRule &&
+ ((CSSStyleRule)
list.item(i)).getSelectorText().equals(selector)) {
+ return ((CSSStyleRule) list.item(i)).getCssText();
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get style by selectorName
+ *
+ * @param selectorName
+ * @return style
+ */
+ public String getStyle(String selectorName) {
+ if (styleSheet != null) {
+ CSSRuleList list = styleSheet.getCssRules();
+
+ if (list != null) {
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i) instanceof CSSStyleRule &&
+ ((CSSStyleRule)
list.item(i)).getSelectorText().equals(selectorName)) {
+ return ((CSSStyleRule) list.item(i)).getStyle().getCssText();
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @param selector
+ * @param style
+ */
+ public void setCSS(String selector, String style) {
+ if (styleSheet != null) {
+ CSSRuleList list = styleSheet.getCssRules();
+
+ if (list != null) {
+ // check if selector passed by parameter already exists in CSS
+ for (int i = 0; i < list.getLength(); i++) {
+ if (list.item(i) instanceof CSSStyleRule &&
+ ((CSSStyleRule)
list.item(i)).getSelectorText().equals(selector)) {
+ CSSStyleRule rule = (CSSStyleRule) list.item(i);
+ CSSStyleDeclaration declaration = rule.getStyle();
+ declaration.setCssText(style);
+
+ return;
+ }
+ }
+ // insert NEW selector to style sheet
+ styleSheet.insertRule(selector + startBraces + style + endBraces,
list.getLength());
+ formatProcessorCSS.formatModel(model);
+ }
+ }
+ }
+
+ /**
+ * Save model to file
+ */
+ public void releaseModel() {
+ model.releaseFromEdit();
+ }
+
+ /**
+ * Save model to file
+ */
+ public void saveModel() {
+// ICSSModel cssModel = (ICSSModel) model;
+// ICSSDocument document = cssModel.getDocument();
+
+// if (document instanceof CSSStyleSheet) {
+// styleSheet = (CSSStyleSheet) document;
+// }
+// formatProcessorCSS.formatModel(model);
+ try {
+ formatProcessorCSS.formatFile(styleFile);
+ model.save();
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -63,8 +63,9 @@
public static final String WHITE_SPACE = " "; //$NON-NLS-1$
public static String COLON = ":"; //$NON-NLS-1$
public static String SEMICOLON = ";"; //$NON-NLS-1$
- public static String COMMA = ";"; //$NON-NLS-1$
+ public static String COMMA = ","; //$NON-NLS-1$
public static String DASH = "-"; //$NON-NLS-1$
+ public static String SLASH = "/"; //$NON-NLS-1$
public static final RGB RGB_BLACK = new RGB(0,0,0);
public static final RGB RGB_WHITE = new RGB(0xFF, 0xFF, 0xFF);
@@ -76,5 +77,5 @@
public static String OPEN_DIV_TAG = "<div style=\"width: 100%;";
public static String CLOSE_DIV_TAG = "</div>";
- public static String TEXT_FOR_PREVIEW = "\">Text for preview";
+ public static String TEXT_FOR_PREVIEW = "Double click to edit preview.";
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Selector.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Selector.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Selector.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.common;
+
+/**
+ * Selector class.
+ */
+public class Selector {
+
+ private String value = null;
+ private String id = null;
+
+ /**
+ * Constructor.
+ *
+ * @param id
+ * @param value
+ */
+ public Selector(String id, String value) {
+ this.id = id;
+ this.value = value;
+ }
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return
+ * @see java.lang.String#toString()
+ */
+ public String toString() {
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null || !(obj instanceof Selector)) {
+ return false;
+ }
+ Selector selector = (Selector) obj;
+ if (id == null || selector.getId() == null) {
+ return false;
+ }
+ if (id.equals(selector.getId())) {
+ return true;
+ }
+ return super.equals(obj);
+ }
+}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Util.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Util.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Util.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -12,15 +12,23 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
@@ -275,15 +283,76 @@
*
* @return IProject object
*/
- public static IProject getCurrentProject() {
- IEditorPart editor = JspEditorPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- IEditorInput input = editor.getEditorInput();
- IProject project = null;
- if (input instanceof IFileEditorInput) {
- IFile file = ((IFileEditorInput) input).getFile();
- project = file.getProject();
+ public static IResource getCurrentProject() {
+ IResource result = null;
+ IWorkbenchPage page =
JspEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if (page != null && page.getActiveEditor() != null) {
+ IEditorPart editor = page.getActiveEditor();
+ IEditorInput input = editor.getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) input).getFile();
+ result = file.getProject();
+ }
+ } else {
+ result = ResourcesPlugin.getWorkspace().getRoot();
}
- return project;
+ return result;
}
+
+ /**
+ * Get current opened CSS file. If file is not CSS file - return null instead.
+ *
+ * @return IFile CSS file
+ */
+ public static IFile getActiveCssFile() {
+ IWorkbenchPage page =
JspEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if (page != null && page.getActiveEditor() != null) {
+ IEditorInput input = page.getActiveEditor().getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) input).getFile();
+ if (file.getName().toLowerCase().endsWith("css")) {
+ return file;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ */
+ public static String getActivePageCSSSelectorIfAny() {
+ IWorkbenchPage page =
JspEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ ISelection selection = page.getSelection();
+ String sText = null;
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ for (Iterator iterator = ss.iterator(); iterator.hasNext();) {
+ Object node = iterator.next();
+ if (node instanceof ICSSNode) {
+ return getSelector((ICSSNode)node);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ */
+ private static String getSelector(ICSSNode node) {
+ if (node != null) {
+ short nodeType = node.getNodeType();
+ if (nodeType == ICSSNode.STYLESHEET_NODE) {
+ ICSSStyleSheet styleSheet = (ICSSStyleSheet) node;
+ return getSelector(styleSheet.getFirstChild());
+ } else if (nodeType == ICSSNode.STYLERULE_NODE) {
+ ICSSStyleRule styleRule = (ICSSStyleRule) node;
+ return styleRule.getSelectorText();
+ } else {
+ return getSelector(node.getParentNode());
+ }
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleEvent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleEvent.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleEvent.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -1,24 +1,30 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jst.jsp.outline.cssdialog.events;
-
-import java.util.EventObject;
-
-public class ChangeStyleEvent extends EventObject {
- /**
- *
- */
- private static final long serialVersionUID = 3260787731782837929L;
-
- public ChangeStyleEvent(Object source) {
- super(source);
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+
+import java.util.EventObject;
+
+/**
+ * An event which indicates that a style change action occurred.
+ */
+public class ChangeStyleEvent extends EventObject {
+
+ private static final long serialVersionUID = 3260787731782837929L;
+
+ /**
+ * Constructor.
+ *
+ * @param source the Component that originated the event
+ */
+ public ChangeStyleEvent(Object source) {
+ super(source);
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleListener.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleListener.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ChangeStyleListener.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -10,6 +10,14 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+/**
+ * Defines an object which listens for ChangeStyleEvent.
+ */
public interface ChangeStyleListener {
+
+ /**
+ * Invoked when the target of the listener has changed its state.
+ * @param event a ChangeEvent object
+ */
public void styleChanged(ChangeStyleEvent event);
}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ManualChangeStyleListener.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ManualChangeStyleListener.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/ManualChangeStyleListener.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+
+/**
+ * Defines an object which listens for ManualChangeStyleEvent.
+ */
+public interface ManualChangeStyleListener {
+
+ /**
+ * Invoked when the target of the listener has changed its state.
+ * @param event a ChangeEvent object
+ */
+ public void styleChanged(ChangeStyleEvent event);
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogEvent.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogEvent.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogEvent.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+
+import java.util.EventObject;
+
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * An event which indicates that any dialog contains empty mandatory fields.
+ */
+public class MessageDialogEvent extends EventObject {
+
+ private static final long serialVersionUID = -5978788274463066057L;
+
+ private IStatus operationStatus = null;
+
+ /**
+ * Constructor.
+ *
+ * @param source the Component that originated the event
+ */
+ public MessageDialogEvent(Object source, IStatus operationStatus) {
+ super(source);
+ this.operationStatus = operationStatus;
+ }
+
+ /**
+ * Gets operation status.
+ *
+ * @return the operationStatus
+ */
+ public IStatus getOperationStatus() {
+ return operationStatus;
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogListener.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogListener.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/MessageDialogListener.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+
+/**
+ * Defines an object which listens for MessageDialogEvent.
+ */
+public interface MessageDialogListener {
+
+ /**
+ * Invoked when the target of the listener has changed its state.
+ * @param event a MessageDialogEvent object
+ */
+ public void throwMessage(MessageDialogEvent event);
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/StyleAttributes.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -1,81 +1,141 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jst.jsp.outline.cssdialog.events;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.Map.Entry;
-
-public class StyleAttributes {
-
- private HashMap<String, String> attributeMap;
- private ArrayList<ChangeStyleListener> listeners = new
ArrayList<ChangeStyleListener>();
-
- public StyleAttributes() {
- this.attributeMap = new HashMap<String, String>();
- }
-
- public HashMap<String, String> getAttributeMap() {
- return attributeMap;
- }
-
- public void setAttributeMap(HashMap<String, String> attributeMap) {
- this.attributeMap = attributeMap;
- addNewListener();
- }
-
- public void addChangeStyleListener(ChangeStyleListener listener) {
- listeners.add(listener);
- }
-
- public ChangeStyleListener[] getChangeStyleListeners() {
- return listeners.toArray(new ChangeStyleListener[listeners.size()]);
- }
-
- public void removeChangeStyleListener(ChangeStyleListener listener) {
- listeners.remove(listener);
- }
-
- private void addNewListener() {
- ChangeStyleEvent event = new ChangeStyleEvent(this);
- for (ChangeStyleListener listener : listeners)
- listener.styleChanged(event);
- }
-
- public void addAttribute(String name, String value) {
- attributeMap.put(name, value);
- addNewListener();
- }
-
- public void removeAttribute(String name) {
- attributeMap.remove(name);
- addNewListener();
- }
-
- public Set<Entry<String, String>> entrySet() {
- return attributeMap.entrySet();
- }
-
- public String getAttribute(String name) {
- return attributeMap.get(name);
- }
-
- public Set<String> keySet() {
- return attributeMap.keySet();
- }
-
- public void clear() {
- attributeMap.clear();
- addNewListener();
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Class is used to store an array of style attributes and support listeners.
+ */
+public class StyleAttributes {
+
+ private HashMap<String, String> attributeMap;
+ private ArrayList<ChangeStyleListener> listeners = new
ArrayList<ChangeStyleListener>();
+
+ /**
+ * Default constructor.
+ */
+ public StyleAttributes() {
+ this.attributeMap = new HashMap<String, String>();
+ }
+
+ /**
+ * Gets attribute map.
+ *
+ * @return map of attributes
+ */
+ public HashMap<String, String> getAttributeMap() {
+ return attributeMap;
+ }
+
+ /**
+ * Sets attribute map.
+ *
+ * @param attributeMap value
+ */
+ public void setAttributeMap(HashMap<String, String> attributeMap) {
+ this.attributeMap = attributeMap;
+ notifyListeners();
+ }
+
+ /**
+ * Add ChangeStyleListener object.
+ *
+ * @param listener ChangeStyleListener object to be added
+ */
+ public void addChangeStyleListener(ChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ChangeStyleListener[] getChangeStyleListeners() {
+ return listeners.toArray(new ChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ChangeStyleListener object passed by parameter.
+ *
+ * @param listener ChangeStyleListener object to be removed
+ */
+ public void removeChangeStyleListener(ChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Add attribute with the given name and value.
+ *
+ * @param name the name of attribute
+ * @param value the value of attribute
+ */
+ public void addAttribute(String name, String value) {
+ attributeMap.put(name, value);
+ notifyListeners();
+ }
+
+ /**
+ * Remove attribute with the given name.
+ *
+ * @param name the name of attribute to be removed
+ */
+ public void removeAttribute(String name) {
+ attributeMap.remove(name);
+ notifyListeners();
+ }
+
+ /**
+ * @see java.util.HashMap#entrySet()
+ */
+ public Set<Entry<String, String>> entrySet() {
+ return attributeMap.entrySet();
+ }
+
+ /**
+ * Get attribute value with the given name.
+ *
+ * @param name the name of attribute to be returned
+ * @return attribute value
+ */
+ public String getAttribute(String name) {
+ return attributeMap.get(name);
+ }
+
+ /**
+ * @see java.util.HashMap#keySet()
+ */
+ public Set<String> keySet() {
+ return attributeMap.keySet();
+ }
+
+ /**
+ * Clear cache of attributes.
+ */
+ public void clear() {
+ attributeMap.clear();
+ notifyListeners();
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/TabPropertySheetMouseAdapter.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/TabPropertySheetMouseAdapter.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/TabPropertySheetMouseAdapter.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -10,12 +10,13 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.events;
+import java.util.ArrayList;
+import java.util.HashMap;
+
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.DisposeEvent;
@@ -39,10 +40,8 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
-
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
-
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.outline.cssdialog.FontFamilyDialog;
@@ -54,9 +53,6 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabPropertySheetControl;
-import java.util.ArrayList;
-import java.util.HashMap;
-
/**
* Listener for tree in tab property sheet
*
@@ -75,10 +71,18 @@
private HashMap<String, ArrayList<String>> comboMap;
private HashMap<String, ArrayList<String>> elementsMap;
- //Dzmitry Sakovich
- //private CSSDialog cssDialog;
private TabPropertySheetControl tabPropertySheetControl;
+ private ArrayList<ManualChangeStyleListener> listeners = new
ArrayList<ManualChangeStyleListener>();
+
+ /**
+ * Constructor.
+ *
+ * @param tree
+ * @param elementsMap
+ * @param comboMap
+ * @param tabPropertySheetControl
+ */
public TabPropertySheetMouseAdapter(Tree tree, HashMap<String,
ArrayList<String>> elementsMap,
HashMap<String, ArrayList<String>> comboMap, TabPropertySheetControl
tabPropertySheetControl) {
this.tabPropertySheetControl = tabPropertySheetControl;
@@ -164,19 +168,18 @@
item.setText(Constants.SECOND_COLUMN, colorCombo.getText());
panel.dispose();
tabPropertySheetControl.updateData(true);
-
- //Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!tabPropertySheetControl.getUpdateDataFromStyleAttributes())
{
+ notifyListeners();
+ }
}
});
-
colorCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
item.setText(Constants.SECOND_COLUMN, colorCombo.getText());
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!tabPropertySheetControl.getUpdateDataFromStyleAttributes())
{
+ notifyListeners();
+ }
}
});
@@ -193,12 +196,9 @@
}
});
btn.setToolTipText(JstUIMessages.COLOR_DIALOG_TITLE);
-
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- RGB startRgb =
Util.getColor(item.getText(Constants.SECOND_COLUMN).toLowerCase()
- .trim());
-
+ RGB startRgb =
Util.getColor(item.getText(Constants.SECOND_COLUMN).toLowerCase().trim());
if (startRgb == null) {
startRgb = Constants.RGB_BLACK;
}
@@ -210,18 +210,15 @@
RGB rgb = colorDialog.open();
if (rgb != null) {
String str = Util.createColorString(rgb);
-
if (ColorParser.getInstance().getMap().get(str) != null) {
- item.setText(Constants.SECOND_COLUMN,
- ColorParser.getInstance().getMap().get(str));
+ item.setText(Constants.SECOND_COLUMN,
ColorParser.getInstance().getMap().get(str));
} else {
item.setText(Constants.SECOND_COLUMN, str);
}
-
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if
(!tabPropertySheetControl.getUpdateDataFromStyleAttributes()) {
+ notifyListeners();
+ }
}
panel.dispose();
@@ -243,10 +240,9 @@
}
});
btn.setToolTipText(JstUIMessages.IMAGE_DIALOG_MESSAGE);
-
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- IProject project = Util.getCurrentProject();
+ IAdaptable project = Util.getCurrentProject();
ImageSelectionDialog dialog = new
ImageSelectionDialog(tree.getShell(),
new WorkbenchLabelProvider(), new
WorkbenchContentProvider());
@@ -262,9 +258,9 @@
item.setText(Constants.SECOND_COLUMN, value);
panel.dispose();
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if
(!tabPropertySheetControl.getUpdateDataFromStyleAttributes()) {
+ notifyListeners();
+ }
}
}
});
@@ -276,17 +272,15 @@
if (!color) {
ArrayList<String> list =
comboMap.get(item.getText(Constants.FIRST_COLUMN).trim());
- for (String str : list)
+ for (String str : list) {
combo.add(str);
-
+ }
if (btn != null) {
btn.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
false));
}
combo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
combo.setFocus();
-
if ((combo.indexOf(item.getText(column)) == Constants.DONT_CONTAIN)
&&
!item.getText(column).equals(Constants.EMPTY)) {
combo.setText(item.getText(column));
@@ -294,34 +288,29 @@
combo.select(combo.indexOf(item.getText(column)));
}
- // Add a listener to set the selected item back into the
- // cell
+ // Add a listener to set the selected item back into the cell
final int col = column;
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
item.setText(col, combo.getText());
panel.dispose();
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!tabPropertySheetControl.getUpdateDataFromStyleAttributes())
{
+ notifyListeners();
+ }
}
});
-
combo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
item.setText(col, combo.getText());
- tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!tabPropertySheetControl.getUpdateDataFromStyleAttributes())
{
+ notifyListeners();
+ }
}
});
} else {
colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
btn.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
false));
-
colorCombo.setFocus();
}
@@ -357,7 +346,6 @@
Button btn = null;
final Text text = new Text(panel, SWT.BORDER);
-
if
(item.getText(Constants.FIRST_COLUMN).trim().equalsIgnoreCase(CSSConstants.FONT_FAMILY))
{
btn = new Button(panel, SWT.NONE);
@@ -371,19 +359,17 @@
}
});
btn.setToolTipText(JstUIMessages.FONT_FAMILY_TIP);
-
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FontFamilyDialog dialog = new FontFamilyDialog(tree.getShell(),
item.getText(Constants.SECOND_COLUMN));
-
if (dialog.open() == Window.OK) {
item.setText(Constants.SECOND_COLUMN,
dialog.getFontFamily());
panel.dispose();
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if
(!tabPropertySheetControl.getUpdateDataFromStyleAttributes()) {
+ notifyListeners();
+ }
}
}
});
@@ -417,14 +403,50 @@
final int col = column;
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
- // Set the text of the editor's control back
- // into the cell
+ // Set the text of the editor's control back into the cell
item.setText(col, text.getText());
tabPropertySheetControl.updateData(true);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!tabPropertySheetControl.getUpdateDataFromStyleAttributes()) {
+ notifyListeners();
+ }
}
});
}
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ManualChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ManualChangeStyleListener[] getManualChangeStyleListeners() {
+ return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ManualChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -17,7 +17,7 @@
import java.util.Map.Entry;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
@@ -44,6 +44,8 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.ImageCombo;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
@@ -61,8 +63,8 @@
private Combo backgroundRepeatCombo;
private StyleAttributes styleAttributes;
- //TODO Dzmitry Sakovich
- //private CSSDialog cssDialog;
+ private ArrayList<ManualChangeStyleListener> listeners = new
ArrayList<ManualChangeStyleListener>();
+ private boolean updateDataFromStyleAttributes = false;
/**
* Constructor for creating controls
@@ -74,8 +76,6 @@
super(composite, SWT.NONE);
this.styleAttributes = styleAttributes;
- //TODO Dzmitry Sakovich
- //this.cssDialog = dialog;
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = numColumns;
setLayout(gridLayout);
@@ -89,19 +89,17 @@
colorCombo = new ImageCombo(this, SWT.BORDER);
colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
colorCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = colorCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.BACKGROUND_COLOR,
tmp);
- } else {
-
styleAttributes.removeAttribute(CSSConstants.BACKGROUND_COLOR);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.BACKGROUND_COLOR, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.BACKGROUND_COLOR);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
@@ -132,7 +130,6 @@
dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
RGB rgb = dlg.open();
-
if (rgb != null) {
String colorStr = Util.createColorString(rgb);
colorCombo.setText(colorStr);
@@ -148,25 +145,21 @@
label.setText(JstUIMessages.BACKGROUND_IMAGE);
backgroundImageCombo = new Combo(this, SWT.BORDER);
-
final GridData backgroundImageGridData = new GridData(GridData.FILL,
GridData.CENTER, true, false);
backgroundImageCombo.setLayoutData(backgroundImageGridData);
backgroundImageCombo.add(Constants.NONE);
-
backgroundImageCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = backgroundImageCombo.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- tmp = adjustBackgroundURL(tmp);
- styleAttributes.addAttribute(CSSConstants.BACKGROUND_IMAGE, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.BACKGROUND_IMAGE);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ tmp = adjustBackgroundURL(tmp);
+ styleAttributes.addAttribute(CSSConstants.BACKGROUND_IMAGE, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.BACKGROUND_IMAGE);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
@@ -185,7 +178,7 @@
});
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- IProject project = Util.getCurrentProject();
+ IAdaptable project = Util.getCurrentProject();
ImageSelectionDialog dialog = new ImageSelectionDialog(getShell(),
new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(JstUIMessages.IMAGE_DIALOG_TITLE);
@@ -215,20 +208,17 @@
gridData.horizontalSpan = 2;
backgroundRepeatCombo = new Combo(this, SWT.BORDER);
backgroundRepeatCombo.setLayoutData(gridData);
-
backgroundRepeatCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = backgroundRepeatCombo.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.BACKGROUND_REPEAT, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.BACKGROUND_REPEAT);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.BACKGROUND_REPEAT, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.BACKGROUND_REPEAT);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
ArrayList<String> list = comboMap.get(CSSConstants.BACKGROUND_REPEAT);
@@ -244,25 +234,27 @@
* @param param
*/
public void updateData(boolean param) {
+ updateDataFromStyleAttributes = true;
String tmp;
-
+ // set BACKGROUND_COLOR attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_COLOR)) != null)
{
colorCombo.setText(tmp);
} else {
colorCombo.setText(Constants.EMPTY);
}
-
+ // set BACKGROUND_IMAGE attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_IMAGE)) != null)
{
backgroundImageCombo.setText(tmp);
} else {
backgroundImageCombo.setText(Constants.EMPTY);
}
-
+ // set BACKGROUND_REPEAT attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_REPEAT)) != null)
{
backgroundRepeatCombo.setText(tmp);
} else {
backgroundRepeatCombo.setText(Constants.EMPTY);
}
+ updateDataFromStyleAttributes = false;
}
//Fix for JBIDE-3084
@@ -275,4 +267,41 @@
return backgroundURL;
}
-}
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ManualChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ManualChangeStyleListener[] getManualChangeStyleListeners() {
+ return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ManualChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
+}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -37,6 +37,8 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.ImageCombo;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
@@ -70,8 +72,8 @@
private ArrayList<String> list;
private StyleAttributes styleAttributes;
- // TODO Dzmitry Sakovich
- // private CSSDialog cssDialog;
+ private ArrayList<ManualChangeStyleListener> listeners = new
ArrayList<ManualChangeStyleListener>();
+ private boolean updateDataFromStyleAttributes = false;
/**
* Constructor for creating controls
@@ -103,50 +105,38 @@
widthText = new Text(this, SWT.BORDER | SWT.SINGLE);
widthText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
- extWidthCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
-
widthText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = widthText.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extWidth = extWidthCombo.getText().trim();
-
- if (extWidth != null) {
- styleAttributes.addAttribute(CSSConstants.WIDTH, tmp +
extWidth);
- } else {
- styleAttributes.addAttribute(CSSConstants.WIDTH, tmp);
- }
- } else {
- styleAttributes.removeAttribute(CSSConstants.WIDTH);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extWidth = extWidthCombo.getText().trim();
+ if (extWidth != null) {
+ styleAttributes.addAttribute(CSSConstants.WIDTH, tmp + extWidth);
+ } else {
+ styleAttributes.addAttribute(CSSConstants.WIDTH, tmp);
+ }
} else {
styleAttributes.removeAttribute(CSSConstants.WIDTH);
}
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
+ extWidthCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ extWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
extWidthCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String width = widthText.getText().trim();
- if (width == null) {
- return;
+ if (width != null && !width.equals(Constants.EMPTY)) {
+ String tmp = extWidthCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.WIDTH, width +
tmp);
+ }
}
- if (width.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
- String tmp = extWidthCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.WIDTH, width + tmp);
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -162,47 +152,38 @@
heightText = new Text(this, SWT.BORDER | SWT.SINGLE);
heightText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
- extHeightCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extHeightCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
-
heightText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = heightText.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extHeight = extHeightCombo.getText().trim();
- if (extHeight != null) {
- styleAttributes.addAttribute(CSSConstants.HEIGHT, tmp +
extHeight);
- } else {
- styleAttributes.addAttribute(CSSConstants.HEIGHT, tmp);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extHeight = extHeightCombo.getText().trim();
+ if (extHeight != null) {
+ styleAttributes.addAttribute(CSSConstants.HEIGHT, tmp +
extHeight);
} else {
- styleAttributes.removeAttribute(CSSConstants.HEIGHT);
+ styleAttributes.addAttribute(CSSConstants.HEIGHT, tmp);
}
} else {
styleAttributes.removeAttribute(CSSConstants.HEIGHT);
}
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
+ extHeightCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ extHeightCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
extHeightCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String height = heightText.getText().trim();
- if (height == null) {
- return;
+ if (height != null && !height.equals(Constants.EMPTY)) {
+ String tmp = extHeightCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.HEIGHT, height +
tmp);
+ }
}
- if (height.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
- String tmp = extHeightCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.HEIGHT, height + tmp);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -225,21 +206,17 @@
gridData.horizontalSpan = 2;
borderStyleCombo = new Combo(this, SWT.BORDER);
borderStyleCombo.setLayoutData(gridData);
-
borderStyleCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = borderStyleCombo.getText().trim();
- if (tmp != null) {
- if (!tmp.equals(Constants.EMPTY)) {
- styleAttributes.addAttribute(CSSConstants.BORDER_STYLE,
tmp);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- return;
- }
+ if (tmp != null && !tmp.equals(Constants.EMPTY)) {
+ styleAttributes.addAttribute(CSSConstants.BORDER_STYLE, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.BORDER_STYLE);
}
- styleAttributes.removeAttribute(CSSConstants.BORDER_STYLE);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.BORDER_STYLE);
@@ -257,21 +234,17 @@
Composite tmpComposite = getCompositeElement();
borderColorCombo = new ImageCombo(tmpComposite, SWT.BORDER);
borderColorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
borderColorCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = borderColorCombo.getText().trim();
- if (tmp != null) {
- if (!tmp.equals(Constants.EMPTY)) {
- styleAttributes.addAttribute(CSSConstants.BORDER_COLOR,
tmp);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- return;
- }
+ if (tmp != null && !tmp.equals(Constants.EMPTY)) {
+ styleAttributes.addAttribute(CSSConstants.BORDER_COLOR, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.BORDER_COLOR);
}
- styleAttributes.removeAttribute(CSSConstants.BORDER_COLOR);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
@@ -299,7 +272,6 @@
dlg.setRGB((Util.getColor((borderColorCombo.getText().trim())) ==
null)
? Constants.RGB_BLACK :
Util.getColor((borderColorCombo.getText().trim())));
dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
-
RGB rgb = dlg.open();
if (rgb != null) {
String colorStr = Util.createColorString(rgb);
@@ -317,10 +289,6 @@
borderWidthCombo = new Combo(this, SWT.BORDER | SWT.SINGLE);
borderWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
- extBorderWidthCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extBorderWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
false, false));
-
borderWidthCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String currentText = borderWidthCombo.getText();
@@ -330,54 +298,47 @@
extBorderWidthCombo.select(0);
extBorderWidthCombo.setEnabled(false);
styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
currentText);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
return;
}
}
-
extBorderWidthCombo.setEnabled(true);
-
String tmp = borderWidthCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extBorderWidth =
extBorderWidthCombo.getText().trim();
-
- if (extBorderWidth != null) {
- styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
- tmp + extBorderWidth);
- } else {
- styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
tmp);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extBorderWidth = extBorderWidthCombo.getText();
+ if (extBorderWidth != null) {
+ styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH, tmp +
extBorderWidth);
} else {
- styleAttributes.removeAttribute(CSSConstants.BORDER_WIDTH);
+ styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH, tmp);
}
} else {
styleAttributes.removeAttribute(CSSConstants.BORDER_WIDTH);
}
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.BORDER_WIDTH);
for (String str : list) {
borderWidthCombo.add(str);
}
+ extBorderWidthCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ extBorderWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
false, false));
extBorderWidthCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String borderWidth = borderWidthCombo.getText().trim();
- if (borderWidth == null) {
- return;
+ if (borderWidth != null &&
!borderWidth.equals(Constants.EMPTY)) {
+ String tmp = extBorderWidthCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
borderWidth + tmp);
+ }
}
- if (borderWidth.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
- String tmp = extBorderWidthCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
borderWidth + tmp);
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -398,54 +359,38 @@
marginText = new Text(this, SWT.BORDER | SWT.SINGLE);
marginText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
- extMarginCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extMarginCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
-
marginText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = marginText.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extMargin = extMarginCombo.getText().trim();
-
- if (extMargin != null) {
- styleAttributes.addAttribute(CSSConstants.MARGIN, tmp +
extMargin);
- } else {
- styleAttributes.addAttribute(CSSConstants.MARGIN, tmp);
- }
- } else {
- styleAttributes.removeAttribute(CSSConstants.MARGIN);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extMargin = extMarginCombo.getText().trim();
+ if (extMargin != null) {
+ styleAttributes.addAttribute(CSSConstants.MARGIN, tmp +
extMargin);
+ } else {
+ styleAttributes.addAttribute(CSSConstants.MARGIN, tmp);
+ }
} else {
styleAttributes.removeAttribute(CSSConstants.MARGIN);
}
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
+ extMarginCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ extMarginCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
extMarginCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String margin = marginText.getText().trim();
-
- if (margin == null) {
- return;
+ if (margin != null && !margin.equals(Constants.EMPTY)) {
+ String tmp = extMarginCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.MARGIN, margin +
tmp);
+ }
}
-
- if (margin.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
-
- String tmp = extMarginCombo.getText();
-
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.MARGIN, margin + tmp);
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -461,54 +406,38 @@
paddingText = new Text(this, SWT.BORDER | SWT.SINGLE);
paddingText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
- extPaddingCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extPaddingCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
-
paddingText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = paddingText.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extPadding = extPaddingCombo.getText().trim();
-
- if (extPadding != null) {
- styleAttributes.addAttribute(CSSConstants.PADDING, tmp +
extPadding);
- } else {
- styleAttributes.addAttribute(CSSConstants.PADDING, tmp);
- }
- } else {
- styleAttributes.removeAttribute(CSSConstants.PADDING);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extPadding = extPaddingCombo.getText().trim();
+ if (extPadding != null) {
+ styleAttributes.addAttribute(CSSConstants.PADDING, tmp +
extPadding);
+ } else {
+ styleAttributes.addAttribute(CSSConstants.PADDING, tmp);
+ }
} else {
styleAttributes.removeAttribute(CSSConstants.PADDING);
}
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
+ extPaddingCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ extPaddingCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false,
false));
extPaddingCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String padding = paddingText.getText().trim();
-
- if (padding == null) {
- return;
+ if (padding != null && !padding.equals(Constants.EMPTY)) {
+ String tmp = extPaddingCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.PADDING, padding +
tmp);
+ }
}
-
- if (padding.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
-
- String tmp = extPaddingCombo.getText();
-
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.PADDING, padding +
tmp);
-
- // TODO Dzmitry Sakovich
- // cssDialog.setStyleForPreview();
- }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -533,18 +462,17 @@
}
/**
- * Method for get data in controls (if param equal true ), or set data (if
- * param equal false).
+ * Method for get data in controls (if parameter equals true ), or set data (if
parameter equals false).
*
* @param param
*/
public void updateData(boolean param) {
+ updateDataFromStyleAttributes = true;
String tmp;
-
+ // set WIDTH and EXTENSION_WIDTH attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.WIDTH)) != null) {
String[] str = Util.convertExtString(tmp);
widthText.setText(str[0]);
-
if (extWidthCombo.indexOf(str[1]) != -1) {
extWidthCombo.setText(str[1]);
extWidthCombo.select(extWidthCombo.indexOf(str[1]));
@@ -555,7 +483,7 @@
widthText.setText(Constants.EMPTY);
extWidthCombo.select(0);
}
-
+ // set HEIGHT and EXTENSION_HEIGHT attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.HEIGHT)) != null) {
String[] str = Util.convertExtString(tmp);
heightText.setText(str[0]);
@@ -570,19 +498,19 @@
heightText.setText(Constants.EMPTY);
extHeightCombo.select(0);
}
-
+ // set BORDER_STYLE attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.BORDER_STYLE)) != null) {
borderStyleCombo.setText(tmp);
} else {
borderStyleCombo.setText(Constants.EMPTY);
}
-
+ // set BORDER_COLOR attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.BORDER_COLOR)) != null) {
borderColorCombo.setText(tmp);
} else {
borderColorCombo.setText(Constants.EMPTY);
}
-
+ // set BORDER_WIDTH and EXTENSION_BORDER_WIDTH attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.BORDER_WIDTH)) != null) {
String[] str = Util.convertExtString(tmp);
borderWidthCombo.setText(str[0]);
@@ -597,7 +525,7 @@
borderWidthCombo.setText(Constants.EMPTY);
extBorderWidthCombo.select(0);
}
-
+ // set MARGIN and EXTENSION_MARGIN attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.MARGIN)) != null) {
String[] str = Util.convertExtString(tmp);
marginText.setText(str[0]);
@@ -612,7 +540,7 @@
marginText.setText(Constants.EMPTY);
extMarginCombo.select(0);
}
-
+ // set PADDING and EXTENSION_PADDING attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.PADDING)) != null) {
String[] str = Util.convertExtString(tmp);
paddingText.setText(str[0]);
@@ -627,5 +555,43 @@
paddingText.setText(Constants.EMPTY);
extPaddingCombo.select(0);
}
+ updateDataFromStyleAttributes = false;
}
-}
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ManualChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ManualChangeStyleListener[] getManualChangeStyleListeners() {
+ return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ManualChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
+}
\ No newline at end of file
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.EditorAreaHelper;
+import org.eclipse.ui.internal.EditorManager;
+import org.eclipse.ui.internal.WorkbenchPage;
+import org.eclipse.ui.internal.WorkbenchWindow;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
+
+/**
+ * Class for creating Preview sheet tab
+ */
+public class TabPreviewControl extends Composite {
+
+ /** Editor in which we open visual page. */
+ protected final static String EDITOR_ID =
"org.eclipse.wst.css.core.csssource.source"; //$NON-NLS-1$
+
+ private IFile cssFile = null;
+ private StructuredTextEditor editor = null;
+
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite The parent composite for tab
+ */
+ public TabPreviewControl(Composite tabFolder, StyleAttributes styleAttributes) {
+ super(tabFolder, SWT.NONE);
+ setLayout(new FillLayout());
+ }
+
+ /**
+ *
+ */
+ public void updateDataFile(IFile cssFile) {
+ if (cssFile != null) {
+ this.cssFile = cssFile;
+ IEditorInput input = new FileEditorInput(cssFile);
+
+ try {
+ WorkbenchWindow workbenchWindow =
(WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ EditorAreaHelper editorPresentation = new EditorAreaHelper((WorkbenchPage)
workbenchWindow.getActivePage());
+ EditorManager editorManager = new EditorManager(workbenchWindow, (WorkbenchPage)
workbenchWindow.getActivePage(), editorPresentation);
+
+ IEditorReference ref = editorManager.openEditor(EDITOR_ID, input, true, null);
+
+ if (ref != null) {
+// if (getChildren() != null && getChildren().length > 0) {
+ if (editor != null) {
+// editor.doRevertToSaved();
+// editor.dispose();
+ getChildren()[0].dispose();
+ }
+ editor = (StructuredTextEditor)ref.getEditor(true);
+ editor.createPartControl(this);
+ editor.getTextViewer().setEditable(false);
+ }
+
+ layout();
+ } catch (PartInitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void closeEditor(boolean save) {
+ if (editor != null) {
+ editor.close(save);
+ editor.doRevertToSaved();
+ }
+ }
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPropertySheetControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPropertySheetControl.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPropertySheetControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -18,11 +18,11 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.TabPropertySheetMouseAdapter;
@@ -37,12 +37,15 @@
private Tree tree;
private StyleAttributes styleAttributes;
+ private TabPropertySheetMouseAdapter propertySheetMouseAdapter = null;
+ boolean updateDataFromStyleAttributes = false;
+
/**
* Constructor for creating controls
*
* @param composite The parent composite for tab
*/
- public TabPropertySheetControl(TabFolder tabFolder, HashMap<String,
ArrayList<String>> elementMap,
+ public TabPropertySheetControl(Composite tabFolder, HashMap<String,
ArrayList<String>> elementMap,
HashMap<String, ArrayList<String>> comboMap, StyleAttributes
styleAttributes) {
super(tabFolder, SWT.NONE);
this.styleAttributes = styleAttributes;
@@ -65,7 +68,6 @@
item.setFont(Constants.FIRST_COLUMN,
JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
ArrayList<String> list = elementMap.get(str);
-
for (String strList : list) {
TreeItem subItem = new TreeItem(item, SWT.NONE);
subItem.setText(Constants.FIRST_COLUMN, strList);
@@ -74,8 +76,8 @@
updateData(false);
- tree.addMouseListener(new TabPropertySheetMouseAdapter(tree, elementMap,
comboMap, this));
-
+ propertySheetMouseAdapter = new TabPropertySheetMouseAdapter(tree, elementMap,
comboMap, this);
+ tree.addMouseListener(propertySheetMouseAdapter);
for (int i = 0; i < tree.getColumnCount(); i++) {
tree.getColumn(i).pack();
}
@@ -105,9 +107,12 @@
}
}
} else {
- for (int i = 0; i < tree.getItemCount(); i++)
- for (int j = 0; j < tree.getItem(i).getItemCount(); j++)
+ updateDataFromStyleAttributes = true;
+ for (int i = 0; i < tree.getItemCount(); i++) {
+ for (int j = 0; j < tree.getItem(i).getItemCount(); j++) {
tree.getItem(i).getItem(j).setText(Constants.SECOND_COLUMN,
Constants.EMPTY);
+ }
+ }
Set<String> set = styleAttributes.keySet();
for (String str : set) {
@@ -121,6 +126,7 @@
}
}
setExpanded();
+ updateDataFromStyleAttributes = false;
}
}
@@ -129,18 +135,15 @@
*/
private void setExpanded() {
TreeItem item = null;
-
for (int i = 0; i < tree.getItemCount(); i++) {
tree.getItem(i).setExpanded(false);
}
-
Set<String> set = styleAttributes.keySet();
for (String attr : set) {
if ((item = find(attr)) != null) {
item.setExpanded(true);
}
}
-
for (int i = 0; i < tree.getColumnCount(); i++) {
tree.getColumn(i).pack();
}
@@ -155,13 +158,10 @@
private TreeItem find(String attr) {
TreeItem item = null;
TreeItem subItem = null;
-
for (int i = 0; i < tree.getItemCount(); i++) {
item = tree.getItem(i);
-
for (int j = 0; j < item.getItemCount(); j++) {
subItem = item.getItem(j);
-
if (subItem.getText().equals(attr)) {
return item;
}
@@ -170,4 +170,24 @@
return null;
}
+
+ /**
+ * Gets the getUpdateDataFromStyleAttributes parameter value.
+ *
+ * @return boolean value
+ */
+ public boolean getUpdateDataFromStyleAttributes() {
+ return updateDataFromStyleAttributes;
+ }
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ if (propertySheetMouseAdapter != null) {
+ propertySheetMouseAdapter.addManualChangeStyleListener(listener);
+ }
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -10,12 +10,15 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
@@ -34,10 +37,8 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
-
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.outline.cssdialog.FontFamilyDialog;
@@ -46,14 +47,11 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.ImageCombo;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.StringTokenizer;
-
/**
* Class for creating control in Quick edit tab
*
@@ -70,8 +68,9 @@
private HashMap<String, ArrayList<String>> comboMap;
private StyleAttributes styleAttributes;
- //TODO Dzmitry Sakovich
- //private CSSDialog dialog;
+ private ArrayList<ManualChangeStyleListener> listeners = new
ArrayList<ManualChangeStyleListener>();
+ private boolean updateDataFromStyleAttributes = false;
+
/**
* Constructor for creating controls
*
@@ -81,8 +80,6 @@
StyleAttributes styleAttributes) {
super(sc, SWT.NONE);
- //TODO Dzmitry Sakovich
- //this.dialog = dialog;
this.styleAttributes = styleAttributes;
this.comboMap = comboMap;
@@ -90,22 +87,7 @@
gridLayout.numColumns = GRID_NUM_COLUMNS;
setLayout(gridLayout);
- ArrayList<String> listKeys = new ArrayList<String>();
- for (String key : styleAttributes.keySet()) {
- listKeys.add(key);
- }
- Collections.sort(listKeys);
- for (String key : listKeys) {
- label = new Label(this, SWT.LEFT);
- label.setText(format(key));
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
false));
-
- if (comboMap.keySet().contains(key)) {
- createCombo(key, styleAttributes.getAttribute(key));
- } else {
- createText(key, styleAttributes.getAttribute(key));
- }
- }
+ init();
}
/**
@@ -113,7 +95,6 @@
*/
public void updateData() {
Control[] controls = this.getChildren();
-
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
if (!controls[i].isDisposed()) {
@@ -122,25 +103,32 @@
}
}
+ init();
+ this.layout();
+ }
+
+ /**
+ * Initialize method.
+ */
+ private void init() {
ArrayList<String> listKeys = new ArrayList<String>();
for (String key : styleAttributes.keySet()) {
listKeys.add(key);
}
-
Collections.sort(listKeys);
+ updateDataFromStyleAttributes = true;
for (String key : listKeys) {
label = new Label(this, SWT.LEFT);
label.setText(format(key));
label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
false));
-
+ // each attribute might be represented in two ways
if (comboMap.keySet().contains(key)) {
createCombo(key, styleAttributes.getAttribute(key));
} else {
createText(key, styleAttributes.getAttribute(key));
}
}
-
- this.layout();
+ updateDataFromStyleAttributes = false;
}
/**
@@ -176,7 +164,6 @@
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
RGB startRgb =
Util.getColor((colorCombo.getText().toLowerCase().trim()));
-
if (startRgb == null) {
startRgb = Constants.RGB_BLACK;
}
@@ -188,7 +175,6 @@
RGB rgb = colorDialog.open();
if (rgb != null) {
String str = Util.createColorString(rgb);
-
if (ColorParser.getInstance().getMap().get(str) != null) {
colorCombo.setText(ColorParser.getInstance().getMap().get(str));
} else {
@@ -206,24 +192,21 @@
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
-
HashMap<String, String> colorMap = ColorParser.getInstance().getMap();
-
for (String key : colorMap.keySet()) {
RGB rgb = Util.getColor(key);
colorCombo.add(colorMap.get(key), rgb);
}
-
if (btn == null) {
new Label(this, SWT.NONE);
}
colorCombo.setText(value);
-
//if css attribute contain choose_folder button
} else if (Util.containFolder(name)) {
Composite tmpComposite = getCompositeElement();
@@ -251,7 +234,7 @@
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- IProject project = Util.getCurrentProject();
+ IAdaptable project = Util.getCurrentProject();
ImageSelectionDialog dialog = new
ImageSelectionDialog(getShell(),
new WorkbenchLabelProvider(), new
WorkbenchContentProvider());
String title = JstUIMessages.IMAGE_DIALOG_TITLE;
@@ -279,8 +262,9 @@
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
} else {
@@ -309,24 +293,20 @@
}
extCombo.select(extCombo.indexOf(values[EXT_VALUE_NUMBER]));
-
extCombo.addModifyListener(new ModifyListener() {
String key = name;
public void modifyText(ModifyEvent event) {
String tmpCombo = combo.getText().trim();
- if (tmpCombo == null) {
- return;
+ if (tmpCombo != null &&
!tmpCombo.equals(Constants.EMPTY)) {
+ String tmpExt = extCombo.getText();
+ if (tmpExt != null) {
+ styleAttributes.addAttribute(key, tmpCombo +
tmpExt);
+ }
}
- if (tmpCombo.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
- String tmpExt = extCombo.getText();
- if (tmpExt != null) {
- styleAttributes.addAttribute(key, tmpCombo + tmpExt);
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
- }
}
});
@@ -335,54 +315,49 @@
public void modifyText(ModifyEvent e) {
String currentText = combo.getText();
-
String[] items = combo.getItems();
-
for (int i = 0; i < items.length; i++) {
if (currentText.equalsIgnoreCase(items[i])) {
extCombo.select(VALUE_NUMBER);
extCombo.setEnabled(false);
styleAttributes.addAttribute(key, currentText);
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
return;
}
}
extCombo.setEnabled(true);
-
String tmp = combo.getText().trim();
- if (tmp != null) {
- if (!tmp.equals(Constants.EMPTY)) {
- String extTmp = extCombo.getText().trim();
-
- if (extTmp != null) {
- styleAttributes.addAttribute(key, tmp + extTmp);
- } else {
- styleAttributes.addAttribute(key, tmp);
- }
- } else {
- styleAttributes.removeAttribute(key);
- }
+ if (tmp != null && !tmp.equals(Constants.EMPTY)) {
+ String extTmp = extCombo.getText().trim();
+ if (extTmp != null) {
+ styleAttributes.addAttribute(key, tmp + extTmp);
+ } else {
+ styleAttributes.addAttribute(key, tmp);
+ }
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
} else {
-// new Label(this, SWT.NONE).setLayoutData(new GridData(GridData.END,
GridData.CENTER, false, false));
combo.addModifyListener(new ModifyListener() {
String key = name;
+
public void modifyText(ModifyEvent event) {
if (!combo.getText().trim().equals(Constants.EMPTY)) {
styleAttributes.addAttribute(key,
combo.getText().trim());
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
}
@@ -403,7 +378,6 @@
*/
private void createText(final String name, final String value) {
Button btn = null;
-
final Text text;
// create "button" in case of FONT_FAMILY style property
@@ -428,7 +402,6 @@
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FontFamilyDialog dialog = new FontFamilyDialog(getShell(),
text.getText());
-
if (dialog.open() == Window.OK) {
text.setText(dialog.getFontFamily());
}
@@ -444,8 +417,9 @@
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
} else {
@@ -473,50 +447,38 @@
public void modifyText(ModifyEvent event) {
String tmpCombo = text.getText().trim();
- if (tmpCombo == null) {
- return;
+ if (tmpCombo != null &&
!tmpCombo.equals(Constants.EMPTY)) {
+ String tmpExt = extCombo.getText();
+ if (tmpExt != null) {
+ styleAttributes.addAttribute(key, tmpCombo +
tmpExt);
+ }
}
- if (tmpCombo.equals(Constants.EMPTY)) {
- return;
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
}
- String tmpExt = extCombo.getText();
- if (tmpExt != null) {
- styleAttributes.addAttribute(key, tmpCombo + tmpExt);
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
- }
}
});
-
text.addModifyListener(new ModifyListener() {
String key = name;
public void modifyText(ModifyEvent e) {
String tmp = text.getText().trim();
-
- if (tmp != null) {
- if (!tmp.equals(Constants.EMPTY)) {
- String extTmp = extCombo.getText().trim();
-
- if (extTmp != null) {
- styleAttributes.addAttribute(key, tmp + extTmp);
- } else {
- styleAttributes.addAttribute(key, tmp);
- }
- } else {
- styleAttributes.removeAttribute(key);
- }
+ if (tmp != null && !tmp.equals(Constants.EMPTY)) {
+ String extTmp = extCombo.getText().trim();
+ if (extTmp != null) {
+ styleAttributes.addAttribute(key, tmp + extTmp);
+ } else {
+ styleAttributes.addAttribute(key, tmp);
+ }
} else {
styleAttributes.removeAttribute(key);
}
-
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
} else {
-// new Label(this, SWT.NONE).setLayoutData(new GridData(GridData.END,
GridData.CENTER, false, false));
-
text.addModifyListener(new ModifyListener() {
String key = name;
@@ -526,8 +488,9 @@
} else {
styleAttributes.removeAttribute(key);
}
- //TODO Dzmitry Sakovich
- //dialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
}
@@ -581,4 +544,41 @@
return finalStr;
}
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ManualChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ManualChangeStyleListener[] getManualChangeStyleListeners() {
+ return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ManualChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -42,6 +42,8 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.ImageCombo;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.ManualChangeStyleListener;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
@@ -65,8 +67,8 @@
private ArrayList<String> list;
private StyleAttributes styleAttributes;
- //TODO Dzmitry Sakovich
- //private Browser browser = null;
+ private ArrayList<ManualChangeStyleListener> listeners = new
ArrayList<ManualChangeStyleListener>();
+ private boolean updateDataFromStyleAttributes = false;
/**
* Constructor for creating controls
@@ -78,8 +80,6 @@
super(composite, SWT.NONE);
this.styleAttributes = styleAttributes;
- //TODO Dzmitry Sakovich
- //this.browser = dialog;
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = numColumns;
setLayout(gridLayout);
@@ -93,19 +93,17 @@
fontFamilyText = new Text(this, SWT.BORDER | SWT.SINGLE);
fontFamilyText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
fontFamilyText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = fontFamilyText.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_FAMILY, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_FAMILY);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.FONT_FAMILY, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.FONT_FAMILY);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
@@ -125,7 +123,6 @@
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FontFamilyDialog dialog = new FontFamilyDialog(getShell(),
fontFamilyText.getText());
-
if (dialog.open() == Window.OK) {
fontFamilyText.setText(dialog.getFontFamily());
}
@@ -141,19 +138,17 @@
colorCombo = new ImageCombo(this, SWT.BORDER);
colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
-
colorCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = colorCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.COLOR, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.COLOR);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.COLOR, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.COLOR);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
@@ -184,7 +179,6 @@
dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
RGB rgb = dlg.open();
-
if (rgb != null) {
String colorStr = Util.createColorString(rgb);
colorCombo.setText(colorStr);
@@ -207,22 +201,18 @@
extFontSizeCombo = new Combo(tmpComposite, SWT.BORDER | SWT.READ_ONLY);
extFontSizeCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
false, false));
-
extFontSizeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String fontSize = fontSizeCombo.getText().trim();
- if (fontSize == null) {
- return;
+ if (fontSize != null && !fontSize.equals(Constants.EMPTY)) {
+ String tmp = extFontSizeCombo.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(CSSConstants.FONT_SIZE, fontSize
+ tmp);
+ }
}
- if (fontSize.equals(Constants.EMPTY)) {
- return;
- }
- String tmp = extFontSizeCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.FONT_SIZE, fontSize +
tmp);
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
- }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
for (int i = 0; i < Constants.extSizes.length; i++) {
@@ -232,43 +222,34 @@
fontSizeCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String currentText = fontSizeCombo.getText();
-
list = comboMap.get(CSSConstants.FONT_SIZE);
-
for (String str : list) {
if (currentText.equals(str)) {
extFontSizeCombo.select(0);
extFontSizeCombo.setEnabled(false);
styleAttributes.addAttribute(CSSConstants.FONT_SIZE,
currentText);
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
return;
}
}
extFontSizeCombo.setEnabled(true);
-
String tmp = fontSizeCombo.getText();
-
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- String extFont = extFontSizeCombo.getText().trim();
-
- if (extFont != null) {
- styleAttributes.addAttribute(CSSConstants.FONT_SIZE, tmp
+ extFont);
- } else {
- styleAttributes.addAttribute(CSSConstants.FONT_SIZE,
tmp);
- }
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_SIZE);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ String extFont = extFontSizeCombo.getText().trim();
+ if (extFont != null) {
+ styleAttributes.addAttribute(CSSConstants.FONT_SIZE, tmp +
extFont);
+ } else {
+ styleAttributes.addAttribute(CSSConstants.FONT_SIZE, tmp);
+ }
} else {
styleAttributes.removeAttribute(CSSConstants.FONT_SIZE);
}
-
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.FONT_SIZE);
@@ -287,19 +268,17 @@
gridData.horizontalSpan = 2;
fontStyleCombo = new Combo(this, SWT.BORDER);
fontStyleCombo.setLayoutData(gridData);
-
fontStyleCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = fontStyleCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_STYLE, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_STYLE);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.FONT_STYLE, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.FONT_STYLE);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.FONT_STYLE);
@@ -318,19 +297,17 @@
gridData.horizontalSpan = 2;
fontWeigthCombo = new Combo(this, SWT.BORDER);
fontWeigthCombo.setLayoutData(gridData);
-
fontWeigthCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = fontWeigthCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_WEIGHT, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_WEIGHT);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.FONT_WEIGHT, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.FONT_WEIGHT);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.FONT_WEIGHT);
@@ -349,19 +326,17 @@
gridData.horizontalSpan = 2;
textDecorationCombo = new Combo(this, SWT.BORDER);
textDecorationCombo.setLayoutData(gridData);
-
textDecorationCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = textDecorationCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.TEXT_DECORATION,
tmp);
- } else {
-
styleAttributes.removeAttribute(CSSConstants.TEXT_DECORATION);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.TEXT_DECORATION, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.TEXT_DECORATION);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.TEXT_DECORATION);
@@ -380,19 +355,17 @@
gridData.horizontalSpan = 2;
textAlignCombo = new Combo(this, SWT.BORDER);
textAlignCombo.setLayoutData(gridData);
-
textAlignCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = textAlignCombo.getText();
- if (tmp != null) {
- if (tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.TEXT_ALIGN, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.TEXT_ALIGN);
- }
+ if (tmp != null && tmp.trim().length() > 0) {
+ styleAttributes.addAttribute(CSSConstants.TEXT_ALIGN, tmp);
+ } else {
+ styleAttributes.removeAttribute(CSSConstants.TEXT_ALIGN);
}
- //TODO Dzmitry Sakovich
- //cssDialog.setStyleForPreview();
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
}
});
list = comboMap.get(CSSConstants.TEXT_ALIGN);
@@ -418,26 +391,26 @@
}
/**
- * Method for get data in controls (if param equal true ), or set data (if
- * param equal false).
+ * Method for get data in controls (if parameter equal true ), or set data (if
parameter equal false).
*
* @param param
*/
public void updateData(boolean param) {
+ updateDataFromStyleAttributes = true;
String tmp;
-
+ // set FONT_FAMILY attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.FONT_FAMILY)) != null) {
fontFamilyText.setText(tmp);
} else {
fontFamilyText.setText(Constants.EMPTY);
}
-
+ // set COLOR attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.COLOR)) != null) {
colorCombo.setText(tmp);
} else {
colorCombo.setText(Constants.EMPTY);
}
-
+ // set FONT_SIZE and EXTENSION_FONT_SIZE attributes
if ((tmp = styleAttributes.getAttribute(CSSConstants.FONT_SIZE)) != null) {
String[] str = Util.convertExtString(tmp);
fontSizeCombo.setText(str[0]);
@@ -452,29 +425,67 @@
fontSizeCombo.setText(Constants.EMPTY);
extFontSizeCombo.select(0);
}
-
+ // set TEXT_DECORATION attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.TEXT_DECORATION)) != null)
{
textDecorationCombo.setText(tmp);
} else {
textDecorationCombo.setText(Constants.EMPTY);
}
-
+ // set FONT_STYLE attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.FONT_STYLE)) != null) {
fontStyleCombo.setText(tmp);
} else {
fontStyleCombo.setText(Constants.EMPTY);
}
-
+ // set FONT_WEIGHT attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.FONT_WEIGHT)) != null) {
fontWeigthCombo.setText(tmp);
} else {
fontWeigthCombo.setText(Constants.EMPTY);
}
-
+ // set TEXT_ALIGN attribute
if ((tmp = styleAttributes.getAttribute(CSSConstants.TEXT_ALIGN)) != null) {
textAlignCombo.setText(tmp);
} else {
textAlignCombo.setText(Constants.EMPTY);
}
+ updateDataFromStyleAttributes = false;
}
+
+ /**
+ * Add ManualChangeStyleListener object.
+ *
+ * @param listener ManualChangeStyleListener object to be added
+ */
+ public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Gets an array of ChangeStyleListener object.
+ *
+ * @return an array of ChangeStyleListener object
+ */
+ public ManualChangeStyleListener[] getManualChangeStyleListeners() {
+ return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
+ }
+
+ /**
+ * Remove ManualChangeStyleListener object passed by parameter.
+ *
+ * @param listener ManualChangeStyleListener object to be removed
+ */
+ public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method is used to notify all subscribed listeners about any changes within style
attribute map.
+ */
+ private void notifyListeners() {
+ ChangeStyleEvent event = new ChangeStyleEvent(this);
+ for (ManualChangeStyleListener listener : listeners) {
+ listener.styleChanged(event);
+ }
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2008-11-21
10:35:47 UTC (rev 11944)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2008-11-21
13:53:11 UTC (rev 11945)
@@ -10,34 +10,51 @@
******************************************************************************/
package org.jboss.tools.jst.web.ui.wizards.css;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
-
+import org.eclipse.ui.IWorkbenchWizard;
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogEvent;
+import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogListener;
-
+/**
+ * New CSS class wizard.
+ */
public class NewCSSClassWizard extends Wizard implements INewWizard {
- private NewCSSClassWizardPage page;
+ private static final String WIZARD_WINDOW_TITLE = "New CSS Class";
+
+ // workbench selection when the wizard was started
+ protected IStructuredSelection selection;
+ // the workbench instance
+ protected IWorkbench workbench;
+
+ // wizard contains only one page
+ private NewCSSClassWizardPage page;
+
/**
* Constructor for SampleNewWizard.
*/
public NewCSSClassWizard() {
super();
+ setWindowTitle(WIZARD_WINDOW_TITLE);
}
- /** {@link org.eclipse.ui.IWorkbenchWizard#init(IWorkbench, IStructuredSelection)}
*/
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- }
+ /**
+ * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ }
/**
* Adding the page to the wizard.
@@ -57,15 +74,36 @@
return true;
}
+ /**
+ * @see org.eclipse.jface.wizard.IWizard#canFinish()
+ */
+ @Override
+ public boolean canFinish() {
+ return page.showFinish;
+ }
+
+ /**
+ * @see org.eclipse.jface.wizard.IWizard#performCancel()
+ */
+ @Override
+ public boolean performCancel() {
+ page.cancel();
+ return true;
+ }
+
+ /**
+ * Class representing the first page of the wizard.
+ */
private class NewCSSClassWizardPage extends WizardPage {
// TODO: take out to the property manager file
- final static String WIZARD_WINDOW_TITLE = "New CSS Class";
final static String WIZARD_TITLE = "CSS Class";
final static String WIZARD_DESCRIPTION = "Create New CSS Class.";
private CSSClassDialog dialog;
+ boolean showFinish = false;
+
/**
* Constructor for SampleNewWizardPage.
*
@@ -73,7 +111,6 @@
*/
public NewCSSClassWizardPage() {
super("newCSSClassWizard");
- setWindowTitle(WIZARD_WINDOW_TITLE);
setTitle(WIZARD_TITLE);
setDescription(WIZARD_DESCRIPTION);
}
@@ -86,13 +123,69 @@
GridLayout layout = new GridLayout();
container.setLayout(layout);
- dialog = new CSSClassDialog(getShell(), true);
+ // Initialize CSS dialog that is integrated to CSS wizard.
+ // Also it can be used separately without integration to wizard component.
+ dialog = new CSSClassDialog(getShell(), selection, true);
+ dialog.addMessageDialogListener(new MessageDialogListener() {
+ @Override
+ public void throwMessage(MessageDialogEvent event) {
+ if (event != null) {
+ IStatus status = event.getOperationStatus();
+ if (status != null) {
+ applyToStatusLine(status);
+ }
+ getWizard().getContainer().updateButtons();
+ }
+ }
+ });
dialog.createDialogComposite(container);
setControl(container);
}
+ /**
+ * Save page model.
+ */
public void saveChanges() {
dialog.saveChanges();
}
+
+ /**
+ * Handle cancel operation correctly.
+ */
+ public void cancel() {
+ dialog.closeDialog();
+ }
+
+ /**
+ * Applies the status to the status line of a dialog page.
+ */
+ private void applyToStatusLine(IStatus status) {
+ String message= status.getMessage();
+ if (message.length() == 0) {
+ message = null;
+ }
+ switch (status.getSeverity()) {
+ case IStatus.OK:
+ setErrorMessage(null);
+ setMessage(message);
+ showFinish = true;
+ break;
+ case IStatus.WARNING:
+ setErrorMessage(null);
+ showFinish = true;
+ setMessage(message, WizardPage.WARNING);
+ break;
+ case IStatus.INFO:
+ setErrorMessage(null);
+ showFinish = true;
+ setMessage(message, WizardPage.INFORMATION);
+ break;
+ default:
+ setErrorMessage(message);
+ setMessage(null);
+ showFinish = false;
+ break;
+ }
+ }
}
}