Author: izhukov
Date: 2008-12-03 12:38:15 -0500 (Wed, 03 Dec 2008)
New Revision: 12253
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/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/TabQuickEditControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java
Log:
JBIDE-3340 fixed
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-12-03
17:35:01 UTC (rev 12252)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2008-12-03
17:38:15 UTC (rev 12253)
@@ -194,20 +194,15 @@
((CSSStyleRule)
list.item(i)).getSelectorText().equals(selector)) {
CSSStyleRule rule = (CSSStyleRule) list.item(i);
+ styleSheet.deleteRule(i);
+
+ i = styleSheet.insertRule(selector + startBraces +
styleAttributes.getStyle() + endBraces, i);
+ rule = (CSSStyleRule) list.item(i);
CSSStyleDeclaration declaration = rule.getStyle();
- // previously before updating remove all existing properties
- while (declaration.getLength() > 0) {
- declaration.removeProperty(declaration.item(0));
- }
// set properties
Set<Entry<String, String>> set =
styleAttributes.entrySet();
for (Map.Entry<String, String> me : set) {
-// try {
- declaration.setProperty(me.getKey(), me.getValue(),
Constants.EMPTY);
-// } catch (Exception e) {
-// declaration.removeProperty(me.getKey());
-// e.printStackTrace();
-// }
+ declaration.setProperty(me.getKey(), me.getValue(),
Constants.EMPTY);
}
formatProcessorCSS.formatModel(model);
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-12-03
17:35:01 UTC (rev 12252)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java 2008-12-03
17:38:15 UTC (rev 12253)
@@ -90,18 +90,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.BACKGROUND_COLOR,
tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.BACKGROUND_COLOR);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(colorCombo.getText(), CSSConstants.BACKGROUND_COLOR);
+ }
+ });
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
for (Map.Entry<String, String> me : set) {
RGB rgb = Util.getColor(me.getKey());
@@ -151,7 +143,7 @@
backgroundImageCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String tmp = backgroundImageCombo.getText();
- if (tmp != null && tmp.trim().length() > 0) {
+ if (tmp != null && !tmp.trim().equals(Constants.EMPTY)) {
tmp = adjustBackgroundURL(tmp);
styleAttributes.addAttribute(CSSConstants.BACKGROUND_IMAGE, tmp.trim());
} else {
@@ -210,15 +202,7 @@
backgroundRepeatCombo.setLayoutData(gridData);
backgroundRepeatCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
- String tmp = backgroundRepeatCombo.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.BACKGROUND_REPEAT, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.BACKGROUND_REPEAT);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
+ modifyAttribute(backgroundRepeatCombo.getText(),
CSSConstants.BACKGROUND_REPEAT);
}
});
ArrayList<String> list = comboMap.get(CSSConstants.BACKGROUND_REPEAT);
@@ -253,6 +237,23 @@
updateDataFromStyleAttributes = false;
}
+ /**
+ * Method is used to correctly process modify event occurred on specify CSS attribute
control.
+ *
+ * @param attributeValue changed value of control were action takes place
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyAttribute(String attributeValue, String attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ styleAttributes.addAttribute(attributeName, attributeValue.trim());
+ } else {
+ styleAttributes.removeAttribute(attributeName);
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
// Fix for JBIDE-3084
// in css background image should always be wrapped into url(*);
private static String adjustBackgroundURL(String backgroundURL) {
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-12-03
17:35:01 UTC (rev 12252)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java 2008-12-03
17:38:15 UTC (rev 12253)
@@ -102,42 +102,17 @@
widthText = new Text(this, SWT.BORDER | SWT.SINGLE);
widthText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
widthText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent event) {
- String tmp = widthText.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extWidth = extWidthCombo.getText();
- if (extWidth != null) {
- tmp += extWidth;
- }
- styleAttributes.addAttribute(CSSConstants.WIDTH, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.WIDTH);
- extWidthCombo.select(0);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent e) {
+ modifyAttribute(widthText.getText(), extWidthCombo, CSSConstants.WIDTH);
+ }
+ });
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();
- if (width != null && !width.trim().equals(Constants.EMPTY))
{
- String tmp = extWidthCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.WIDTH, width +
tmp);
- }
- } else {
- extWidthCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(widthText.getText(), extWidthCombo, CSSConstants.WIDTH);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extWidthCombo.add(Constants.extSizes[i]);
}
@@ -152,42 +127,17 @@
heightText = new Text(this, SWT.BORDER | SWT.SINGLE);
heightText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
heightText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent event) {
- String tmp = heightText.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extHeight = extHeightCombo.getText();
- if (extHeight != null) {
- tmp += extHeight;
- }
- styleAttributes.addAttribute(CSSConstants.HEIGHT, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.HEIGHT);
- extHeightCombo.select(0);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent e) {
+ modifyAttribute(heightText.getText(), extHeightCombo, CSSConstants.HEIGHT);
+ }
+ });
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();
- if (height != null && !height.trim().equals(Constants.EMPTY))
{
- String tmp = extHeightCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.HEIGHT, height +
tmp);
- }
- } else {
- extHeightCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(heightText.getText(), extHeightCombo, CSSConstants.HEIGHT);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extHeightCombo.add(Constants.extSizes[i]);
}
@@ -209,18 +159,10 @@
borderStyleCombo = new Combo(this, SWT.BORDER);
borderStyleCombo.setLayoutData(gridData);
borderStyleCombo.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent event) {
- String tmp = borderStyleCombo.getText();
- if (tmp != null && !tmp.trim().equals(Constants.EMPTY)) {
- styleAttributes.addAttribute(CSSConstants.BORDER_STYLE,
tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.BORDER_STYLE);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(borderStyleCombo.getText(), CSSConstants.BORDER_STYLE);
+ }
+ });
list = comboMap.get(CSSConstants.BORDER_STYLE);
for (String str : list) {
borderStyleCombo.add(str);
@@ -237,18 +179,10 @@
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 && !tmp.trim().equals(Constants.EMPTY)) {
- styleAttributes.addAttribute(CSSConstants.BORDER_COLOR,
tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.BORDER_COLOR);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(borderColorCombo.getText(), CSSConstants.BORDER_COLOR);
+ }
+ });
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
for (Map.Entry<String, String> me : set) {
RGB rgb = Util.getColor(me.getKey());
@@ -307,20 +241,7 @@
}
}
extBorderWidthCombo.setEnabled(true);
- String tmp = borderWidthCombo.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extBorderWidth = extBorderWidthCombo.getText();
- if (extBorderWidth != null) {
- tmp += extBorderWidth;
- }
- styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.BORDER_WIDTH);
- extBorderWidthCombo.select(0);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
+ modifyAttribute(borderWidthCombo.getText(), extBorderWidthCombo,
CSSConstants.BORDER_WIDTH);
}
});
list = comboMap.get(CSSConstants.BORDER_WIDTH);
@@ -330,22 +251,10 @@
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();
- if (borderWidth != null &&
!borderWidth.trim().equals(Constants.EMPTY)) {
- String tmp = extBorderWidthCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.BORDER_WIDTH,
borderWidth + tmp);
- }
- } else {
- extBorderWidthCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(borderWidthCombo.getText(), extBorderWidthCombo,
CSSConstants.BORDER_WIDTH);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extBorderWidthCombo.add(Constants.extSizes[i]);
}
@@ -365,42 +274,18 @@
marginText = new Text(this, SWT.BORDER | SWT.SINGLE);
marginText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
marginText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent event) {
- String tmp = marginText.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extMargin = extMarginCombo.getText();
- if (extMargin != null) {
- tmp += extMargin;
- }
- styleAttributes.addAttribute(CSSConstants.MARGIN, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.MARGIN);
- extMarginCombo.select(0);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent e) {
+ modifyAttribute(marginText.getText(), extMarginCombo, CSSConstants.MARGIN);
+ }
+ });
+
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();
- if (margin != null && !margin.trim().equals(Constants.EMPTY))
{
- String tmp = extMarginCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.MARGIN, margin +
tmp);
- }
- } else {
- extMarginCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(marginText.getText(), extMarginCombo, CSSConstants.MARGIN);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extMarginCombo.add(Constants.extSizes[i]);
}
@@ -415,42 +300,17 @@
paddingText = new Text(this, SWT.BORDER | SWT.SINGLE);
paddingText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
false));
paddingText.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent event) {
- String tmp = paddingText.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extPadding = extPaddingCombo.getText();
- if (extPadding != null) {
- tmp += extPadding;
- }
- styleAttributes.addAttribute(CSSConstants.PADDING, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.PADDING);
- extPaddingCombo.select(0);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent e) {
+ modifyAttribute(paddingText.getText(), extPaddingCombo, CSSConstants.PADDING);
+ }
+ });
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();
- if (padding != null &&
!padding.trim().equals(Constants.EMPTY)) {
- String tmp = extPaddingCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.PADDING, padding +
tmp);
- }
- } else {
- extPaddingCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(paddingText.getText(), extPaddingCombo,
CSSConstants.PADDING);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extPaddingCombo.add(Constants.extSizes[i]);
}
@@ -543,6 +403,70 @@
}
/**
+ * Method is used to correctly process modify event occurred on specify CSS attribute
control.
+ *
+ * @param attributeValue changed value of control were action takes place
+ * @param extAttribute the attribute extension control that might be also affected
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyAttribute(String attributeValue, Combo extAttribute, String
attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ String extWidth = extAttribute.getText();
+ if (extWidth != null) {
+ attributeValue += extWidth;
+ }
+ styleAttributes.addAttribute(attributeName, attributeValue);
+ } else {
+ styleAttributes.removeAttribute(attributeName);
+ extAttribute.select(0);
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
+ * Method is used to correctly process modify event occurred on specify CSS extension
attribute control.
+ *
+ * @param attributeValue current value of attribute control
+ * @param extAttribute the attribute extension control were action takes place
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyExtAttribute(String attributeValue, Combo extAttribute, String
attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ String tmp = extAttribute.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(attributeName, attributeValue + tmp);
+ }
+ } else {
+ if (extAttribute.getSelectionIndex() > 0) {
+ extAttribute.select(0);
+ }
+ return;
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
+ * Method is used to correctly process modify event occurred on specify CSS attribute
control.
+ *
+ * @param attributeValue changed value of control were action takes place
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyAttribute(String attributeValue, String attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ styleAttributes.addAttribute(attributeName, attributeValue.trim());
+ } else {
+ styleAttributes.removeAttribute(attributeName);
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
* Add ManualChangeStyleListener object.
*
* @param listener ManualChangeStyleListener object to be added
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-12-03
17:35:01 UTC (rev 12252)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java 2008-12-03
17:38:15 UTC (rev 12253)
@@ -305,7 +305,9 @@
styleAttributes.addAttribute(key, tmpCombo +
tmpExt);
}
} else {
- extCombo.select(0);
+ if (extCombo.getSelectionIndex() > 0) {
+ extCombo.select(0);
+ }
return;
}
if (!updateDataFromStyleAttributes) {
@@ -455,7 +457,9 @@
styleAttributes.addAttribute(key, tmpCombo +
tmpExt);
}
} else {
- extCombo.select(0);
+ if (extCombo.getSelectionIndex() > 0) {
+ extCombo.select(0);
+ }
return;
}
if (!updateDataFromStyleAttributes) {
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-12-03
17:35:01 UTC (rev 12252)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java 2008-12-03
17:38:15 UTC (rev 12253)
@@ -94,19 +94,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_FAMILY, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_FAMILY);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
-
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(fontFamilyText.getText(), CSSConstants.FONT_FAMILY);
+ }
+ });
Button button = new Button(this, SWT.PUSH);
button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
button.setToolTipText(JstUIMessages.FONT_FAMILY_TIP);
@@ -139,18 +130,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.COLOR, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.COLOR);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(colorCombo.getText(), CSSConstants.COLOR);
+ }
+ });
Set<Entry<String, String>> set =
ColorParser.getInstance().getMap().entrySet();
for (Map.Entry<String, String> me : set) {
RGB rgb = Util.getColor(me.getKey());
@@ -202,22 +185,10 @@
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();
- if (fontSize != null &&
!fontSize.trim().equals(Constants.EMPTY)) {
- String tmp = extFontSizeCombo.getText();
- if (tmp != null) {
- styleAttributes.addAttribute(CSSConstants.FONT_SIZE, fontSize
+ tmp);
- }
- } else {
- extFontSizeCombo.select(0);
- return;
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyExtAttribute(fontSizeCombo.getText(), extFontSizeCombo,
CSSConstants.FONT_SIZE);
+ }
+ });
for (int i = 0; i < Constants.extSizes.length; i++) {
extFontSizeCombo.add(Constants.extSizes[i]);
}
@@ -239,19 +210,7 @@
}
extFontSizeCombo.setEnabled(true);
- String tmp = fontSizeCombo.getText();
- if (tmp != null && tmp.trim().length() > 0) {
- String extFont = extFontSizeCombo.getText();
- if (extFont != null) {
- tmp += extFont;
- }
- styleAttributes.addAttribute(CSSConstants.FONT_SIZE, tmp);
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_SIZE);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
+ modifyAttribute(fontSizeCombo.getText(), extFontSizeCombo,
CSSConstants.BORDER_WIDTH);
}
});
list = comboMap.get(CSSConstants.FONT_SIZE);
@@ -271,18 +230,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_STYLE, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_STYLE);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(fontStyleCombo.getText(), CSSConstants.FONT_STYLE);
+ }
+ });
list = comboMap.get(CSSConstants.FONT_STYLE);
for (String str : list) {
fontStyleCombo.add(str);
@@ -300,18 +251,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.FONT_WEIGHT, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.FONT_WEIGHT);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(fontWeigthCombo.getText(), CSSConstants.FONT_WEIGHT);
+ }
+ });
list = comboMap.get(CSSConstants.FONT_WEIGHT);
for (String str : list) {
fontWeigthCombo.add(str);
@@ -329,18 +272,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.TEXT_DECORATION,
tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.TEXT_DECORATION);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(textDecorationCombo.getText(), CSSConstants.TEXT_DECORATION);
+ }
+ });
list = comboMap.get(CSSConstants.TEXT_DECORATION);
for (String str : list) {
textDecorationCombo.add(str);
@@ -358,18 +293,10 @@
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 && tmp.trim().length() > 0) {
- styleAttributes.addAttribute(CSSConstants.TEXT_ALIGN, tmp.trim());
- } else {
- styleAttributes.removeAttribute(CSSConstants.TEXT_ALIGN);
- }
- if (!updateDataFromStyleAttributes) {
- notifyListeners();
- }
- }
- });
+ public void modifyText(ModifyEvent event) {
+ modifyAttribute(textAlignCombo.getText(), CSSConstants.TEXT_ALIGN);
+ }
+ });
list = comboMap.get(CSSConstants.TEXT_ALIGN);
for (String str : list) {
textAlignCombo.add(str);
@@ -443,6 +370,70 @@
}
/**
+ * Method is used to correctly process modify event occurred on specify CSS attribute
control.
+ *
+ * @param attributeValue changed value of control were action takes place
+ * @param extAttribute the attribute extension control that might be also affected
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyAttribute(String attributeValue, Combo extAttribute, String
attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ String extWidth = extAttribute.getText();
+ if (extWidth != null) {
+ attributeValue += extWidth;
+ }
+ styleAttributes.addAttribute(attributeName, attributeValue);
+ } else {
+ styleAttributes.removeAttribute(attributeName);
+ extAttribute.select(0);
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
+ * Method is used to correctly process modify event occurred on specify CSS extension
attribute control.
+ *
+ * @param attributeValue current value of attribute control
+ * @param extAttribute the attribute extension control were action takes place
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyExtAttribute(String attributeValue, Combo extAttribute, String
attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ String tmp = extAttribute.getText();
+ if (tmp != null) {
+ styleAttributes.addAttribute(attributeName, attributeValue + tmp);
+ }
+ } else {
+ if (extAttribute.getSelectionIndex() > 0) {
+ extAttribute.select(0);
+ }
+ return;
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
+ * Method is used to correctly process modify event occurred on specify CSS attribute
control.
+ *
+ * @param attributeValue changed value of control were action takes place
+ * @param attributeName CSS name of the first parameter
+ */
+ private void modifyAttribute(String attributeValue, String attributeName) {
+ if (attributeValue != null &&
!attributeValue.trim().equals(Constants.EMPTY)) {
+ styleAttributes.addAttribute(attributeName, attributeValue.trim());
+ } else {
+ styleAttributes.removeAttribute(attributeName);
+ }
+ if (!updateDataFromStyleAttributes) {
+ notifyListeners();
+ }
+ }
+
+ /**
* Add ManualChangeStyleListener object.
*
* @param listener ManualChangeStyleListener object to be added