Author: dmaliarevich
Date: 2011-01-28 09:58:43 -0500 (Fri, 28 Jan 2011)
New Revision: 28700
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/StyleFormatController.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-8220 , CSSStyleDialog should be on the Formatting
toolbar
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml 2011-01-28 14:42:16
UTC (rev 28699)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/resources/textFormatting.xml 2011-01-28 14:58:43
UTC (rev 28700)
@@ -24,4 +24,7 @@
<vpe:format type="ForegroundColorFormat">
<vpe:formatAttribute type="style" />
</vpe:format>
+ <vpe:format type="StyleFormat">
+ <vpe:formatAttribute type="style" />
+ </vpe:format>
</vpe:textFormatting>
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java 2011-01-28
14:42:16 UTC (rev 28699)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java 2011-01-28
14:58:43 UTC (rev 28700)
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * 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.vpe.editor.template.textformating;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
-
-/**
- * Class contains data from template for text formating (Text Formating Tollbar).
- * @author Igels
- */
-public class TextFormatingData {
-
- private FormatData[] formats;
-
- /**
- * @param templateTextFormatingElement - Element <vpe:textFormatting>
- */
- public TextFormatingData(Element templateTextFormatingElement) {
- NodeList list =
templateTextFormatingElement.getElementsByTagName(VpeTemplateManager.TAG_FORMAT);
-
- List<FormatData> defaultFormats = new ArrayList<FormatData>();
-
- if(VpeTemplateManager.ATTR_VALUE_YES.
- equals(templateTextFormatingElement.getAttribute(VpeTemplateManager.ATTR_USE_DEFAULT_FORMATS)))
{
- //adds default format data
- FormatData[] formats
=VpeTemplateManager.getDefaultTextFormattingData().getAllFormatData();
- for (FormatData formatData :formats) {
-
- defaultFormats.add(formatData);
- }
- }
- List<FormatData> localFormats=new ArrayList<FormatData>();
-
- for(int i=0;i<list.getLength();i++) {
- Element element = (Element)list.item(i);
- localFormats.add(new FormatData(element));
- }
- formats=(FormatData[])mergeLocalAndDefaultFormats(defaultFormats,
localFormats).toArray(new FormatData[0]);
- }
- /**
- * Merges local and default formats.
- * If format with some type exist in local copy and remote, we use
- * local format
- *
- * @return merged list
- */
- private List<FormatData> mergeLocalAndDefaultFormats(List<FormatData>
defaultFormats,List<FormatData> localFormats) {
-
- List<FormatData> result = new ArrayList<FormatData>(localFormats);
- for (FormatData formatData : defaultFormats) {
- if(!isFormatExistInList(result,formatData)) {
- result.add(formatData);
- }
- }
- return result;
- }
-
- private boolean isFormatExistInList(List<FormatData> formatData, FormatData data)
{
-
- if(data.getType()==null) {
-
- return false;
- }
-
- for (FormatData format : formatData) {
-
- if(data.getType().equals(format.getType())) {
- return true;
- }
- }
-
- return false;
- }
- /**
- * @return children - <vpe:format>
- */
- public FormatData[] getAllFormatData() {
- return formats;
- }
-
- /**
- * @param type
- * @return
- */
- public FormatData[] getFormatDatas(String type) {
- ArrayList<FormatData> result = new ArrayList<FormatData>();
- for(int i=0; i<formats.length; i++) {
- if(type.equals(formats[i].getType())) {
- result.add(formats[i]);
- }
- }
- return result.toArray(new FormatData[]{});
- }
-
- /**
- * @param type
- * @return
- */
- public boolean hasFormatData(String type) {
- return getFormatDatas(type).length>0;
- }
-
-}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/textformating/TextFormatingData.java 2011-01-28
14:58:43 UTC (rev 28700)
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * 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.vpe.editor.template.textformating;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+
+/**
+ * Class contains data from template for text formating (Text Formating Tollbar).
+ * @author Igels
+ */
+public class TextFormatingData {
+
+ private FormatData[] formats;
+
+ /**
+ * @param templateTextFormatingElement - Element <vpe:textFormatting>
+ */
+ public TextFormatingData(Element templateTextFormatingElement) {
+ NodeList list =
templateTextFormatingElement.getElementsByTagName(VpeTemplateManager.TAG_FORMAT);
+
+ List<FormatData> defaultFormats = new ArrayList<FormatData>();
+
+ if(VpeTemplateManager.ATTR_VALUE_YES.
+ equals(templateTextFormatingElement.getAttribute(VpeTemplateManager.ATTR_USE_DEFAULT_FORMATS)))
{
+ //adds default format data
+ FormatData[] formats
=VpeTemplateManager.getDefaultTextFormattingData().getAllFormatData();
+ for (FormatData formatData :formats) {
+
+ defaultFormats.add(formatData);
+ }
+ }
+ List<FormatData> localFormats=new ArrayList<FormatData>();
+
+ for(int i=0;i<list.getLength();i++) {
+ Element element = (Element)list.item(i);
+ localFormats.add(new FormatData(element));
+ }
+ formats=(FormatData[])mergeLocalAndDefaultFormats(defaultFormats,
localFormats).toArray(new FormatData[0]);
+ }
+ /**
+ * Merges local and default formats.
+ * If format with some type exist in local copy and remote, we use
+ * local format
+ *
+ * @return merged list
+ */
+ private List<FormatData> mergeLocalAndDefaultFormats(List<FormatData>
defaultFormats,List<FormatData> localFormats) {
+
+ List<FormatData> result = new ArrayList<FormatData>(localFormats);
+ for (FormatData formatData : defaultFormats) {
+ if(!isFormatExistInList(result,formatData)) {
+ result.add(formatData);
+ }
+ }
+ return result;
+ }
+
+ private boolean isFormatExistInList(List<FormatData> formatData, FormatData data)
{
+
+ if(data.getType()==null) {
+
+ return false;
+ }
+
+ for (FormatData format : formatData) {
+
+ if(data.getType().equals(format.getType())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ /**
+ * @return children - <vpe:format>
+ */
+ public FormatData[] getAllFormatData() {
+ return formats;
+ }
+
+ /**
+ * @param type
+ * @return
+ */
+ public FormatData[] getFormatDatas(String type) {
+ ArrayList<FormatData> result = new ArrayList<FormatData>();
+ for(int i=0; i<formats.length; i++) {
+ if(type.equals(formats[i].getType())) {
+ result.add(formats[i]);
+ }
+ }
+ return result.toArray(new FormatData[]{});
+ }
+
+ /**
+ * @param type
+ * @return
+ */
+ public boolean hasFormatData(String type) {
+ return getFormatDatas(type).length>0;
+ }
+
+}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/StyleFormatController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/StyleFormatController.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/StyleFormatController.java 2011-01-28
14:58:43 UTC (rev 28700)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 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.vpe.editor.toolbar.format;
+
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.jst.css.dialog.CSSStyleDialog;
+import org.jboss.tools.vpe.editor.template.textformating.FormatAttributeData;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author dmaliarevich
+ *
+ * CSSStyleDialog should be on the Formatting toolbar.
+ *
https://issues.jboss.org/browse/JBIDE-8220
+ */
+public class StyleFormatController extends AttributeFormatController {
+
+ public static final String TYPE = "StyleFormat"; //$NON-NLS-1$
+
+ protected ToolItem toolItem;
+ private String styleString = null;
+
+ public StyleFormatController(FormatControllerManager manager, ToolItem toolItem) {
+ super(manager);
+ this.toolItem = toolItem;
+ setToolbarItemEnabled(false);
+ }
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+
+ @Override
+ public void setToolbarItemEnabled(boolean enabled) {
+ toolItem.setEnabled(enabled);
+ }
+
+ @Override
+ public void handleEvent(Event event) {
+ String baseStyle = ""; //$NON-NLS-1$
+ Node node = manager.getCurrentSelectedNode();
+ /*
+ * Try to get style attribute value
+ */
+ if (node instanceof Element) {
+ Element element = (Element) node;
+ if (element.hasAttribute(FormatAttributeData.STYLE_TYPE)) {
+ baseStyle = element.getAttribute(FormatAttributeData.STYLE_TYPE);
+ }
+ }
+ /*
+ * Open the dialog
+ */
+ CSSStyleDialog cssDialog = new CSSStyleDialog(PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell(), baseStyle);
+ if (cssDialog.open() == Window.OK) {
+ styleString = cssDialog.getStyle();
+ }
+ super.handleEvent(event);
+ }
+
+ @Override
+ protected void setStyle(Attr styleAttribute,
+ FormatAttributeData templateData) {
+ /*
+ * 'styleString' is not null when user has pressed OK in the dialog.
+ * Thus node's style should be replaced with the new value.
+ * Otherwise nothing should be and will be changed.
+ */
+ if (null != styleString) {
+ styleAttribute.setValue(styleString);
+ }
+ }
+
+ @Override
+ protected boolean isStyleSet(Attr attribute,
+ FormatAttributeData templateData) {
+ return false;
+ }
+
+ @Override
+ public void setToolbarItemSelection() {
+ /*
+ * Do nothing
+ */
+ }
+
+ @Override
+ protected void setToolbarItemSelection(boolean selected) {
+ /*
+ * Do nothing
+ */
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2011-01-28
14:42:16 UTC (rev 28699)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/format/TextFormattingToolBar.java 2011-01-28
14:58:43 UTC (rev 28700)
@@ -26,6 +26,8 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
+import org.jboss.tools.jst.css.CSSPlugin;
+import org.jboss.tools.jst.css.dialog.common.Util;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.toolbar.SplitToolBar;
@@ -169,7 +171,17 @@
listener = new ForegroundColorFormatController(formatControllerManager, item);
item.addListener(SWT.Selection, listener);
// itemDescriptors.add(new ToolItemDescriptor(item, true, listener, true));
-
+
+ /*
+ * Fixes
https://issues.jboss.org/browse/JBIDE-8220
+ * CSSStyleDialog should be on the Formatting toolbar.
+ */
+ item = createToolItem(toolBar, SWT.CHECK,
+ CSSPlugin.getImageDescriptor(Util.IMAGE_COLORLARGE_FILE_LOCATION).createImage(),
+ VpeUIMessages.EDIT_STYLE_ATTRIBUTE);
+ listener = new StyleFormatController(formatControllerManager, item);
+ item.addListener(SWT.Selection, listener);
+
// sep = new ToolItem(horBar, SWT.SEPARATOR);
//
// item = createToolItem(horBar, SWT.PUSH, "icons/left.gif",
VpeToolbarFormatMessages.getInstance().getString(ALIGN_LEFT_KEY));
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2011-01-28
14:42:16 UTC (rev 28699)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2011-01-28
14:58:43 UTC (rev 28700)
@@ -62,6 +62,7 @@
public static String ITALIC;
public static String UNDERLINE;
public static String FOREGROUND_COLOR;
+ public static String EDIT_STYLE_ATTRIBUTE;
public static String VPE_UPDATE_JOB_TITLE;
public static String VPE_VISUAL_REFRESH_JOB;
public static String VpeDnD_PLACE_AFTER_INSIDE;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2011-01-28
14:42:16 UTC (rev 28699)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2011-01-28
14:58:43 UTC (rev 28700)
@@ -45,6 +45,7 @@
ITALIC=Italic
UNDERLINE=Underline
FOREGROUND_COLOR=Foreground Color
+EDIT_STYLE_ATTRIBUTE=Edit Style
VPE_UPDATE_JOB_TITLE=Visual Editor View Update
VPE_VISUAL_REFRESH_JOB=Visual Editor Refresh