JBoss Tools SVN: r15467 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 08:09:17 -0400 (Sat, 23 May 2009)
New Revision: 15467
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4317
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java 2009-05-23 11:05:30 UTC (rev 15466)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java 2009-05-23 12:09:17 UTC (rev 15467)
@@ -186,6 +186,8 @@
} else {
setPreviewContent(text);
}
+
+ browser.setText(generateBrowserPage());
previewText.setVisible(false);
browser.setVisible(true);
previewComposite.layout();
15 years, 4 months
JBoss Tools SVN: r15466 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 07:05:30 -0400 (Sat, 23 May 2009)
New Revision: 15466
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4317
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 2009-05-23 10:58:35 UTC (rev 15465)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-05-23 11:05:30 UTC (rev 15466)
@@ -249,6 +249,7 @@
* - name of new style class
*/
public void addNewClass(String styleClassName) {
+ getStyleComposite().clearStyleComposite();
cssModel.updateCSSStyle(selectorLabel, getStyleAttributes());
selectorLabel = cssModel.addCSSRule(styleClassName);
preview.setSelector(selectorLabel);
15 years, 4 months
JBoss Tools SVN: r15465 - trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 06:58:35 -0400 (Sat, 23 May 2009)
New Revision: 15465
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4317
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 2009-05-23 10:42:57 UTC (rev 15464)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2009-05-23 10:58:35 UTC (rev 15465)
@@ -92,8 +92,10 @@
*/
@Override
public boolean performFinish() {
- editFilePage.dialog.save();
- editFilePage.dialog.releaseResources();
+ if (editFilePage.dialog != null) {
+ editFilePage.dialog.save();
+ editFilePage.dialog.releaseResources();
+ }
return true;
}
@@ -112,7 +114,9 @@
*/
@Override
public boolean performCancel() {
- editFilePage.dialog.releaseResources();
+ if (editFilePage.dialog != null) {
+ editFilePage.dialog.releaseResources();
+ }
return true;
}
@@ -164,9 +168,10 @@
public void createControl(final Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
-
+
container.setLayout(new GridLayout(1, true));
- GridData gridData = new GridData(GridData.FILL,GridData.FILL,true,true);
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL,
+ true, true);
container.setLayoutData(gridData);
if (getWizard().getContainer() instanceof WizardDialog) {
@@ -178,8 +183,8 @@
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == editFilePage) {
- if (dialog == null) {
- dialog = new CSSClassDialog(getShell(),
+ if (dialog == null) {
+ dialog = new CSSClassDialog(getShell(),
(IFile) classDescription.getCssFile(),
selection) {
protected void handleStatusChanged(
@@ -201,7 +206,7 @@
};
dialog.createControlPane(container);
container.layout();
- }else {
+ } else {
dialog.setFile((IFile) classDescription
.getCssFile());
}
15 years, 4 months
JBoss Tools SVN: r15464 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 06:42:57 -0400 (Sat, 23 May 2009)
New Revision: 15464
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4317
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-05-23 10:14:35 UTC (rev 15463)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2009-05-23 10:42:57 UTC (rev 15464)
@@ -144,7 +144,7 @@
public void widgetSelected(SelectionEvent event) {
CSSStyleDialog cssDialog = new CSSStyleDialog(composite.getShell(),txtStyle.getText());
if (cssDialog.open() == Window.OK) {
- txtStyle.setText(cssDialog.getNewStyle());
+ txtStyle.setText(cssDialog.getStyle());
}
}
});
15 years, 4 months
JBoss Tools SVN: r15463 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/selection.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 06:14:35 -0400 (Sat, 23 May 2009)
New Revision: 15463
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/selection/VpeSourceSelection.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4317
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/selection/VpeSourceSelection.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/selection/VpeSourceSelection.java 2009-05-23 09:52:55 UTC (rev 15462)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/selection/VpeSourceSelection.java 2009-05-23 10:14:35 UTC (rev 15463)
@@ -72,12 +72,16 @@
}
private boolean inParents(Node node1, Node node2) {
- Node p = node2.getParentNode();
- while (p != null) {
- if (p == node1) return true;
- p = p.getParentNode();
+ if (node2 != null) {
+ Node p = node2.getParentNode();
+ while (p != null) {
+ if (p == node1)
+ return true;
+ p = p.getParentNode();
+ }
}
return false;
+
}
public Node getCommonAncestor() {
15 years, 4 months
JBoss Tools SVN: r15462 - in trunk/jst/plugins: org.jboss.tools.jst.jsp/META-INF and 9 other directories.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 05:52:55 -0400 (Sat, 23 May 2009)
New Revision: 15462
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/resources/cssdialog/color_properties.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSSelectorValidator.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSStyleValueValidator.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ICSSDialogModel.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/StyleAttributes.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSParser.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/ICSSTabControl.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSTreeItemWidgetValueProperty.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidget.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidgetValueProperty.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/ImageCombo.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeCombo.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeText.java
Removed:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ImageCombo.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/events/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSElementsParser.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ColorParser.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ComboParser.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/IListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/Parser.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ParserListener.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
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/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/OpenCSSDialogActionDelegate.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/CSSValidator.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/parsers/BaseListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/BaseTabControl.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/TabPreviewControl.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:
https://jira.jboss.org/jira/browse/JBIDE-4129
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-05-23 09:52:55 UTC (rev 15462)
@@ -58,9 +58,11 @@
org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.ui.views,
+ org.eclipse.core.databinding,
+ org.eclipse.jface.databinding,
+ org.eclipse.core.databinding.property,
org.jboss.tools.jst.web.kb;bundle-version="1.0.0"
Bundle-Version: 2.0.0
Export-Package: org.jboss.tools.jst.jsp.outline.cssdialog.common,
- org.jboss.tools.jst.jsp.outline.cssdialog.events,
org.jboss.tools.jst.jsp.outline.cssdialog.parsers
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-05-23 09:52:55 UTC (rev 15462)
@@ -201,6 +201,9 @@
style="push"
toolbarPath="Normal/additions"
tooltip="Open CSS Dialog based on the active CSS file">
+ <!--<selection
+ class="org.eclipse.core.resources.IFile">
+ </selection>-->
</action>
</editorContribution>
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/resources/cssdialog/color_properties.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/resources/cssdialog/color_properties.xml (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/resources/cssdialog/color_properties.xml 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+ <comment>Example</comment>
+ <entry key="#F0F8FF">AliceBlue</entry>
+ <entry key="#FAEBD7">AntiqueWhite</entry>
+ <entry key="#00FFFF">Aqua" </entry>
+ <entry key="#7FFFD4">Aquamarine" </entry>
+ <entry key="#F0FFFF">Azure" </entry>
+ <entry key="#F5F5DC">Beige</entry>
+ <entry key="#FFE4C4">Bisque</entry>
+ <entry key="#000000">Black</entry>
+ <entry key="#FFEBCD">BlanchedAlmond</entry>
+ <entry key="#0000FF">Blue</entry>
+ <entry key="#8A2BE2">BlueViolet</entry>
+ <entry key="#A52A2A">Brown</entry>
+ <entry key="#DEB887">BurlyWood</entry>
+ <entry key="#5F9EA0">CadetBlue</entry>
+ <entry key="#7FFF00">Chartreuse</entry>
+ <entry key="#D2691E">Chocolate</entry>
+ <entry key="#FF7F50">Coral</entry>
+ <entry key="#6495ED">CornflowerBlue</entry>
+ <entry key="#FFF8DC">Cornsilk</entry>
+ <entry key="#DC143C">Crimson</entry>
+ <entry key="#00FFFF">Cyan</entry>
+ <entry key="#00008B">DarkBlue</entry>
+ <entry key="#008B8B">DarkCyan</entry>
+ <entry key="#B8860B">DarkGoldenRod</entry>
+ <entry key="#A9A9A9">DarkGray</entry>
+ <entry key="#006400">DarkGreen</entry>
+ <entry key="#BDB76B">DarkKhaki</entry>
+ <entry key="#8B008B">DarkMagenta</entry>
+ <entry key="#556B2F">DarkOliveGreen</entry>
+ <entry key="#FF8C00">Darkorange</entry>
+ <entry key="#9932CC">DarkOrchid</entry>
+ <entry key="#8B0000">DarkRed</entry>
+ <entry key="#E9967A">DarkSalmon</entry>
+ <entry key="#8FBC8F">DarkSeaGreen</entry>
+ <entry key="#483D8B">DarkSlateBlue</entry>
+ <entry key="#2F4F4F">DarkSlateGray</entry>
+ <entry key="#00CED1">DarkTurquoise</entry>
+ <entry key="#9400D3">DarkViolet</entry>
+ <entry key="#FF1493">DeepPink</entry>
+ <entry key="#00BFFF">DeepSkyBlue</entry>
+ <entry key="#696969">DimGray</entry>
+ <entry key="#696969">DimGrey</entry>
+ <entry key="#1E90FF">DodgerBlue</entry>
+ <entry key="#B22222">FireBrick</entry>
+ <entry key="#FFFAF0">FloralWhite</entry>
+ <entry key="#228B22">ForestGreen</entry>
+ <entry key="#FF00FF">Fuchsia</entry>
+ <entry key="#DCDCDC">Gainsboro</entry>
+ <entry key="#F8F8FF">GhostWhite</entry>
+ <entry key="#FFD700">Gold</entry>
+ <entry key="#DAA520">GoldenRod</entry>
+ <entry key="#808080">Gray</entry>
+ <entry key="#808080">Grey</entry>
+ <entry key="#008000">Green</entry>
+ <entry key="#ADFF2F">GreenYellow</entry>
+ <entry key="#F0FFF0">HoneyDew</entry>
+ <entry key="#FF69B4">HotPink</entry>
+ <entry key="#CD5C5C">IndianRed</entry>
+ <entry key="#4B0082">Indigo</entry>
+ <entry key="#FFFFF0">Ivory</entry>
+ <entry key="#F0E68C">Khaki</entry>
+ <entry key="#E6E6FA">Lavender</entry>
+ <entry key="#FFF0F5">LavenderBlush</entry>
+ <entry key="#7CFC00">LawnGreen</entry>
+ <entry key="#FFFACD">LemonChiffon</entry>
+ <entry key="#ADD8E6">LightBlue</entry>
+ <entry key="#F08080">LightCoral</entry>
+ <entry key="#E0FFFF">LightCyan</entry>
+ <entry key="#FAFAD2">LightGoldenRodYellow</entry>
+ <entry key="#D3D3D3">LightGray</entry>
+ <entry key="#D3D3D3">LightGrey</entry>
+ <entry key="#90EE90">LightGreen</entry>
+ <entry key="#FFB6C1">LightPink</entry>
+ <entry key="#FFA07A">LightSalmon</entry>
+ <entry key="#20B2AA">LightSeaGreen</entry>
+ <entry key="#87CEFA">LightSkyBlue</entry>
+ <entry key="#778899">LightSlateGray</entry>
+ <entry key="#778899">LightSlateGrey</entry>
+ <entry key="#B0C4DE">LightSteelBlue</entry>
+ <entry key="#FFFFE0">LightYellow</entry>
+ <entry key="#00FF00">Lime</entry>
+ <entry key="#32CD32">LimeGreen</entry>
+ <entry key="#FAF0E6">Linen</entry>
+ <entry key="#FF00FF">Magenta</entry>
+ <entry key="#800000">Maroon</entry>
+ <entry key="#66CDAA">MediumAquaMarine</entry>
+ <entry key="#0000CD">MediumBlue</entry>
+ <entry key="#BA55D3">MediumOrchid</entry>
+ <entry key="#9370D8">MediumPurple</entry>
+ <entry key="#3CB371">MediumSeaGreen</entry>
+ <entry key="#7B68EE">MediumSlateBlue</entry>
+ <entry key="#00FA9A">MediumSpringGreen</entry>
+ <entry key="#48D1CC">MediumTurquoise</entry>
+ <entry key="#C71585">MediumVioletRed</entry>
+ <entry key="#191970">MidnightBlue</entry>
+ <entry key="#F5FFFA">MintCream</entry>
+ <entry key="#FFE4E1">MistyRose</entry>
+ <entry key="#FFE4B5">Moccasin</entry>
+ <entry key="#FFDEAD">NavajoWhite</entry>
+ <entry key="#000080">Navy</entry>
+ <entry key="#FDF5E6">OldLace</entry>
+ <entry key="#808000">Olive</entry>
+ <entry key="#6B8E23">OliveDrab</entry>
+ <entry key="#FFA500">Orange</entry>
+ <entry key="#FF4500">OrangeRed</entry>
+ <entry key="#DA70D6">Orchid</entry>
+ <entry key="#EEE8AA">PaleGoldenRod</entry>
+ <entry key="#98FB98">PaleGreen</entry>
+ <entry key="#AFEEEE">PaleTurquoise</entry>
+ <entry key="#D87093">PaleVioletRed</entry>
+ <entry key="#FFEFD5">PapayaWhip</entry>
+ <entry key="#FFDAB9">PeachPuff</entry>
+ <entry key="#CD853F">Peru</entry>
+ <entry key="#FFC0CB">Pink</entry>
+ <entry key="#DDA0DD">Plum</entry>
+ <entry key="#B0E0E6">PowderBlue</entry>
+ <entry key="#800080">Purple</entry>
+ <entry key="#FF0000">Red</entry>
+ <entry key="#BC8F8F">RosyBrown</entry>
+ <entry key="#4169E1">RoyalBlue</entry>
+ <entry key="#8B4513">SaddleBrown</entry>
+ <entry key="#FA8072">Salmon</entry>
+ <entry key="#F4A460">SandyBrown</entry>
+ <entry key="#2E8B57">SeaGreen</entry>
+ <entry key="#FFF5EE">SeaShell</entry>
+ <entry key="#A0522D">Sienna</entry>
+ <entry key="#C0C0C0">Silver</entry>
+ <entry key="#87CEEB">SkyBlue</entry>
+ <entry key="#6A5ACD">SlateBlue</entry>
+ <entry key="#708090">SlateGray</entry>
+ <entry key="#FFFAFA">Snow</entry>
+ <entry key="#00FF7F">SpringGreen</entry>
+ <entry key="#4682B4">SteelBlue</entry>
+ <entry key="#D2B48C">Tan</entry>
+ <entry key="#008080">Teal</entry>
+ <entry key="#D8BFD8">Thistle</entry>
+ <entry key="#FF6347">Tomato</entry>
+ <entry key="#40E0D0">Turquoise</entry>
+ <entry key="#EE82EE">Violet</entry>
+ <entry key="#F5DEB3">Wheat</entry>
+ <entry key="#FFFFFF">White</entry>
+ <entry key="#F5F5F5">WhiteSmoke</entry>
+ <entry key="#FFFF00">Yellow</entry>
+ <entry key="#9ACD32">YellowGreen</entry>
+</properties>
\ No newline at end of file
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/resources/cssdialog/color_properties.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -98,4 +98,6 @@
public static String ENTER_CSS_CLASS_NAME;
public static String CSS_CLASS_NAME_NOT_VALID;
public static String CSS_INVALID_STYLE_PROPERTY;
+ public static String PROPERTY_NAME_COLUMN;
+ public static String PROPERTY_VALUE_COLUMN;
}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2009-05-23 09:52:55 UTC (rev 15462)
@@ -72,4 +72,7 @@
PADDING=Padding:
DEFAULT_PREVIEW_TEXT=CSS file to edit will be displayed here
-DEFAULT_TEXT_FOR_BROWSER_PREVIEW=Double click to edit preview. To save changes press Enter button.
\ No newline at end of file
+DEFAULT_TEXT_FOR_BROWSER_PREVIEW=Double click to edit preview. To save changes press Enter button.
+
+PROPERTY_NAME_COLUMN=Attribute
+PROPERTY_VALUE_COLUMN=Value
\ No newline at end of file
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -157,7 +157,7 @@
if (dialog.open() == Window.OK) {
externalEditing = false;
- return dialog.getNewStyle();
+ return dialog.getStyle();
}
} else {
JSPTreeDialog dialog = new JSPTreeDialog();
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,279 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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;
+
+import java.util.Map;
+
+import org.eclipse.core.databinding.AggregateValidationStatus;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.IValueChangeListener;
+import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.common.model.ui.widgets.Split;
+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.common.StyleAttributes;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public abstract class AbstractCSSDialog extends TitleAreaDialog {
+
+ private Browser browser;
+
+ private Text previewText;
+
+ private String previewContent;
+
+ private StyleAttributes styleAttributes;
+
+ private StyleComposite styleComposite;
+
+ private DataBindingContext bindingContext = new DataBindingContext();
+
+ private IStatus status = Status.OK_STATUS;
+
+ final public static int DEFAULT_DIALOG_WIDTH = 500;
+ final public static int DEFAULT_DIALOG_HEIGHT = 500;
+ final public static int DEFAULT_BROWTHER_WEIGHT = 15;
+ final public static int DEFAULT_CONTROLS_WEIGHT = 85;
+
+ /**
+ *
+ */
+ public AbstractCSSDialog(Shell shell) {
+ super(shell);
+
+ previewContent = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
+ styleAttributes = new StyleAttributes();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ Composite parentComposite = (Composite) super.createDialogArea(parent);
+ GridData gridData = (GridData) parentComposite.getLayoutData();
+ gridData.heightHint = DEFAULT_DIALOG_HEIGHT;
+ gridData.widthHint = DEFAULT_DIALOG_WIDTH;
+
+ setTitle(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
+
+ createControlPane(parentComposite);
+
+ return parentComposite;
+ }
+
+ public Composite createControlPane(Composite parent) {
+
+ // Create split component that separates dialog on 2 parts
+ Split dialogContainer = new Split(parent, SWT.VERTICAL);
+
+ createBrowserComposite(dialogContainer);
+ createControlComposite(dialogContainer);
+
+ dialogContainer.setWeights(new int[] { DEFAULT_BROWTHER_WEIGHT,
+ DEFAULT_CONTROLS_WEIGHT });
+ dialogContainer.setLayoutData(new GridData(GridData.FILL,
+ GridData.BEGINNING, true, true));
+
+ ((IObservable) getStyleAttributes().getAttributeMap())
+ .addChangeListener(new IChangeListener() {
+
+ public void handleChange(ChangeEvent event) {
+ handleStyleChanged();
+
+ }
+
+ });
+
+ AggregateValidationStatus aggregateStatus = new AggregateValidationStatus(
+ getBindingContext().getValidationStatusProviders(),
+ AggregateValidationStatus.MAX_SEVERITY);
+ aggregateStatus.addValueChangeListener(new IValueChangeListener() {
+ public void handleValueChange(ValueChangeEvent event) {
+
+ handleStatusChanged((IStatus) event.diff.getNewValue());
+ }
+ });
+
+ return dialogContainer;
+ }
+
+ protected Composite createControlComposite(Composite parent) {
+
+ // Create down splitter container
+ Composite controlsContainer = new Composite(parent, SWT.None);
+ controlsContainer.setLayout(new GridLayout());
+ controlsContainer.setLayoutData(new GridData(GridData.FILL,
+ GridData.FILL, true, true));
+
+ createExtensionComposite(controlsContainer);
+ styleComposite = createStyleComposite(controlsContainer);
+
+ return controlsContainer;
+
+ }
+
+ protected void createExtensionComposite(Composite parent) {
+
+ }
+
+ /**
+ *
+ * @param parent
+ */
+ protected Composite createBrowserComposite(final Composite parent) {
+
+ final SashForm previewComposite = new SashForm(parent, SWT.None);
+ previewComposite.setLayout(new GridLayout());
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true,
+ true);
+ previewComposite.setLayoutData(gridData);
+
+ browser = new Browser(previewComposite, SWT.BORDER | SWT.MOZILLA);
+ browser.setText(generateBrowserPage());
+ browser.setLayoutData(gridData);
+ browser.addMouseListener(new MouseAdapter() {
+ public void mouseDoubleClick(MouseEvent e) {
+ if (e.widget == browser) {
+ browser.setVisible(false);
+ previewText.setVisible(true);
+ previewText.setFocus();
+ }
+ previewComposite.layout();
+ }
+ });
+
+ previewText = new Text(previewComposite, SWT.NONE | SWT.H_SCROLL);
+ previewText.setLayoutData(gridData);
+ previewText.setText(getPreviewContent());
+ previewText.setEditable(true);
+ previewText.setVisible(false);
+ previewText.addFocusListener(new FocusAdapter() {
+ public void focusLost(FocusEvent e) {
+ if (e.widget == previewText) {
+ String text = previewText.getText();
+ if (text == null || text.equals(Constants.EMPTY)) {
+ setPreviewContent(JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW);
+ } else {
+ setPreviewContent(text);
+ }
+ previewText.setVisible(false);
+ browser.setVisible(true);
+ previewComposite.layout();
+ }
+ }
+ });
+
+ previewComposite.layout();
+ return previewComposite;
+ }
+
+ protected StyleComposite createStyleComposite(Composite parent) {
+ return new StyleComposite(parent, getStyleAttributes(),
+ getBindingContext());
+ }
+
+ protected void handleStyleChanged() {
+ browser.setText(generateBrowserPage());
+ }
+
+ protected void handleStatusChanged(IStatus newStatus) {
+ if (newStatus.isOK() && !status.isOK())
+ setErrorMessage(null);
+ else if (newStatus.getSeverity() == IStatus.ERROR)
+ setErrorMessage(newStatus.getMessage());
+
+ if (newStatus.getSeverity() != status.getSeverity()) {
+ getButton(OK).setEnabled(newStatus.isOK());
+ }
+
+ status = newStatus;
+ }
+
+ public IStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * /** Method is used to build html body that is appropriate to browse.
+ *
+ * @return String html text representation
+ */
+ public String generateBrowserPage() {
+ StringBuffer html = new StringBuffer(Constants.OPEN_DIV_TAG);
+
+ for (Map.Entry<String, String> styleItem : getStyleAttributes()
+ .getAttributeMap().entrySet()) {
+
+ html.append(styleItem.getKey() + Constants.COLON
+ + styleItem.getValue() + Constants.SEMICOLON);
+ }
+
+ html.append("\">" + getPreviewContent() + Constants.CLOSE_DIV_TAG); //$NON-NLS-1$
+
+ return html.toString();
+ }
+
+ @Override
+ public boolean close() {
+ return super.close();
+ }
+
+ public Browser getBrowser() {
+ return browser;
+ }
+
+ public StyleAttributes getStyleAttributes() {
+ return styleAttributes;
+ }
+
+ public String getPreviewContent() {
+ return previewContent;
+ }
+
+ public void setPreviewContent(String previewContent) {
+ this.previewContent = previewContent;
+ }
+
+ public DataBindingContext getBindingContext() {
+ return bindingContext;
+ }
+
+ public StyleComposite getStyleComposite() {
+ return styleComposite;
+ }
+
+ public void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,35 +10,18 @@
******************************************************************************/
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.IResource;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
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.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -48,707 +31,265 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.common.model.ui.widgets.Split;
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.CSSValidator;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSSelectorValidator;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.ICSSDialogModel;
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;
+import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.TabPreviewControl;
/**
* This dialog represents CSSClass dialog.
- *
+ *
* @author Igor Zhukov (izhukov(a)exadel.com)
*/
-public class CSSClassDialog extends TitleAreaDialog implements ChangeStyleListener {
+public class CSSClassDialog extends AbstractCSSDialog {
- public static final String ID = "org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog"; //$NON-NLS-1$
+ // model is the core of the CSS Class Dialog, it manages style attributes
+ private ICSSDialogModel cssModel;
- private static String notUsed = "not_used"; //$NON-NLS-1$
-// private final static String[] fileExtensions = { Util.CSS_FILE_EXTENTION };
-
- private Composite browserContainer = null;
- private Browser browser = null;
- private Text textBrowser = null;
- private String previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
-
- private StyleComposite styleComposite = null;
- private StyleAttributes styleAttributes = null;
- // css file path
- private Text text;
- // css style classes
- private Combo classCombo;
- // combo box content assist
-// private ContentAssistCommandAdapter contentAssistAdapter = null;
- // apply button
- private Button applyButton;
-
- // model is the core of the CSS Class Dialog, it manages style attributes
- private CSSModel cssModel;
-
- // 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;
+ private IFile file;
-// private boolean keyInputSelector = false;
+ private Text fileText;
- // 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;
- // 3. holds an error if inccorrect property was specified
- private IStatus cssValueStatus =null;
+ // css style classes
+ private Combo classCombo;
- // an array of subscribed message dialog listener
- private ArrayList<MessageDialogListener> errorListeners = new ArrayList<MessageDialogListener>();
+ private String selectorLabel;
- // parameter indicates if dialog was opened from Wizard
- private final boolean callFromWizard;
-
- private Button addNewClass;
+ private Button addNewClassButton;
+ // apply button
+ private Button applyButton;
- /**
- * 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, IStructuredSelection selection, boolean callFromWizard) {
- super(parentShell);
-
- setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
+ // preview tab
+ private TabPreviewControl preview;
- filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
- classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
+ /**
+ *
+ * @param parentShell
+ * @param file
+ * @param selection
+ */
+ public CSSClassDialog(Shell parentShell, IFile file,
+ IStructuredSelection selection) {
+ super(parentShell);
- styleAttributes = new StyleAttributes();
- styleAttributes.addChangeStyleListener(this);
- this.callFromWizard = callFromWizard;
- this.selection = selection;
- init();
- }
+ setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX
+ | SWT.APPLICATION_MODAL);
- /**
- * 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(Util.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();
- }
- }
+ this.file = file;
+ this.cssModel = new CSSModel(file);
+ this.selection = selection;
+ }
- /**
- * Sets current style class value.
- *
- * @param currentClassStyle String value
- */
- public void setCurrentStyleClass(String currentClassStyle) {
- this.currentClassStyle = Util.formatStyleClassToCSSView(currentClassStyle);
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
- */
- @Override
- protected Control createDialogArea(final Composite parent) {
- final Composite composite = (Composite) super.createDialogArea(parent);
- if(composite.getLayoutData()!=null && composite.getLayoutData() instanceof GridData) {
- ((GridData)composite.getLayoutData()).widthHint=500;
- ((GridData)composite.getLayoutData()).heightHint=500;
- }
- final Control control = createDialogComposite(composite);
- return control;
- }
-
- public Control createDialog(final Composite parent) {
- return createDialogArea(parent);
+ @Override
+ protected Control createContents(Composite parent) {
+ Control contents = super.createContents(parent);
+ updateControlPane();
+ return contents;
}
- /**
- * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(Composite)
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- updateOKButtonState();
+ @Override
+ protected StyleComposite createStyleComposite(Composite parent) {
+ StyleComposite styleComposite = super.createStyleComposite(parent);
- }
- private Split split;
- /**
- * Create the dialog itself.
- *
- * @param composite parent window
- * @return eclipse Control object
- */
- private Control createDialogComposite(Composite composite) {
- if (!this.callFromWizard) {
- setTitle(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
- setMessage(JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION);
- }
- composite.setLayout(new GridLayout());
-
- // ===============================================================================
- // Create split component that separates dialog on 2 parts
- // ===============================================================================
- split = new Split(composite, SWT.VERTICAL);
+ // add preview tab to styleComposite
+ preview = new TabPreviewControl(styleComposite.getTabFolder(),
+ getStyleAttributes(), cssModel);
+ styleComposite.createTabItem(preview, preview,
+ JstUIMessages.PREVIEW_SHEET_TAB_NAME,
+ JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- // ===============================================================================
- // Create browser container
- // ===============================================================================
- browserContainer = getCompositeElement(split);
- // create browser component
- createBrowserComponent();
+ return styleComposite;
+ }
- // ===============================================================================
- // Create down splitter container
- // ===============================================================================
- Composite downSplitPane = getCompositeElement(split);
+ @Override
+ protected void createExtensionComposite(final Composite parent) {
+ Composite fileControlPanel = new Composite(parent, SWT.BORDER);
+ fileControlPanel.setLayoutData(new GridData(GridData.FILL,
+ GridData.BEGINNING, true, false));
+ fileControlPanel.setLayout(new GridLayout(3, false));
- Composite classComposite = new Composite(downSplitPane, SWT.BORDER);
- classComposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
- classComposite.setLayout(new GridLayout(3, false));
+ // add file path control
+ addLabel(fileControlPanel, JstUIMessages.CSS_CLASS_DIALOG_FILE_LABEL);
- // ===============================================================================
- // Create component that contains CSS file pass and it's selectors (style classes combo box)
- // ===============================================================================
- createCSSFilePathComponent(classComposite);
- createStyleClassCombo(classComposite);
+ GridData fileLayoutData = new GridData(GridData.FILL, GridData.CENTER,
+ true, false);
+ fileLayoutData.horizontalSpan = 2;
- // ===============================================================================
- // 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)) {
- updateApplyButton(true);
- }
- }
- });
+ fileText = new Text(fileControlPanel, SWT.BORDER | SWT.READ_ONLY);
+ fileText.setLayoutData(fileLayoutData);
- // ===============================================================================
- // Create custom button panel
- // ===============================================================================
- createCustomButtonPanel(downSplitPane);
+ // add class control
+ addLabel(fileControlPanel,
+ JstUIMessages.CSS_CLASS_DIALOG_STYLE_CLASS_LABEL);
- styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
- public void styleChanged(ChangeStyleEvent event) {
- if (!browser.isDisposed()) {
- browser.setText(getTextForBrowser());
- }
- }
- });
+ classCombo = new Combo(fileControlPanel, SWT.BORDER | SWT.READ_ONLY);
+ classCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false));
- if (currentFile != null) {
- initCSSModel(currentFile, true);
- } else if (currentClassStyle != null) {
- classCombo.setText(currentClassStyle);
- styleAttributes.setCssSelector(currentClassStyle);
- }
+ // this listener is responsible for processing dialog header message
+ // events
+ classCombo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ handleSelectorSwitched();
+ }
+ });
+ // creates a button for add new class
+ addNewClassButton = new Button(fileControlPanel, SWT.PUSH);
+ addNewClassButton.setText(JstUIMessages.BUTTON_ADD_NEW_STYLE_CLASS);
+ addNewClassButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ InputDialog dlg = new InputDialog(parent.getShell(),
+ JstUIMessages.ENTER_CSS_CLASS_NAME,
+ JstUIMessages.ENTER_CSS_CLASS_NAME, classCombo
+ .getText(), CSSSelectorValidator.getInstance());
+ if (dlg.open() == Window.OK) {
+ addNewClass(dlg.getValue().trim());
+ }
+ }
+ });
- // add content assist to style COMBO component
- SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(classCombo.getItems());
- proposalProvider.setFiltering(true);
+ }
- split.setWeights(new int[]{15, 85});
- split.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
+ @Override
+ protected Composite createControlComposite(Composite parent) {
+ Composite controlComposite = super.createControlComposite(parent);
+ createCustomButtonPanel(controlComposite);
- return composite;
- }
+ return controlComposite;
+ }
- private void createCSSFilePathComponent(Composite parent) {
- Label label = new Label(parent, SWT.LEFT);
- 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(parent, SWT.BORDER|SWT.READ_ONLY);
- GridData gridData =new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.grabExcessHorizontalSpace=true;
- gridData.horizontalSpan=2;
- text.setLayoutData(gridData);
-// text.setEditable(false);
- text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- String cssFile = text.getText().trim();
- // Initialize a variable with the no error status
- filePathStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_FILE_PATH_MESSAGE, null);
- if (cssFile != null && !cssFile.equals(Constants.EMPTY)) {
- filePathStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
- }
- // show corresponding message
- IStatus status = findMostSevere();
- notifyListeners(text, status);
- applyToStatusLine(status);
- }
- });
- }
-
/**
- * This method is used to create and initialize style class comboBox component.
- *
- * @param parent Composite component
+ *
+ * @param parent
+ * @param label
*/
- private void createStyleClassCombo(final Composite parent) {
- Label label = new Label(parent, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.CSS_CLASS_DIALOG_STYLE_CLASS_LABEL);
-
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 1;
-
- classCombo = new Combo(parent, SWT.BORDER|SWT.READ_ONLY);
- classCombo.setLayoutData(gridData);
- // this listener is responsible for processing dialog header message events
- classCombo.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- String cssClass = classCombo.getText().trim();
- // Initialize a variable with the no error status
- classNameStatus = new Status(IStatus.ERROR, notUsed, 0, JstUIMessages.CSS_EMPTY_STYLE_CLASS_MESSAGE, null);
- if (cssClass != null && !cssClass.equals(Constants.EMPTY)) {
- classNameStatus = new Status(IStatus.OK, notUsed, 0, JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
- }
- // show corresponding message
- IStatus status = findMostSevere();
- notifyListeners(classCombo, status);
- applyToStatusLine(status);
- // update CSS style cmposite if needed
- if ((currentClassStyle != null && currentClassStyle.equals(classCombo.getText().trim()))
- || (currentClassStyle == null && classCombo.getText().trim().equals(Constants.EMPTY))) {
- return;
- }
- cssStyleClassChanged();
- updateApplyButton(false);
- }
- });
- //creates a button for add new class
- addNewClass = new Button(parent, SWT.PUSH);
- addNewClass.setText(JstUIMessages.BUTTON_ADD_NEW_STYLE_CLASS);
- addNewClass.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- InputDialog dlg = new InputDialog(parent.getShell(),
- JstUIMessages.ENTER_CSS_CLASS_NAME, JstUIMessages.ENTER_CSS_CLASS_NAME, classCombo.getText(),
- new IInputValidator(){
- private CSSValidator cssValidator = CSSValidator.getInstance();
- /**
- * Simple validation of new CSS Class Name, now we just check that it's not empty string
- */
- public String isValid(String newText) {
- if (cssValidator.isValidSelector(newText)) {
- return null;
- } else {
- return JstUIMessages.CSS_CLASS_NAME_NOT_VALID;
- }
- }
-
- });
- if (dlg.open() == Window.OK) {
- if (classNameStatus.matches(IStatus.ERROR))
- classNameStatus = new Status(IStatus.OK, notUsed, 0,
- JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null);
- addNewStyleClass(dlg.getValue().trim());
- }
- }
- });
+ protected Label addLabel(Composite parent, String label) {
+ Label labelControl = new Label(parent, SWT.LEFT);
+ labelControl.setLayoutData(new GridData(GridData.END, GridData.CENTER,
+ false, false));
+ labelControl.setText(label);
+ return labelControl;
}
- /**
- * Add New Class to CSS Class Dialog
- * @param styleClassName - name of new style class
- */
- public void addNewStyleClass(String styleClassName) {
- updateApplyButton(true);
- styleChanged = true;
- currentClassStyle = styleClassName;
- updateStyleComposite();
- styleAttributes.setCssSelector(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- updateOKButtonState();
- // add new class to end of list
- if (classCombo.indexOf(currentClassStyle) == -1)
- classCombo.add(currentClassStyle);
- // end select it
- classCombo.select(classCombo.getItemCount() - 1);
- cssModel.setCSS(currentClassStyle, styleAttributes);
- }
-// /**
-// * This method is invoked to correctly process class style combo modify event.
-// */
-// private void notifyStyleClassChanged() {
-// Display display = null;
-// if (PlatformUI.isWorkbenchRunning()) {
-// display = PlatformUI.getWorkbench().getDisplay();
-// }
-// if (display != null && (Thread.currentThread() == display.getThread())) {
-// if (uiJob == null) {
-// uiJob = new UIJob(jobName) {
-// @Override
-// public IStatus runInUIThread(IProgressMonitor monitor) {
-// if (monitor.isCanceled()) {
-// return Status.CANCEL_STATUS;
-// }
-// monitor.beginTask(jobName, IProgressMonitor.UNKNOWN);
-//
-// // start operation
-// cssStyleClassChanged();
-// // end operation
-//
-// monitor.done();
-//
-// return Status.OK_STATUS;
-// }
-// };
-// }
-//
-// uiJob.setPriority(Job.SHORT);
-// uiJob.schedule(delay);
-//
-// return;
-// }
-// }
/**
* This method is used to create custom button panel.
- *
- * @param parent Composite component
+ *
+ * @param parent
+ * Composite component
*/
private void createCustomButtonPanel(Composite parent) {
- Composite buttonComposite = new Composite(parent, SWT.NONE);
- buttonComposite.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, true, false));
- buttonComposite.setLayout(new GridLayout());
- // add APPLY button
- applyButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_APPLY);
- updateApplyButton(false);
- applyButton.setToolTipText(JstUIMessages.CSS_APPLY_CHANGES);
- applyButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- if (currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
- // update ComboBox element list
- if (classCombo.indexOf(currentClassStyle) == -1) {
- classCombo.add(currentClassStyle);
- }
- saveChanges(false);
- updateApplyButton(false);
- styleChanged = false;
- }
- }
- });
- // add CLEAR button
- Button clearButton = createCustomButton(buttonComposite, JstUIMessages.BUTTON_CLEAR);
- clearButton.setToolTipText(JstUIMessages.CSS_CLEAR_STYLE_SHEET);
- clearButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- styleComposite.clearStyleComposite(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- styleComposite.updateStyle();
- updateApplyButton(true);
- styleChanged = true;
- }
- });
+ Composite buttonComposite = new Composite(parent, SWT.NONE);
+ buttonComposite.setLayoutData(new GridData(GridData.END,
+ GridData.BEGINNING, true, false));
+ buttonComposite.setLayout(new GridLayout());
+ // add APPLY button
+ applyButton = createCustomButton(buttonComposite,
+ JstUIMessages.BUTTON_APPLY, JstUIMessages.CSS_APPLY_CHANGES,
+ false);
+ applyButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ save();
+ applyButton.setEnabled(false);
+ }
+ });
+ // add CLEAR button
+ Button clearButton = createCustomButton(buttonComposite,
+ JstUIMessages.BUTTON_CLEAR,
+ JstUIMessages.CSS_CLEAR_STYLE_SHEET, true);
+ clearButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ getStyleComposite().clearStyleComposite();
+ }
+ });
}
/**
* This method is used to create custom button.
- *
- * @param parent Composite component
- * @param label Button label value
+ *
+ * @param parent
+ * Composite component
+ * @param label
+ * Button label value
*/
- protected Button createCustomButton(Composite parent, String label) {
+ protected Button createCustomButton(Composite parent, String label,
+ String tooltip, boolean defaultState) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
-// setButtonLayoutData(button);
+ button.setToolTipText(tooltip);
+ button.setEnabled(defaultState);
return button;
}
/**
* Method is used to correctly process style class change operation.
*/
- private void cssStyleClassChanged() {
- if (currentFile != null && !currentFile.equals(Constants.EMPTY)) {
-// if (styleChanged && currentClassStyle != null && !currentClassStyle.equals(Constants.EMPTY)) {
-// MessageBox messageBox = new MessageBox(getParentShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
-// messageBox.setText(JstUIMessages.CSS_SAVE_DIALOG_TITLE);
-// messageBox.setMessage(CSSClassDialog.getMessageForSaveDialog(currentFile));
-// int result = messageBox.open();
-// if (result == SWT.YES) {
-// // update ComboBox element list
-// if (classCombo.indexOf(currentClassStyle) == -1) {
-// classCombo.add(currentClassStyle);
-// }
- cssModel.setCSS(currentClassStyle, styleAttributes);
-// // update content assist proposals
-// SimpleContentProposalProvider proposalProvider =
-// (SimpleContentProposalProvider)contentAssistAdapter.getContentProposalProvider();
-// proposalProvider.setProposals(classCombo.getItems());
-// } else {
-// // FOR https://jira.jboss.org/jira/browse/JBIDE-3542
-// // cssModel.init(currentFile);
-// // styleComposite.revertPreview();
-// }
-// }
- // update current class style value
- currentClassStyle = classCombo.getText().trim();
-
- // if new css was added
-// if (classCombo.indexOf(currentClassStyle) == -1) {
-// classCombo.add(currentClassStyle);
-// styleChanged = true;
-// } else {
-// styleChanged = false;
-// }
- updateApplyButton(true);
- styleChanged = true;
-
- updateStyleComposite();
- styleAttributes.setCssSelector(currentClassStyle);
- styleComposite.updatePreview(currentClassStyle);
- updateOKButtonState();
- } else {
- currentClassStyle = classCombo.getText().trim();
- styleAttributes.setCssSelector(currentClassStyle);
- styleChanged = false;
- }
-
+ protected void handleSelectorSwitched() {
+ if (selectorLabel != null)
+ cssModel.updateCSSStyle(selectorLabel, getStyleAttributes());
+ selectorLabel = classCombo.getText();
+ preview.setSelector(selectorLabel);
+ classCombo.setToolTipText(cssModel.getCSSRuleText(selectorLabel));
+ getStyleComposite().setStyleProperties(
+ cssModel.getClassProperties(selectorLabel));
+ getStyleComposite().selectTab(StyleComposite.DEFAULT_START_TAB);
}
- /**
- * Initialize CSS model with active opened CSS file.
- *
- * @param file IFile object
- * @param useRelativePathPath
- */
- private void initCSSModel(IFile file, boolean updateCSSModel) {
- if (file != null) {
- // create CSS Model
- cssModel = new CSSModel(file);
- currentClassStyle = null;
- classCombo.removeAll();
- classCombo.setEnabled(true);
- // set file path to corresponding text field
- text.setText(file.getFullPath().toOSString());
-
- Point selectionInFile = Util.getSelectionInFile(file);
+ /**
+ * Add New Class to CSS Class Dialog
+ *
+ * @param styleClassName
+ * - name of new style class
+ */
+ public void addNewClass(String styleClassName) {
+ cssModel.updateCSSStyle(selectorLabel, getStyleAttributes());
+ selectorLabel = cssModel.addCSSRule(styleClassName);
+ preview.setSelector(selectorLabel);
+ classCombo.add(selectorLabel);
+ classCombo.select(classCombo.getItemCount() - 1);
+ }
- currentClassStyle = cssModel.getSelectorByPosition(selectionInFile);
-
- // fill in ComboBox component with CSS model selectors
-// List<Selector> selectors = cssModel.getSelectors();
- List<String> selectors = cssModel.getSelectorLabels();
- for (int i = 0; i < selectors.size(); i++) {
-// Selector value = selectors.get(i);
- String label = selectors.get(i);
- classCombo.add(/*value.getValue()*/ label);
-
- }
- /*
- *
- */
- if (currentClassStyle != null) {
- classCombo.setText(currentClassStyle);
- } else {
- classCombo.select(0);
- }
- classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
+ public void releaseResources() {
- styleComposite.setShowPreviewTab(true);
- styleComposite.setCSSModel(cssModel);
- // update style composite component with the values from new CSS file
- if (updateCSSModel) {
- updateStyleComposite();
- }
- styleComposite.initPreview(cssModel);
- }
- }
-
- /**
- * 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 (findMostSevere()!=null&&findMostSevere().getSeverity()==IStatus.ERROR) {
- okButton.setEnabled(false);
- } else {
- okButton.setEnabled(true);
- }
- }
- }
-
- /**
- * Method is used to create browser component to display preview HTML.
- */
- 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(new MouseAdapter() {
- 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 = new Text(browserContainer, SWT.NONE | SWT.H_SCROLL);
- textBrowser.setText(previewBrowserValue);
- textBrowser.addFocusListener(new FocusAdapter() {
- public void focusLost(FocusEvent e) {
- if (e.widget == textBrowser) {
- String text = textBrowser.getText();
- if (text == null || text.equals(Constants.EMPTY)) {
- previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
- } else {
- previewBrowserValue = text;
- }
- textBrowser.dispose();
- // create Browse component instead of text area
- createBrowserComponent();
- }
- browserContainer.layout();
- }
- });
- textBrowser.setLayoutData(gridData);
- textBrowser.setEditable(true);
- textBrowser.setFocus();
- }
- browserContainer.layout();
- }
- });
- browser.setLayoutData(gridData);
- }
-
- /**
- * Update style composite component in accordance with the attributes of selected CSS selector.
- */
- private void updateStyleComposite() {
- String style = cssModel.getStyle(currentClassStyle);
- styleComposite.recreateStyleComposite(style, currentClassStyle);
- }
-
- /**
- * 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;
- }
-
- public void releaseResources() {
-
- if (cssModel != null){
- cssModel.releaseModel();
+ if (cssModel != null) {
+ cssModel.release();
cssModel = null;
}
}
- /**
- * Method should be called in case of dialog closure operation.
- */
- public void saveChanges(boolean close) {
- styleComposite.updateStyle();
- cssModel.setCSS(currentClassStyle, styleAttributes);
- cssModel.saveModel();
- }
+ /**
+ * Method should be called in case of dialog closure operation.
+ */
+ public void save() {
+ cssModel.updateCSSStyle(selectorLabel, getStyleAttributes());
+ cssModel.save();
+ }
- /**
- * Gets current selected style class value.
- *
- * @return selector name
- */
- public String getSelectorName() {
- return Util.formatCSSSelectorToStyleClassView(currentClassStyle);
- }
+ /**
+ * TODO Gets current selected style class value.
+ *
+ * @return selector name
+ */
+ public String getSelectorName() {
+ return Util.formatCSSSelectorToStyleClassView(selectorLabel);
+ }
- /**
- * Method for setting title for dialog
- *
- * @param newShell Shell object
- * @see org.eclipse.jface.window.Window#configureShell(Shell)
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(JstUIMessages.CSS_STYLE_CLASS_EDITOR_TITLE);
- }
-
- /**
- * This method close the dialog.
- *
- * @return true if dialog was closed, false - otherwise
- */
- public boolean closeDialog() {
- setReturnCode(Window.CANCEL);
- return close();
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#close()
- */
- @Override
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#close()
+ */
+ @Override
public boolean close() {
int code = getReturnCode();
switch (code) {
case OK:
- if (styleChanged || classCombo.indexOf(currentClassStyle) == -1) {
- saveChanges(true);
- }
+ save();
break;
case CANCEL:
default:
@@ -758,123 +299,61 @@
return super.close();
}
- /**
- * Add MessageDialogListener object.
- *
- * @param listener MessageDialogListener object to be added
- */
- public void addMessageDialogListener(MessageDialogListener listener) {
- errorListeners.add(listener);
- }
+ public void reinit() {
+ cssModel.setFile(file);
+ cssModel.reinit();
+ preview.reinit(cssModel);
+ updateControlPane();
- /**
- * 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);
- }
- }
+ }
- /**
- * 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(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
- return cssValueStatus;
- }
- if(cssValueStatus!=null && cssValueStatus.matches(IStatus.ERROR)){
- return cssValueStatus;
- } else {
- return classNameStatus;
- }
+ public void setFile(IFile file) {
+ this.file = file;
+ }
+ @Override
+ protected void handleStyleChanged() {
+ super.handleStyleChanged();
+
+ applyButton.setEnabled(true);
+
}
- /**
- * 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;
- }
+ @Override
+ protected void handleStatusChanged(IStatus newStatus) {
+
+ if (newStatus.getSeverity() != getStatus().getSeverity()) {
+ applyButton.setEnabled(newStatus.isOK());
+ getButton(OK).setEnabled(newStatus.isOK());
+ classCombo.setEnabled(newStatus.isOK());
+ addNewClassButton.setEnabled(newStatus.isOK());
}
- }
- public void reinit(){
- releaseResources();
- initCSSModel(currentFile,true);
+ super.handleStatusChanged(newStatus);
}
- public void setCurrentFile(IFile currentFile) {
- this.currentFile = currentFile;
- }
+ protected void updateControlPane() {
- /* (non-Javadoc)
- * @see org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleListener#styleChanged(org.jboss.tools.jst.jsp.outline.cssdialog.events.ChangeStyleEvent)
- */
- public void styleChanged(ChangeStyleEvent event) {
- if (!this.styleAttributes.isValid()) {
- cssValueStatus = new Status(IStatus.ERROR, notUsed, 0,
- JstUIMessages.CSS_INVALID_STYLE_PROPERTY, null);
- notifyListeners(event, cssValueStatus);
- addNewClass.setEnabled(false);
- } else {
- cssValueStatus = null;
- addNewClass.setEnabled(true);
- notifyListeners(event, new Status(IStatus.OK, notUsed, 0,
- JstUIMessages.CSS_STYLE_CLASS_EDITOR_DESCRIPTION, null));
- }
- if (cssValueStatus != null && classCombo != null) {
- classCombo.setEnabled(false);
- } else {
- classCombo.setEnabled(true);
+ fileText.setText(file.getFullPath().toString());
+ classCombo.removeAll();
+ classCombo.setEnabled(true);
+ selectorLabel = cssModel
+ .getSelectorLabel(Util.getSelectionInFile(file).x);
- }
- updateApplyButton(true);
- updateOKButtonState();
- applyToStatusLine(findMostSevere());
- }
- /**
- * Update upplyButtonState
- * @param available
- */
- private void updateApplyButton(boolean enabled){
- if(cssValueStatus!=null
- &&cssValueStatus.matches(IStatus.ERROR)) {
- applyButton.setEnabled(false);
- }else {
- applyButton.setEnabled(enabled);
+ getStyleComposite().setStyleProperties(
+ cssModel.getClassProperties(selectorLabel));
+ preview.setSelector(selectorLabel);
+
+ List<String> selectors = cssModel.getSelectorLabels();
+ for (int i = 0; i < selectors.size(); i++) {
+ String label = selectors.get(i);
+ classCombo.add(label);
+ if (label.equals(selectorLabel))
+ classCombo.select(i);
+
}
-
+
+ applyButton.setEnabled(false);
+
}
}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSStyleDialog.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,246 +10,55 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-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.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-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.CSSConstants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
-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.StyleAttributes;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
/**
* Class for CSS editor dialog
- *
+ *
* @author Dzmitry Sakovich (dsakovich(a)exadel.com)
*/
-public class CSSStyleDialog extends Dialog implements MouseListener, FocusListener {
+public class CSSStyleDialog extends AbstractCSSDialog {
- final static int MIN_HEIGHT_FOR_BROWSER = 60;
+ public CSSStyleDialog(final Shell parentShell, String style) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX
+ | SWT.APPLICATION_MODAL);
- private String previewBrowserValue = JstUIMessages.DEFAULT_TEXT_FOR_BROWSER_PREVIEW;
+ getStyleAttributes().setStyleProperties(parseStyle(style));
- private Composite browserContainer = null;
- private Browser browser = null;
- private Text textBrowser = null;
+ }
- private StyleComposite styleComposite = null;
- private StyleAttributes styleAttributes = null;
- private String oldStyle;
+ public String getStyle() {
+ return getStyleAttributes().getStyle();
+ }
- public CSSStyleDialog(final Shell parentShell, String oldStyle) {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
- this.oldStyle = oldStyle;
- styleAttributes = new StyleAttributes();
- }
+ protected Map<String, String> parseStyle(String styleString) {
- /**
- * Getter for newStyle attribute
- *
- * @return new style string value
- */
- public String getNewStyle() {
- return (styleComposite == null) ? oldStyle : styleComposite.getNewStyle();
- }
+ Map<String, String> properties = new HashMap<String, String>();
- /**
- * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(Composite)
- */
- @Override
- protected Control createDialogArea(final Composite parent) {
- final Composite composite = (Composite) super.createDialogArea(parent);
- if(composite.getLayoutData()!=null && composite.getLayoutData() instanceof GridData) {
- ((GridData)composite.getLayoutData()).widthHint=700;
- ((GridData)composite.getLayoutData()).heightHint=500;
- }
- Split split = new Split(composite, SWT.VERTICAL);
+ if ((styleString != null) && (styleString.length() > 0)) {
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- composite.setLayout(layout);
+ String[] styles = styleString.split(Constants.SEMICOLON);
+ for (String styleElement : styles) {
+ String[] styleElementParts = styleElement.trim().split(
+ Constants.COLON);
+ if ((styleElementParts != null)
+ && (styleElementParts.length == 2)
+ && Util.searchInElement(styleElementParts[0],
+ CSSConstants.CSS_STYLES_MAP)) {
- // initialize browser container
- browserContainer = getCompositeElement(split);
- createBrowserComponent();
+ properties.put(styleElementParts[0], styleElementParts[1]);
+ }
+ }
- styleAttributes.addChangeStyleListener(new ChangeStyleListener() {
- public void styleChanged(ChangeStyleEvent event) {
- browser.setText(getTextForBrowser());
- }
- });
- styleComposite = new StyleComposite(split, styleAttributes, oldStyle);
-
- split.setWeights(new int[]{15, 85});
- split.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
-
- createClearButton(parent);
-
- return composite;
- }
-
- /**
- * 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 is used to create browser component to display preview html.
- */
- 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);
- }
-
- /**
- * create clear button
- * @param parent
- */
- private void createClearButton(Composite parent){
- //add clear button to dialog
- Composite buttonComposite = new Composite(parent, SWT.None);
- GridLayout gridLayoutTmp = new GridLayout();
- gridLayoutTmp.marginHeight = 0;
- gridLayoutTmp.marginRight = 5;
- buttonComposite.setLayout(gridLayoutTmp);
- buttonComposite.setLayoutData(new GridData(GridData.END, GridData.END,
- false, false));
-
- Button clearButton = new Button(buttonComposite, SWT.None);
- clearButton.setText(JstUIMessages.BUTTON_CLEAR);
-
- clearButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- styleComposite.clearStyleComposite(null);
- }
- });
- }
-
- /**
- * 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;
- }
-
- /**
- * Method for setting title for dialog
- *
- * @param newShell Shell object
- * @see org.eclipse.jface.window.Window#configureShell(Shell)
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(JstUIMessages.CSS_STYLE_EDITOR_TITLE);
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- */
- @Override
- protected void okPressed() {
- styleComposite.updateStyle();
- super.okPressed();
- }
-
- /**
- * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
- */
- @Override
- protected IDialogSettings getDialogBoundsSettings() {
- return JspEditorPlugin.getDefault().getDialogSettings();
- }
-
- /**
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
- 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();
+ return properties;
}
-
- /**
- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
- */
- 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)
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/OpenCSSDialogActionDelegate.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/OpenCSSDialogActionDelegate.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/OpenCSSDialogActionDelegate.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,5 +1,6 @@
package org.jboss.tools.jst.jsp.outline.cssdialog;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -13,23 +14,27 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.part.FileEditorInput;
/**
- * This is CSS dialog action delegate class that process actions that is contributed in Eclipse
- * regarding CSS Dialog.
- *
+ * This is CSS dialog action delegate class that process actions that is
+ * contributed in Eclipse regarding CSS Dialog.
+ *
* @author Igor Zhukov
*/
-public class OpenCSSDialogActionDelegate implements IWorkbenchWindowActionDelegate, IObjectActionDelegate,
- IEditorActionDelegate, IViewActionDelegate {
+public class OpenCSSDialogActionDelegate implements
+ IWorkbenchWindowActionDelegate, IObjectActionDelegate,
+ IEditorActionDelegate, IViewActionDelegate {
private Shell shell = null;
- private IStructuredSelection selection = null;
+ private IStructuredSelection selection;
+ private IFile file;
/**
* Initializes this action delegate with the view it will work in.
- *
- * @param view the view that provides the context for this delegate
+ *
+ * @param view
+ * the view that provides the context for this delegate
* @see IViewActionDelegate#init(IViewPart)
*/
public void init(IViewPart view) {
@@ -44,8 +49,9 @@
/**
* Initializes this action delegate with the view it will work in.
- *
- * @param view the view that provides the context for this delegate
+ *
+ * @param view
+ * the view that provides the context for this delegate
* @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
*/
public void init(IWorkbenchWindow window) {
@@ -58,9 +64,9 @@
* Called when the user has selected this action to be executed.
*/
public void run(IAction action) {
- if (shell != null) {
+ if ((shell != null) && (file != null)) {
String styleClass = null;
- CSSClassDialog dialog = new CSSClassDialog(shell, selection, false);
+ CSSClassDialog dialog = new CSSClassDialog(shell, file, selection);
if (dialog.open() == Window.OK) {
styleClass = dialog.getSelectorName();
}
@@ -68,22 +74,34 @@
}
/**
- * Notifies this action delegate that the selection in the workbench has changed.
- *
- * @param action the action proxy that handles presentation portion of the action
- * @param selection the current selection, or <code>null</code> if there is no selection.
+ * Notifies this action delegate that the selection in the workbench has
+ * changed.
+ *
+ * @param action
+ * the action proxy that handles presentation portion of the
+ * action
+ * @param selection
+ * the current selection, or <code>null</code> if there is no
+ * selection.
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof IStructuredSelection) {
- this.selection = (IStructuredSelection)selection;
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ if (structuredSelection.getFirstElement() instanceof IFile) {
+ this.file = (IFile) ((IStructuredSelection) selection)
+ .getFirstElement();
+
+ } else {
+ this.selection = structuredSelection;
+ }
}
}
/**
- * Sets the active part for the delegate. This method will be called
- * every time the action appears in a context menu. The targetPart
- * may change with each invocation.
+ * Sets the active part for the delegate. This method will be called every
+ * time the action appears in a context menu. The targetPart may change with
+ * each invocation.
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
if (targetPart != null && targetPart.getSite() != null) {
@@ -92,17 +110,23 @@
}
/**
- * Sets the active editor for the delegate. Implementors should
- * disconnect from the old editor, connect to the new editor, and
- * update the action to reflect the new editor.
- *
- * @param action the action proxy that handles presentation portion of the action
- * @param editor the new editor target
+ * Sets the active editor for the delegate. Implementors should disconnect
+ * from the old editor, connect to the new editor, and update the action to
+ * reflect the new editor.
+ *
+ * @param action
+ * the action proxy that handles presentation portion of the
+ * action
+ * @param editor
+ * the new editor target
* @see IEditorActionDelegate #setActiveEditor(IAction, IEditorPart)
*/
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
if (targetEditor != null && targetEditor.getSite() != null) {
shell = targetEditor.getSite().getShell();
+ if (targetEditor.getEditorInput() instanceof FileEditorInput)
+ file = ((FileEditorInput) targetEditor.getEditorInput())
+ .getFile();
}
}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/StyleComposite.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,506 +10,194 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
-import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSModel;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.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;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ComboParser;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.Parser;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ParserListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
+import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.BaseTabControl;
+import org.jboss.tools.jst.jsp.outline.cssdialog.tabs.ICSSTabControl;
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;
-import org.xml.sax.Attributes;
/**
* Class for creating style tabs
- *
+ *
* @author Igor Zhukov (izhukov(a)exadel.com)
*/
public class StyleComposite extends Composite {
- private static String NODE_NAME_ELEMENTS = "elements";
- private static String NODE_NAME_VALUE = "value";
- private static String NODE_NAME_ELEMENT = "element";
- private static String NODE_ATTRIBUTE_NAME = "name";
+ private TabFolder tabFolder;
+ private StyleAttributes styleAttributes;
+ public static int DEFAULT_START_TAB = 4;
- private static int TAB_TEXT_FONT_NUMBER = 0;
- private static int FIRST_SELECTION = 0;
- private static int SIZE_NULL = 0;
+ /**
+ * StyleComposite constructor.
+ *
+ * @param parent
+ * Composite object
+ * @param styleAttributes
+ * StyleAttributes objects
+ * @param oldStyle
+ * String value
+ */
+ public StyleComposite(Composite parent, StyleAttributes styleAttributes,
+ DataBindingContext bindingContext) {
+ super(parent, SWT.NONE);
+ this.styleAttributes = styleAttributes;
- private String newStyle;
- private String oldStyle;
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ setLayout(gridLayout);
+ setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
- private TabTextControl tabTextControl;
- private TabBackgroundControl tabBackgroundControl;
- private TabBoxesControl tabBoxesControl;
- private TabPropertySheetControl tabPropertySheetControl;
- private TabQuickEditControl tabQuickEditControl;
- private TabPreviewControl tabPreviewControl;
+ tabFolder = new TabFolder(this, SWT.NONE);
+ tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
+ true, true));
+ tabFolder.addSelectionListener(new SelectionListener() {
- 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;
- private HashMap<String, ArrayList<String>> comboMap = new HashMap<String, ArrayList<String>>();
- private HashMap<String, ArrayList<String>> elementsMap = new HashMap<String, ArrayList<String>>();
+ public void widgetSelected(SelectionEvent e) {
- private boolean showPreviewTab = false;
- private CSSModel cssModel = null;
+ final TabItem tabItem = (TabItem) e.item;
+ if (tabItem.getData() instanceof ICSSTabControl)
+ ((ICSSTabControl) tabItem.getData()).tabSelected();
+ }
- /**
- * StyleComposite constructor.
- *
- * @param parent Composite object
- * @param styleAttributes StyleAttributes objects
- * @param oldStyle String value
- */
- public StyleComposite(Composite parent, StyleAttributes styleAttributes, String oldStyle) {
- super(parent, SWT.NONE);
- this.oldStyle = oldStyle;
- this.styleAttributes = styleAttributes;
- createTabs();
- }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
- /**
- * Gets updated style.
- *
- * @return new style value
- */
- public String getNewStyle() {
- return newStyle;
- }
+ // add text tab
+ ScrolledComposite tabComposite = createTabComposite();
- /**
- * Update new style in accordance with the style attribute values.
- */
- public void updateStyle() {
- if (lastSelectedTab == tabTextFont) {
- tabTextControl.updateData(true);
- } else if (lastSelectedTab == tabBackground) {
- tabBackgroundControl.updateData(true);
- } else if (lastSelectedTab == tabBoxes) {
- tabBoxesControl.updateData(true);
- } else if (lastSelectedTab == tabPropertySheet) {
- tabPropertySheetControl.updateData(true);
- }
- // update newStyle value
- newStyle = styleAttributes.getStyle();
- }
+ BaseTabControl baseTabControl = new TabTextControl(tabComposite,
+ styleAttributes, bindingContext);
- /**
- * Method is used to create it child subtabs.
- */
- private void createTabs() {
- ComboParser comboParser = new ComboParser();
- comboParser.setListener(new BaseListener(comboMap) {
- private ArrayList<String> list = null;
+ createTabItem(tabComposite, baseTabControl,
+ JstUIMessages.TEXT_FONT_TAB_NAME,
+ JstUIMessages.TEXT_FONT_TAB_NAME);
- public void startElement(String uri, String localName, String nodeName, Attributes attrs) {
- if (nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENTS)) {
- return;
- }
+ tabComposite.setContent(baseTabControl);
+ tabComposite.setMinSize(baseTabControl.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT));
- if (!nodeName.trim().equalsIgnoreCase(NODE_NAME_VALUE)) {
- String name = nodeName;
- list = new ArrayList<String>();
- map.put(name, list);
- } else {
- list.add(attrs.getValue(NODE_ATTRIBUTE_NAME));
- }
- }
- });
- comboParser.parse();
+ // add background tab
+ tabComposite = createTabComposite();
- CSSElementsParser cssParser = new CSSElementsParser();
- cssParser.setListener(new BaseListener(elementsMap) {
- private ArrayList<String> list = null;
+ baseTabControl = new TabBackgroundControl(tabComposite,
+ styleAttributes, bindingContext);
- public void startElement(String uri, String localName, String nodeName, Attributes attrs) {
- if (nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENTS)) {
- return;
- }
+ createTabItem(tabComposite, baseTabControl,
+ JstUIMessages.BACKGROUND_TAB_NAME,
+ JstUIMessages.BACKGROUND_TAB_NAME);
- if (!nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENT)) {
- String name = nodeName;
- list = new ArrayList<String>();
- map.put(name, list);
- } else {
- list.add(attrs.getValue(NODE_ATTRIBUTE_NAME));
- }
- }
- });
- cssParser.parse();
+ tabComposite.setContent(baseTabControl);
+ tabComposite.setMinSize(baseTabControl.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT));
- // HashMap<String, String> attributesMap = new HashMap<String, String>();
- ParserListener listener = new ParserListener(styleAttributes);
- parser = new Parser(elementsMap);
- parser.addListener(listener);
- parser.parse(this.oldStyle);
+ // add boxes tab
+ tabComposite = createTabComposite();
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 1;
- setLayout(gridLayout);
- setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+ baseTabControl = new TabBoxesControl(tabComposite, styleAttributes,
+ bindingContext);
- tabFolder = new TabFolder(this, SWT.NONE);
- tabFolder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+ createTabItem(tabComposite, baseTabControl,
+ JstUIMessages.BOXES_TAB_NAME, JstUIMessages.BOXES_TAB_NAME);
- // Create each tab and set its text, tool tip text,
- tabTextFont = new TabItem(tabFolder, SWT.NONE);
- tabTextFont.setText(JstUIMessages.TEXT_FONT_TAB_NAME);
- tabTextFont.setToolTipText(tabTextFont.getText());
- tabTextFont.setControl(createTabTextControl(tabFolder));
- lastSelectedTab = tabTextFont;
+ tabComposite.setContent(baseTabControl);
+ tabComposite.setMinSize(baseTabControl.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT));
- tabBackground = new TabItem(tabFolder, SWT.NONE);
- tabBackground.setText(JstUIMessages.BACKGROUND_TAB_NAME);
- tabBackground.setToolTipText(JstUIMessages.BACKGROUND_TAB_NAME);
- tabBackground.setControl(createTabBackgroundControl(tabFolder));
+ // add propertie tab
+ tabComposite = createTabComposite();
+ baseTabControl = new TabPropertySheetControl(tabComposite,
+ styleAttributes, bindingContext);
- tabBoxes = new TabItem(tabFolder, SWT.NONE);
- tabBoxes.setText(JstUIMessages.BOXES_TAB_NAME);
- tabBoxes.setToolTipText(JstUIMessages.BOXES_TAB_NAME);
- tabBoxes.setControl(createTabBoxesControl(tabFolder));
+ createTabItem(tabComposite, baseTabControl,
+ JstUIMessages.PROPERTY_SHEET_TAB_NAME,
+ JstUIMessages.PROPERTY_SHEET_TAB_NAME);
- tabPropertySheet = new TabItem(tabFolder, SWT.NONE);
- tabPropertySheet.setText(JstUIMessages.PROPERTY_SHEET_TAB_NAME);
- tabPropertySheet.setToolTipText(JstUIMessages.PROPERTY_SHEET_TAB_NAME);
- tabPropertySheet.setControl(createTabPropertySheetControl(tabFolder));
+ tabComposite.setContent(baseTabControl);
+ tabComposite.setMinSize(baseTabControl.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT));
- if (showPreviewTab) {
- tabPreview = new TabItem(tabFolder, SWT.NONE);
- tabPreview.setText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setToolTipText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setControl(createPreviewContol(tabFolder));
- }
+ // add quick edit tab
+ tabComposite = createTabComposite();
+ baseTabControl = new TabQuickEditControl(tabComposite, styleAttributes,
+ bindingContext);
- tabFolder.setSelection(TAB_TEXT_FONT_NUMBER);
+ createTabItem(tabComposite, baseTabControl,
+ JstUIMessages.QUICK_EDIT_TAB_NAME,
+ JstUIMessages.QUICK_EDIT_TAB_NAME);
- tabQuickEdit = new TabItem(tabFolder, SWT.NONE);
- tabQuickEdit.setText(JstUIMessages.QUICK_EDIT_TAB_NAME);
- tabQuickEdit.setToolTipText(JstUIMessages.QUICK_EDIT_TAB_NAME);
- tabQuickEdit.setControl(createTabQuickEditContol(tabFolder));
-
- if (styleAttributes.getAttributeMap().size() > SIZE_NULL) {
- tabFolder.setSelection(tabQuickEdit);
- lastSelectedTab = tabQuickEdit;
- }
+ tabComposite.setContent(baseTabControl);
+ tabComposite.setMinSize(baseTabControl.computeSize(SWT.DEFAULT,
+ SWT.DEFAULT));
- tabFolder.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent se) {
- if (tabFolder.getSelection()[FIRST_SELECTION] == tabQuickEdit) {
- tabQuickEditControl.dispose();
- tabQuickEdit.setControl(createTabQuickEditContol(tabFolder));
- lastSelectedTab = tabQuickEdit;
- } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabTextFont) {
- tabTextControl.updateData(false);
- lastSelectedTab = tabTextFont;
- } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabBackground) {
- tabBackgroundControl.updateData(false);
- lastSelectedTab = tabBackground;
- } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabBoxes) {
- tabBoxesControl.updateData(false);
- lastSelectedTab = tabBoxes;
- } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabPreview) {
- if(!styleAttributes.isValid()){
- //mareshkau, if styles attributes not valid we cann't create
- //correct preview
- return;
- }
- cssModel.setCSS(styleAttributes.getCssSelector(), styleAttributes);
- tabPreviewControl.selectEditorArea(styleAttributes.getCssSelector(), 0);
- lastSelectedTab = tabPreview;
- } else if (tabFolder.getSelection()[FIRST_SELECTION] == tabPropertySheet) {
- // TODO: changes on property sheet tag should reflect changes to another tabs
- tabPropertySheetControl.updateData(false);
- lastSelectedTab = tabPropertySheet;
- }
- }
- });
- }
+ }
- /**
- * 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);
+ /**
+ * Clear whole style composite component.
+ */
+ public void clearStyleComposite() {
+ styleAttributes.clear();
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
+ }
- tabTextControl = new TabTextControl(sc, comboMap, styleAttributes);
- sc.setContent(tabTextControl);
- sc.setMinSize(tabTextControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ /**
+ * Clear whole style composite component.
+ */
+ public void setStyleProperties(Map<String, String> properties) {
+ styleAttributes.setStyleProperties(properties);
- 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);
+ public TabFolder getTabFolder() {
+ return tabFolder;
+ }
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
+ public TabItem createTabItem(Composite content, ICSSTabControl tabControl,
+ String label, String tooltip) {
- tabBackgroundControl = new TabBackgroundControl(sc, comboMap, styleAttributes);
- sc.setContent(tabBackgroundControl);
- sc.setMinSize(tabBackgroundControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ TabItem item = new TabItem(tabFolder, SWT.NONE);
+ item.setText(label);
+ item.setToolTipText(tooltip);
+ item.setControl(content);
+ item.setData(tabControl);
+ return item;
- 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);
+ public ScrolledComposite createTabComposite() {
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
+ ScrolledComposite scroll = new ScrolledComposite(tabFolder,
+ SWT.H_SCROLL | SWT.V_SCROLL);
- tabBoxesControl = new TabBoxesControl(sc, comboMap, styleAttributes);
- sc.setContent(tabBoxesControl);
- sc.setMinSize(tabBoxesControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ scroll.setExpandHorizontal(true);
+ scroll.setExpandVertical(true);
- return sc;
- }
+ return scroll;
+ }
- /**
- * 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);
+ public void selectTab(int index) {
- sc.setExpandHorizontal(true);
- sc.setExpandVertical(true);
+ tabFolder.setSelection(index);
+ TabItem item = tabFolder.getItem(index);
+ if (item.getData() instanceof ICSSTabControl)
+ ((ICSSTabControl) item.getData()).tabSelected();
- 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);
-
- 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);
-
- ManualChangeStyleListener[] listeners = null;
- if (tabQuickEditControl != null) {
- listeners = tabQuickEditControl.getManualChangeStyleListeners();
- }
- tabQuickEditControl = new TabQuickEditControl(sc, comboMap, styleAttributes);
- if (listeners != null && listeners.length > 0) {
- tabQuickEditControl.addManualChangeStyleListener(listeners[0]);
- }
- sc.setContent(tabQuickEditControl);
-
- sc.setMinSize(tabQuickEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- return sc;
- }
-
- /**
- * Clear whole style composite component.
- */
- public void clearStyleComposite(String cssSelector) {
- styleAttributes.clear();
- styleAttributes.setCssSelector(cssSelector);
-
- tabBackgroundControl.updateData(false);
- tabBoxesControl.updateData(false);
- tabPropertySheetControl.updateData(false);
- tabTextControl.updateData(false);
-
- if (tabQuickEdit != null) {
- tabQuickEditControl.updateData();
- }
- }
-
- /**
- * Recreate style composite tab widgets.
- *
- * @param style CSS style
- */
- public void recreateStyleComposite(String style, String cssSelector) {
- styleAttributes.clear();
- styleAttributes.setCssSelector(cssSelector);
- parser.parse(style);
-
- tabBackgroundControl.updateData(false);
- tabBoxesControl.updateData(false);
- tabPropertySheetControl.updateData(false);
- tabTextControl.updateData(false);
-
- if (styleAttributes.getAttributeMap().size() > SIZE_NULL) {
- if ((tabQuickEdit == null) || tabQuickEdit.isDisposed()) {
- tabQuickEdit = new TabItem(tabFolder, SWT.NONE);
- 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();
- }
-
- tabFolder.setSelection(tabQuickEdit);
- lastSelectedTab = tabQuickEdit;
- } else {
- if (tabQuickEdit != null && !tabQuickEdit.isDisposed()) {
-// tabQuickEdit.dispose();
- tabQuickEditControl.updateData();
- }
- tabFolder.redraw();
- }
- }
-
- /**
- * Method is used to update preview tab with corresponding CSS file.
- *
- * @param cssModel model associated with the file that should be displayed in preview tab
- */
- public void initPreview(CSSModel cssModel) {
- if (showPreviewTab && ((tabPreview == null) || tabPreview.isDisposed())) {
- tabPreview = new TabItem(tabFolder, SWT.NONE);
- tabPreview.setText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setToolTipText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setControl(createPreviewContol(tabFolder));
- }
- if (tabPreviewControl != null) {
- tabPreviewControl.initPreview(cssModel);
- if (lastSelectedTab == tabPreview) {
- cssModel.setCSS(styleAttributes.getCssSelector(), styleAttributes);
- tabPreviewControl.selectEditorArea(styleAttributes.getCssSelector(), 0);
- }
- }
- }
-
- /**
- * Method is used to update preview selection area.
- *
- * @param selector CSS selector
- */
- public void updatePreview(String selector) {
- if (tabPreviewControl != null && lastSelectedTab == tabPreview) {
- cssModel.setCSS(selector, styleAttributes);
- tabPreviewControl.selectEditorArea(selector, 0);
- }
- }
-
- /**
- * Method is used to revert preview to before-saved state.
- */
- public void revertPreview() {
- if (showPreviewTab && ((tabPreview == null) || tabPreview.isDisposed())) {
- tabPreview = new TabItem(tabFolder, SWT.NONE);
- tabPreview.setText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setToolTipText(JstUIMessages.PREVIEW_SHEET_TAB_NAME);
- tabPreview.setControl(createPreviewContol(tabFolder));
- }
- if (tabPreviewControl != null) {
- tabPreviewControl.doRevertToSaved();
- tabPreviewControl.selectEditorArea(styleAttributes.getCssSelector(), 0);
- }
- }
-
- /**
- * @param showPreviewTab the showPreviewTab to set
- */
- public void setShowPreviewTab(boolean showPreviewTab) {
- this.showPreviewTab = showPreviewTab;
}
- /**
- * @param cssModel the cssModel to set
- */
- public void setCSSModel(CSSModel cssModel) {
- this.cssModel = cssModel;
- }
-
- /**
- * @return the showPreviewTab
- */
- public boolean isShowPreviewTab() {
- return showPreviewTab;
- }
-
- /**
- * 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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSConstants.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,31 +10,119 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.common;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.BaseListener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.CSSParser;
+import org.xml.sax.Attributes;
+
/**
* This class contains CSS constants
- *
+ *
* @author dsakovich(a)exadel.com
*/
public class CSSConstants {
- public static final String BACKGROUND_REPEAT = "background-repeat"; //$NON-NLS-1$
- public static final String BACKGROUND_COLOR = "background-color"; //$NON-NLS-1$
- public static final String BACKGROUND_IMAGE = "background-image"; //$NON-NLS-1$
- public static final String BORDER_STYLE = "border-style"; //$NON-NLS-1$
- public static final String BORDER_WIDTH = "border-width"; //$NON-NLS-1$
- public static final String WIDTH = "width"; //$NON-NLS-1$
- public static final String HEIGHT = "height"; //$NON-NLS-1$
- public static final String BORDER_COLOR = "border-color"; //$NON-NLS-1$
- public static final String MARGIN = "margin"; //$NON-NLS-1$
- public static final String PADDING = "padding"; //$NON-NLS-1$
- public static final String FONT_SIZE = "font-size"; //$NON-NLS-1$
- public static final String FONT_STYLE = "font-style"; //$NON-NLS-1$
- public static final String FONT_WEIGHT = "font-weight"; //$NON-NLS-1$
- public static final String TEXT_DECORATION = "text-decoration"; //$NON-NLS-1$
- 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 BACKGROUND_REPEAT = "background-repeat"; //$NON-NLS-1$
+ public static final String BACKGROUND_COLOR = "background-color"; //$NON-NLS-1$
+ public static final String BACKGROUND_IMAGE = "background-image"; //$NON-NLS-1$
+ public static final String BORDER_STYLE = "border-style"; //$NON-NLS-1$
+ public static final String BORDER_WIDTH = "border-width"; //$NON-NLS-1$
+ public static final String WIDTH = "width"; //$NON-NLS-1$
+ public static final String HEIGHT = "height"; //$NON-NLS-1$
+ public static final String BORDER_COLOR = "border-color"; //$NON-NLS-1$
+ public static final String MARGIN = "margin"; //$NON-NLS-1$
+ public static final String PADDING = "padding"; //$NON-NLS-1$
+ public static final String FONT_SIZE = "font-size"; //$NON-NLS-1$
+ public static final String FONT_STYLE = "font-style"; //$NON-NLS-1$
+ public static final String FONT_WEIGHT = "font-weight"; //$NON-NLS-1$
+ public static final String TEXT_DECORATION = "text-decoration"; //$NON-NLS-1$
+ 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$
+ public static final String STYLE = "style"; //$NON-NLS-1$
+ public static final String CLASS = "class"; //$NON-NLS-1$
+
+ public static final Map<String, ArrayList<String>> CSS_STYLE_VALUES_MAP = new HashMap<String, ArrayList<String>>();
+
+ public static final Map<String, ArrayList<String>> CSS_STYLES_MAP = new HashMap<String, ArrayList<String>>();
+
+ public static Map<String, String> COLORS;
+
+ private static final String CSS_VALUES_FILE = "cssdialog/cssElementsWithCombo.xml"; //$NON-NLS-1$
+ private static final String CSS_STYLES_FILE = "cssdialog/cssElements.xml"; //$NON-NLS-1$
+ private static final String COLORS_FILE = "cssdialog/color_properties.xml"; //$NON-NLS-1$
+
+ private static final String NODE_NAME_ELEMENTS = "elements"; //$NON-NLS-1$
+ private static final String NODE_NAME_VALUE = "value"; //$NON-NLS-1$
+ private static final String NODE_NAME_ELEMENT = "element"; //$NON-NLS-1$
+ private static final String NODE_ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+
+ static {
+
+ // initialize colors
+ try {
+
+ Properties properties = new Properties();
+
+ InputStream is = JspEditorPlugin.getDefault().getBundle()
+ .getResource(COLORS_FILE).openStream();
+ properties.loadFromXML(is);
+
+ is.close();
+ COLORS = (Map) properties;
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ CSSParser parser = new CSSParser();
+ parser.setListener(new BaseListener(CSS_STYLE_VALUES_MAP) {
+ private ArrayList<String> list = null;
+
+ public void startElement(String uri, String localName,
+ String nodeName, Attributes attrs) {
+ if (nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENTS)) {
+ return;
+ }
+
+ if (!nodeName.trim().equalsIgnoreCase(NODE_NAME_VALUE)) {
+ String name = nodeName;
+ list = new ArrayList<String>();
+ map.put(name, list);
+ } else {
+ list.add(attrs.getValue(NODE_ATTRIBUTE_NAME));
+ }
+ }
+ });
+ parser.parse(CSS_VALUES_FILE);
+
+ parser.setListener(new BaseListener(CSS_STYLES_MAP) {
+ private ArrayList<String> list = null;
+
+ public void startElement(String uri, String localName,
+ String nodeName, Attributes attrs) {
+ if (nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENTS)) {
+ return;
+ }
+
+ if (!nodeName.trim().equalsIgnoreCase(NODE_NAME_ELEMENT)) {
+ String name = nodeName;
+ list = new ArrayList<String>();
+ map.put(name, list);
+ } else {
+ list.add(attrs.getValue(NODE_ATTRIBUTE_NAME));
+ }
+ }
+ });
+ parser.parse(CSS_STYLES_FILE);
+
+ }
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSModel.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.common;
-import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -28,8 +27,6 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -42,7 +39,6 @@
import org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
import org.w3c.dom.css.CSSStyleDeclaration;
@@ -54,55 +50,54 @@
*
*
*/
-public class CSSModel {
+public class CSSModel implements ICSSDialogModel {
- private static String startBraces = "{"; //$NON-NLS-1$
- private static String endBraces = "}"; //$NON-NLS-1$
+ private static String startBraces = "{"; //$NON-NLS-1$
+ private static String endBraces = "}"; //$NON-NLS-1$
- private FormatProcessorCSS formatProcessorCSS = null;
- private IStructuredModel model = null;
- private IFile styleFile = null;
+ private IStructuredModel model = null;
+ private IFile styleFile = null;
- private CSSStyleSheet styleSheet = null;
- private ICSSStyleSheet eclipseStyleSheet = null;
- private String COPY_SUFFIX = "_copy";
- private boolean copy = false;
-
-
+ private CSSStyleSheet styleSheet = null;
+ private static final String COPY_SUFFIX = "_copy"; //$NON-NLS-1$
+ private boolean copy = false;
+
/**
- * Constructor.
- *
- * @param styleFile CSS style class that should initialize CSS model
- */
- public CSSModel(IFile styleFile) {
- init(styleFile);
- }
+ * Constructor.
+ *
+ * @param styleFile
+ * CSS style class that should initialize CSS model
+ */
+ public CSSModel(final IFile file) {
+ this.styleFile = file;
+ if (file != null)
+ init();
+ }
- public void init(IFile styleFile) {
- try {
- this.styleFile = styleFile;
- if (model != null) {
- releaseModel();
- }
- copy = false;
- formatProcessorCSS = new FormatProcessorCSS();
- IModelManager modelManager = StructuredModelManager.getModelManager();
- model = modelManager.getExistingModelForEdit(styleFile);
-
-
- if (model == null)
+ protected void init() {
+
+ try {
+ if (model != null) {
+ release();
+ }
+ copy = false;
+ IModelManager modelManager = StructuredModelManager
+ .getModelManager();
+ model = modelManager.getExistingModelForEdit(styleFile);
+
+ if (model == null) {
model = modelManager.getModelForEdit(styleFile);
- else {
+ } else {
copy = true;
- // copy the model
+ // copy the model
model = modelManager.copyModelForEdit(model.getId(), model
.getId()
+ COPY_SUFFIX);
-
- // set the correct location
+
+ // set the correct location
model.setBaseLocation(styleFile.getLocation().toString());
-
+
// some steps to prepare document ( it is necessary to correct
// work of highlight in preview tab )
IDocumentPartitioner partitioner = new StructuredTextPartitionerForCSS();
@@ -111,216 +106,131 @@
IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING,
partitioner);
partitioner.connect(model.getStructuredDocument());
-
+
}
if (model instanceof ICSSModel) {
- ICSSModel cssModel = (ICSSModel) model;
- ICSSDocument document = cssModel.getDocument();
- if (document instanceof CSSStyleSheet) {
- styleSheet = (CSSStyleSheet) document;
- prepareModel(styleSheet);
- }
- if (document instanceof ICSSStyleSheet) {
- eclipseStyleSheet = (ICSSStyleSheet) document;
- }
-
-
- }
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (ResourceInUse e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
+ ICSSModel cssModel = (ICSSModel) model;
- /**
- * Method is used to select area that corresponds to specific selector.
- *
- * @param selector the selector that should be selected in editor area
- * @param index if CSS file contains more then one elements with the same selector name,
- * then index is serial number of this selector
- */
- public IndexedRegion getSelectorRegion(String selector, int index) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (eclipseStyleSheet != null) {
-// if (selector != null && !selector.equals(Constants.EMPTY)) {
-// ICSSStyleRule styleRule = Util.getSelector(eclipseStyleSheet, selector, index);
-// if (styleRule != null) {
-// if (styleRule instanceof IndexedRegion) {
-// return (IndexedRegion) styleRule;
-// }
-// }
-// }
-// }
-
- if ( selector != null) {
- CSSStyleRule rule = getRulesMapping().get(selector);
- if (rule != null)
- if (rule instanceof IndexedRegion) {
- return (IndexedRegion) rule;
+ if (cssModel.getDocument() instanceof CSSStyleSheet) {
+ styleSheet = (CSSStyleSheet) cssModel.getDocument();
+ prepareModel(styleSheet);
}
-
+ }
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (ResourceInUse e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
}
- return null;
- }
-
-
- public List<String> getSelectorLabels() {
- List<String> selectorLabels;
+ }
- selectorLabels = new ArrayList<String>(getRulesMapping().keySet());
+ public String addCSSRule(final String selector) {
+ String selectorLabel = null;
+ if ((styleSheet != null) && (selector != null)
+ && !selector.equals(Constants.EMPTY)) {
+ CSSStyleRule rule = (CSSStyleRule) ((ICSSDocument) styleSheet)
+ .createCSSRule(selector + startBraces + endBraces);
+ ((ICSSStyleSheet) styleSheet).appendRule(rule);
- Collections.sort(selectorLabels);
+ for (Map.Entry<String, CSSStyleRule> ruleEntry : getRulesMapping()
+ .entrySet()) {
+ if (ruleEntry.getValue() == rule)
+ selectorLabel = ruleEntry.getKey();
+ }
- return selectorLabels;
+ }
+ return selectorLabel;
}
- /**
- * Gets CSS attributes for the given selector in string representation.
- *
- * @param selector CSS selector value
- * @return CSS attributes string representation
- */
- public String getCSSText(String selector) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// if (styleSheet != null && selector != 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();
-// }
-// }
-// }
-// }
- if ( selector != null) {
- CSSStyleRule rule = getRulesMapping().get(selector);
+ protected CSSStyleRule getCSSStyle(final String selectorLabel) {
+ if (selectorLabel != null) {
+ final CSSStyleRule rule = getRulesMapping().get(selectorLabel);
if (rule != null)
- return rule.getCssText();
+ return rule;
}
- return null;
- }
+ return null;
+ }
- /**
- * Get style by selectorName
- *
- * @param selectorName
- * @return style
- */
- public String getStyle(String selectorName) {
- //FIXED by sdzmitrovich - JBIDE-3148
-// 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();
-// }
-// }
-// }
-// }
- if (selectorName != null) {
- CSSStyleRule rule = getRulesMapping().get(selectorName);
+ public IDocument getDocument() {
+ if (model != null)
+ return model.getStructuredDocument();
+ return null;
+ }
+
+ public IFile getFile() {
+ return styleFile;
+ }
+
+ public IndexedRegion getIndexedRegion(final String selectorLabel) {
+ if (selectorLabel != null) {
+ final CSSStyleRule rule = getRulesMapping().get(selectorLabel);
if (rule != null)
- return rule.getStyle().getCssText();
+ if (rule instanceof IndexedRegion)
+ return (IndexedRegion) rule;
}
+ return null;
+ }
- return null;
- }
+ public String getSelectorLabel(final int offset) {
+ ICSSNode node = (ICSSNode) model.getIndexedRegion(offset);
- /**
- * Sets CSS style for the given selector.
- *
- * @param selector CSS selector value
- * @param styleAttribute the style to be set
- */
- public void setCSS(String selector, StyleAttributes styleAttributes) {
- if (styleSheet != null && selector != null && !selector.equals(Constants.EMPTY)) {
- CSSRuleList list = styleSheet.getCssRules();
- //FIXED by sdzmitrovich - JBIDE-3148
-// 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);
-// styleSheet.deleteRule(i);
-//
-// i = styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, i);
-// rule = (CSSStyleRule) list.item(i);
-// CSSStyleDeclaration declaration = rule.getStyle();
-// // set properties
-// Set<Entry<String, String>> set = styleAttributes.entrySet();
-// for (Map.Entry<String, String> me : set) {
-// declaration.setProperty(me.getKey(), me.getValue(), Constants.EMPTY);
-// }
-//
-// formatProcessorCSS.formatModel(model);
-// return;
-// }
-// }
-// // insert NEW selector to style sheet
-// styleSheet.insertRule(selector + startBraces + styleAttributes.getStyle() + endBraces, list.getLength());
-// formatProcessorCSS.formatModel(model);
- CSSStyleRule rule = getRulesMapping().get(selector);
- if (rule == null) {
- rule = (CSSStyleRule)((ICSSDocument)styleSheet).createCSSRule(
- selector + startBraces + styleAttributes.getStyle() + endBraces);
- ((ICSSStyleSheet)styleSheet).appendRule(rule);
- } else {
+ while (node != null) {
- CSSStyleDeclaration declaration = rule.getStyle();
- // set properties
- Set<Entry<String, String>> set = styleAttributes.entrySet();
-
- if ((set.size() == 0) && (declaration.getLength()>0))
- declaration.setCssText(Constants.EMPTY);
- else
- for (Map.Entry<String, String> me : set) {
- declaration.setProperty(me.getKey(), me.getValue(),
- Constants.EMPTY);
- }
+ if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
+ break;
+ } else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
+ node = ((ICSSStyleSheet) node).getFirstChild();
+ break;
}
- }
- }
- /**
- * Gets file associated with current model.
- *
- * @return the styleFile
- */
- public IFile getStyleFile() {
- return this.styleFile;
+ node = node.getParentNode();
+ }
+
+ if (node != null) {
+ for (final Entry<String, CSSStyleRule> rule : getRulesMapping()
+ .entrySet()) {
+ if (node.equals(rule.getValue()))
+ return rule.getKey();
+ }
+ }
+ return null;
}
- /**
- * Release CSS model correctly from editing.
- */
- public void releaseModel() {
+ public List<String> getSelectorLabels() {
+
+ List<String> selectorLabels;
+
+ selectorLabels = new ArrayList<String>(getRulesMapping().keySet());
+
+ Collections.sort(selectorLabels);
+
+ return selectorLabels;
+ }
+
+ public void reinit() {
+ init();
+
+ }
+
+ public void release() {
IModelManager modelManager = StructuredModelManager.getModelManager();
- if (model != null && !modelManager.isShared(model.getId()))
+
+ if ((model != null) && !modelManager.isShared(model.getId()) /* copy */) {
model.releaseFromEdit();
+ }
model = null;
+
}
- /**
- * Save model. Associate file will be saved automatically.
- */
- public void saveModel() {
- try {
-
- /*
+ public void save() {
+ try {
+
+ /*
* it is necessary not to dialog appears when "dirty" css file is
* being saved ( test case : 1) open css file 2) make same changes
* 3) open css dialog 4) make some changes 5)press ok )
@@ -335,16 +245,81 @@
LocationKind.NORMALIZE);
buffer.setDirty(false);
}
-
- model.save();
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
- }
-
- /**
+
+ model.save();
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e.getMessage());
+ }
+
+ }
+
+ public void setFile(final IFile file) {
+ this.styleFile = file;
+
+ }
+
+ public void updateCSSStyle(final String selectorLabel,
+ final StyleAttributes styleAttributes) {
+ if ((styleSheet != null) && (selectorLabel != null)
+ && !selectorLabel.equals(Constants.EMPTY)) {
+ final CSSStyleRule rule = getRulesMapping().get(selectorLabel);
+ if (rule != null) {
+
+ final CSSStyleDeclaration declaration = rule.getStyle();
+
+ // set properties
+ final Set<Entry<String, String>> set = styleAttributes
+ .entrySet();
+
+ if ((set.size() == 0) && (declaration.getLength() > 0)) {
+ declaration.setCssText(Constants.EMPTY);
+ } else {
+ for (final Map.Entry<String, String> me : set) {
+ if ((me.getValue() == null)
+ || (me.getValue().length() == 0)) {
+ declaration.removeProperty(me.getKey());
+ } else {
+ declaration.setProperty(me.getKey(), me.getValue(),
+ Constants.EMPTY);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ public Map<String, String> getClassProperties(final String selectorLabel) {
+ final CSSStyleRule rule = getRulesMapping().get(selectorLabel);
+ Map<String, String> styleMap = new HashMap<String, String>();
+ if (rule != null) {
+ final CSSStyleDeclaration declaration = rule.getStyle();
+ for (int i = 0; i < declaration.getLength(); i++) {
+ String propperty = declaration.item(i);
+ String value = declaration.getPropertyValue(propperty);
+ styleMap.put(propperty, value);
+ }
+ }
+
+ return styleMap;
+
+ }
+
+ private void prepareModel(final CSSStyleSheet styleSheet) {
+
+ final CSSRuleList rules = styleSheet.getCssRules();
+ if ((rules != null) && (rules.getLength() > 0)) {
+ final CSSRule rule = rules.item(rules.getLength() - 1);
+ final String text = rule.getCssText();
+ if ((text != null) && (!text.endsWith(endBraces))) {
+ rule.setCssText(text + "\n" + endBraces); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
* get mapping key is label ( label = class name + sequence number of such
* css class ) value is CSSStyleRule
*
@@ -352,19 +327,19 @@
* right but it demands more complex synchronization data
*
*/
- private Map<String, CSSStyleRule> getRulesMapping() {
+ protected Map<String, CSSStyleRule> getRulesMapping() {
- Map<String, CSSStyleRule> rulesMapping = new HashMap<String, CSSStyleRule>();
+ final Map<String, CSSStyleRule> rulesMapping = new HashMap<String, CSSStyleRule>();
if (styleSheet != null) {
- CSSRuleList list = styleSheet.getCssRules();
+ final CSSRuleList list = styleSheet.getCssRules();
- Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
+ final Map<String, Integer> frequencyMap = new HashMap<String, Integer>();
if (list != null) {
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i) instanceof CSSStyleRule) {
- CSSStyleRule rule = ((CSSStyleRule) list.item(i));
+ final CSSStyleRule rule = ((CSSStyleRule) list.item(i));
Integer freq = frequencyMap.get(rule.getSelectorText());
@@ -372,7 +347,7 @@
frequencyMap.put(rule.getSelectorText(), freq);
- String ruleLabel = rule.getSelectorText()
+ final String ruleLabel = rule.getSelectorText()
+ (freq > 1 ? Constants.START_BRACKET + freq
+ Constants.END_BRACKET
: Constants.EMPTY);
@@ -388,55 +363,18 @@
return rulesMapping;
}
- public IDocument getStructuredDocument() {
- return model.getStructuredDocument();
+ public String getCSSRuleText(final String selectorLabel) {
+ final CSSStyleRule rule = getCSSStyle(selectorLabel);
+ if (rule != null)
+ return rule.getCssText();
+ return null;
}
- public void reload() {
- try {
- if(model.isDirty()) {
- model.reload(new FileInputStream(styleFile.getLocation().toFile()));
- }
- } catch (Exception e) {
- JspEditorPlugin.getPluginLog().logError(e.getMessage());
- }
-
- }
-
- public String getSelectorByPosition(Point selectionInFile) {
-
- ICSSNode node = (ICSSNode) model.getIndexedRegion(selectionInFile.x);
-
- while (node != null) {
-
- if (node.getNodeType() == ICSSNode.STYLERULE_NODE) {
- break;
- } else if (node.getNodeType() == ICSSNode.STYLESHEET_NODE) {
- node = ((ICSSStyleSheet) node).getFirstChild();
- break;
- }
-
- node = node.getParentNode();
- }
-
- if (node != null)
- for (Entry<String, CSSStyleRule> rule : getRulesMapping()
- .entrySet()) {
- if (node.equals(rule.getValue()))
- return rule.getKey();
- }
+ public String getCSSStyleText(final String selectorLabel) {
+ final CSSStyleRule rule = getCSSStyle(selectorLabel);
+ if (rule != null)
+ return rule.getStyle().getCssText();
return null;
}
-
- private void prepareModel(CSSStyleSheet styleSheet) {
- CSSRuleList rules = styleSheet.getCssRules();
- if ((rules != null) && (rules.getLength() > 0)) {
- CSSRule rule = rules.item(rules.getLength() - 1);
- String text = rule.getCssText();
- if ((text != null) && (!text.endsWith(endBraces))) {
- rule.setCssText(text + "\n"+ endBraces); //$NON-NLS-1$
- }
- }
- }
}
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSSelectorValidator.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSSelectorValidator.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSSelectorValidator.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleRule;
+
+/**
+ * CSS Validator
+ *
+ * @author yradtsevich
+ *
+ */
+public class CSSSelectorValidator extends CSSValidator implements
+ IInputValidator {
+ private static Reference<CSSSelectorValidator> instanceCache;
+
+ public static CSSSelectorValidator getInstance() {
+ CSSSelectorValidator instance = null;
+ if (instanceCache != null) {
+ instance = instanceCache.get();
+ }
+ if (instance == null) {
+ instance = new CSSSelectorValidator();
+ instanceCache = new SoftReference<CSSSelectorValidator>(instance);
+ }
+ return instance;
+ }
+
+ private CSSSelectorValidator() {
+ super();
+ }
+
+ /**
+ * Validates CSS selector value.
+ *
+ * @param selector
+ * the selector value
+ * @return {@code true} if the selector is valid, {@code false} otherwise
+ */
+ public boolean isValidSelector(String selector) {
+ getValidatingDocument().set(selector + "{}"); //$NON-NLS-1$
+
+ CSSRuleList cssRules = getValidatingCSS().getCssRules();
+ if (cssRules.getLength() != 1) {
+ // if the selector is like 'a{} b', or it is empty, or the rule
+ // cannot be created
+ return false;
+ }
+
+ CSSStyleRule cssRule = (CSSStyleRule) cssRules.item(0);
+ if (!selector.equals(cssRule.getSelectorText())) {
+ // if the selector is like 'a{{{'
+ return false;
+ }
+
+ cleanValidatingDocument();
+
+ return true;
+ }
+
+ public String isValid(String value) {
+ return isValidSelector(value) ? null
+ : JstUIMessages.CSS_CLASS_NAME_NOT_VALID;
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSSelectorValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSStyleValueValidator.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSStyleValueValidator.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSStyleValueValidator.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.w3c.dom.css.CSSStyleDeclaration;
+import org.w3c.dom.css.CSSStyleRule;
+
+/**
+ * CSS Validator
+ *
+ * @author yradtsevich
+ *
+ */
+@SuppressWarnings("restriction")
+public class CSSStyleValueValidator extends CSSValidator implements IValidator {
+ private final LogHacker logHacker = new LogHacker();
+ private static Reference<CSSStyleValueValidator> instanceCache;
+
+ public static CSSStyleValueValidator getInstance() {
+ CSSStyleValueValidator instance = null;
+ if (instanceCache != null) {
+ instance = instanceCache.get();
+ }
+ if (instance == null) {
+ instance = new CSSStyleValueValidator();
+ instanceCache = new SoftReference<CSSStyleValueValidator>(instance);
+ }
+ return instance;
+ }
+
+ private CSSStyleValueValidator() {
+ super();
+ }
+
+ /**
+ * Validates value of a CSS attribute.
+ *
+ * @param value
+ * the
+ * @return {@code true} if the attribute is valid, {@code false} otherwise
+ */
+ public boolean isValidValue(String value) {
+ logHacker.disableLogging();
+ boolean valid = true;
+ try {
+ getValidatingCSS().insertRule(".testSelector {}", 0); //$NON-NLS-1$
+ CSSStyleRule cssRule = ((CSSStyleRule) getValidatingCSS()
+ .getCssRules().item(0));
+ CSSStyleDeclaration declaration = cssRule.getStyle();
+ declaration.setProperty("background", value, Constants.EMPTY); //$NON-NLS-1$
+ } catch (Throwable e) {
+ valid = false;
+ } finally {
+ logHacker.enableLogging();
+ cleanValidatingDocument();
+ }
+
+ return valid;
+ }
+
+ /**
+ * Provides a way to temporarily delete all loggers from
+ * {@link org.eclipse.core.internal.runtime.RuntimeLog}
+ *
+ * @author yradtsevich
+ *
+ */
+ private class LogHacker {
+ private Field logListeners = null;
+ private Object oldValue = null;
+
+ public LogHacker() {
+ try {
+ logListeners = org.eclipse.core.internal.runtime.RuntimeLog.class
+ .getDeclaredField("logListeners"); //$NON-NLS-1$
+ logListeners.setAccessible(true);
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void disableLogging() {
+ try {
+ oldValue = logListeners.get(null);
+ logListeners.set(null, new ArrayList<Object>(0));
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void enableLogging() {
+ try {
+ if (oldValue != null) {
+ logListeners.set(null, oldValue);
+ }
+ } catch (Throwable e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } finally {
+ oldValue = null;
+ }
+ }
+ }
+
+ public IStatus validate(Object value) {
+ return isValidValue((String) value) ? Status.OK_STATUS : new Status(
+ IStatus.ERROR, JspEditorPlugin.PLUGIN_ID,
+ JstUIMessages.CSS_INVALID_STYLE_PROPERTY);
+ }
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSStyleValueValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/CSSValidator.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,19 +10,10 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.common;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-
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.text.IStructuredDocument;
-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;
/**
@@ -31,28 +22,13 @@
* @author yradtsevich
*
*/
-@SuppressWarnings("restriction")
-public class CSSValidator {
+public abstract class CSSValidator {
// FIXME: this hard-coded string have to be replaced by reference
private static final String CSS_CONTENT_TYPE_IDENTIFIER = "org.eclipse.wst.css.core.csssource"; //$NON-NLS-1$
private final CSSStyleSheet validatingCSS;
private final IStructuredDocument validatingDocument;
- private final LogHacker logHacker = new LogHacker();
- private static Reference<CSSValidator> instanceCache;
- public static CSSValidator getInstance() {
- CSSValidator instance = null;
- if (instanceCache != null) {
- instance = instanceCache.get();
- }
- if (instance == null) {
- instance = new CSSValidator();
- instanceCache = new SoftReference<CSSValidator>(instance);
- }
- return instance;
- }
-
- private CSSValidator() {
+ public CSSValidator() {
IModelManager modelManager = StructuredModelManager.getModelManager();
ICSSModel validatingModel = (ICSSModel) modelManager
.createUnManagedStructuredModelFor(CSS_CONTENT_TYPE_IDENTIFIER);
@@ -60,102 +36,16 @@
validatingCSS = (CSSStyleSheet) validatingModel.getDocument();
}
- private void cleanValidatingDocument() {
+ protected void cleanValidatingDocument() {
validatingDocument.set(""); //$NON-NLS-1$
}
- /**
- * Validates value of a CSS attribute.
- *
- * @param value
- * the
- * @return {@code true} if the attribute is valid, {@code false} otherwise
- */
- public boolean isValidValue(String value) {
- logHacker.disableLogging();
- boolean valid = true;
- try {
- validatingCSS.insertRule(".testSelector {}", 0); //$NON-NLS-1$
- CSSStyleRule cssRule = ((CSSStyleRule) validatingCSS.getCssRules().item(0));
- CSSStyleDeclaration declaration = cssRule.getStyle();
- declaration.setProperty("background", value, Constants.EMPTY); //$NON-NLS-1$
- } catch (Throwable e) {
- valid = false;
- } finally {
- logHacker.enableLogging();
- cleanValidatingDocument();
- }
-
- return valid;
+ protected CSSStyleSheet getValidatingCSS() {
+ return validatingCSS;
}
- /**
- * Validates CSS selector value.
- *
- * @param selector
- * the selector value
- * @return {@code true} if the selector is valid, {@code false} otherwise
- */
- public boolean isValidSelector(String selector) {
- validatingDocument.set(selector + "{}"); //$NON-NLS-1$
-
- CSSRuleList cssRules = validatingCSS.getCssRules();
- if (cssRules.getLength() != 1) {
- // if the selector is like 'a{} b', or it is empty, or the rule cannot be created
- return false;
- }
-
- CSSStyleRule cssRule = (CSSStyleRule) cssRules.item(0);
- if (!selector.equals(cssRule.getSelectorText())) {
- // if the selector is like 'a{{{'
- return false;
- }
-
- cleanValidatingDocument();
-
- return true;
+ protected IStructuredDocument getValidatingDocument() {
+ return validatingDocument;
}
- /**
- * Provides a way to temporarily delete all loggers from
- * {@link org.eclipse.core.internal.runtime.RuntimeLog}
- *
- * @author yradtsevich
- *
- */
- private class LogHacker {
- private Field logListeners = null;
- private Object oldValue = null;
-
- public LogHacker() {
- try {
- logListeners = org.eclipse.core.internal.runtime.RuntimeLog.class
- .getDeclaredField("logListeners");
- logListeners.setAccessible(true);
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void disableLogging() {
- try {
- oldValue = logListeners.get(null);
- logListeners.set(null, new ArrayList<Object>(0));
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void enableLogging() {
- try {
- if (oldValue != null) {
- logListeners.set(null, oldValue);
- }
- } catch (Throwable e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } finally {
- oldValue = null;
- }
- }
- }
}
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ICSSDialogModel.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ICSSDialogModel.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ICSSDialogModel.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public interface ICSSDialogModel {
+
+ public String addCSSRule(String selector);
+
+ public String getCSSStyleText(String selectorLabel);
+
+ public String getCSSRuleText(String selectorLabel);
+
+ public IDocument getDocument();
+
+ public IFile getFile();
+
+ public IndexedRegion getIndexedRegion(String selectorLabel);
+
+ public String getSelectorLabel(int offset);
+
+ public List<String> getSelectorLabels();
+
+ public void reinit();
+
+ public void release();
+
+ public void save();
+
+ public void setFile(IFile file);
+
+ public void updateCSSStyle(String selectorLabel, StyleAttributes styleAttributes);
+
+ public Map<String, String> getClassProperties(final String selectorLabel);
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ICSSDialogModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ImageCombo.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ImageCombo.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/ImageCombo.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,1277 +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.jst.jsp.outline.cssdialog.common;
-
-import java.util.Arrays;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.TypedListener;
-import org.eclipse.swt.widgets.Widget;
-import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-
-
-/**
- * The ImageCombo Combo-Widget class with images represents a selectable user
- * interface object that combines a text field and a list and issues
- * notification when an item is selected from the list.
- *
- * @author dsakovich(a)exadel.com
- */
-public final class ImageCombo extends Composite {
- private static final boolean gtk = "gtk".equals(SWT.getPlatform());
- private static final int X = 0;
- private static final int Y = 0;
- private static final int WIDTH = 20;
- private static final int HEIGHT = 15;
- private static final int DEPTH = 1;
- private static final int DEFAULT_SELECTION = -1;
- private boolean dontDrop = false;
- private int visibleItemCount = 10;
- private Text text;
- private Table table;
- private Shell popup;
- private Button arrowButton;
- private boolean hasFocus;
- private Listener listener;
- private Listener filter;
-
- /**
- * Constructs a new instance of this class given its parent and a style
- * value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in class
- * <code>SWT</code> which is applicable to instances of this class, or must
- * be built by <em>bitwise OR</em>'ing together (that is, using the
- * <code>int</code> "|" operator) two or more of those <code>SWT</code>
- * style constants. The class description lists the style constants that are
- * applicable to the class. Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent
- * a widget which will be the parent of the new instance (cannot
- * be null)
- * @param style
- * the style of widget to construct
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the parent</li>
- * </ul>
- *
- * @see SWT#BORDER
- * @see SWT#READ_ONLY
- * @see SWT#FLAT
- * @see Widget#getStyle()
- */
- public ImageCombo(Composite parent, int style) {
- super(parent, style = checkStyle(style));
-
- int textStyle = SWT.SINGLE;
-
- if (gtk) {
- textStyle |= SWT.BORDER;
- }
-
- if ((style & SWT.READ_ONLY) != 0) {
- textStyle |= SWT.READ_ONLY;
- }
-
- if ((style & SWT.FLAT) != 0) {
- textStyle |= SWT.FLAT;
- }
-
- text = new Text(this, textStyle);
-
- int arrowStyle = SWT.ARROW | SWT.DOWN;
-
- if ((style & SWT.FLAT) != 0) {
- arrowStyle |= SWT.FLAT;
- }
-
- arrowButton = new Button(this, arrowStyle);
- listener = new Listener() {
- public void handleEvent(Event event) {
- if (popup == event.widget) {
- popupEvent(event);
-
- return;
- }
- if (text == event.widget) {
- textEvent(event);
-
- return;
- }
- if (table == event.widget) {
- listEvent(event);
-
- return;
- }
- if (arrowButton == event.widget) {
- arrowEvent(event);
-
- return;
- }
- if (ImageCombo.this == event.widget) {
- comboEvent(event);
-
- return;
- }
- if (getShell() == event.widget) {
- handleFocus(SWT.FocusOut);
- }
- }
- };
- filter = new Listener() {
- public void handleEvent(Event event) {
- Shell shell = ((Control) event.widget).getShell();
-
- if (shell == ImageCombo.this.getShell()) {
- handleFocus(SWT.FocusOut);
- }
- }
- };
-
- int[] comboEvents = { SWT.Dispose, SWT.Move, SWT.Resize };
- for (int i = 0; i < comboEvents.length; i++)
- this.addListener(comboEvents[i], listener);
-
- int[] textEvents = {
- SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn
- };
-
- for (int i = 0; i < textEvents.length; i++) {
- text.addListener(textEvents[i], listener);
- }
- int[] arrowEvents = { SWT.Selection, SWT.FocusIn };
-
- for (int i = 0; i < arrowEvents.length; i++) {
- arrowButton.addListener(arrowEvents[i], listener);
- }
- createPopup(DEFAULT_SELECTION);
- }
-
- /**
- * Check style.
- * @param style
- * @return
- */
- static int checkStyle(int style) {
- int mask = gtk ? (SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)
- : (SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-
- return style & mask;
- }
-
- /**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string
- * the new item
- *
- * @param image
- * image for the item
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
- public void add(String string, Image image) {
- checkWidget();
-
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- TableItem newItem = new TableItem(this.table, SWT.NONE);
- newItem.setText(string);
-
- if (image != null) {
- newItem.setImage(image);
- }
-
- newItem.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- TableItem item = (TableItem) e.getSource();
- item.getImage().dispose();
- }
- });
- }
-
- /**
- * Adds the argument to the receiver's list at the given zero-relative
- * index.
- * <p>
- * Note: To add an item at the end of the list, use the result of calling
- * <code>getItemCount()</code> as the index or use <code>add(String)</code>.
- * </p>
- *
- * @param string
- * the new item
- *
- * @param image
- * image for the item
- *
- * @param index
- * the index for the item
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0
- * and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String)
- */
- public void add(String string, Image image, int index) {
- checkWidget();
-
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- TableItem newItem = new TableItem(this.table, SWT.NONE, index);
-
- if (image != null) {
- newItem.setImage(image);
- newItem.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- TableItem item = (TableItem) e.getSource();
- item.getImage().dispose();
- }
- });
- }
- }
-
- /**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string
- * the new item
- * @param rgb
- * RGB color image for the item
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see #add(String,int)
- */
- public void add(String string, RGB rgb) {
- Color white = new Color(getDisplay(), Constants.RGB_WHITE);
- Color black = new Color(getDisplay(), Constants.RGB_BLACK);
- Color color = new Color(getDisplay(), rgb);
-
- Image image = new Image(getDisplay(), WIDTH, HEIGHT);
- GC gc = new GC(image);
- gc.setBackground(color);
- gc.fillRectangle(X, Y, WIDTH, HEIGHT);
- gc.setBackground(black);
- gc.drawRectangle(X, Y, WIDTH, HEIGHT);
- gc.dispose();
-
- ImageData imageData = image.getImageData();
- image.dispose();
- color.dispose();
-
- PaletteData palette = new PaletteData(new RGB[] { Constants.RGB_BLACK, Constants.RGB_WHITE, });
- ImageData maskData = new ImageData(WIDTH, HEIGHT, DEPTH, palette);
- Image mask = new Image(getDisplay(), maskData);
- gc = new GC(mask);
- gc.setBackground(black);
- gc.fillRectangle(X, Y, WIDTH, HEIGHT);
- gc.setBackground(white);
- gc.fillRectangle(X, Y, WIDTH, HEIGHT);
- gc.dispose();
- maskData = mask.getImageData();
- mask.dispose();
-
- Image icon = new Image(getDisplay(), imageData, maskData);
- color.dispose();
- black.dispose();
- white.dispose();
- add(string, icon);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the receiver's text is modified, by sending it one of the messages
- * defined in the <code>ModifyListener</code> interface.
- *
- * @param listener
- * the listener which should be notified
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
- */
- public void addModifyListener(ModifyListener listener) {
- checkWidget();
-
- if (listener == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Modify, typedListener);
- }
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when the receiver's selection changes, by sending it one of the messages
- * defined in the <code>SelectionListener</code> interface.
- * <p>
- * <code>widgetSelected</code> is called when the combo's list selection
- * changes. <code>widgetDefaultSelected</code> is typically called when
- * ENTER is pressed the combo's text area.
- * </p>
- *
- * @param listener
- * the listener which should be notified
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #removeSelectionListener
- * @see SelectionEvent
- */
- public void addSelectionListener(SelectionListener listener) {
- checkWidget();
-
- if (listener == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection, typedListener);
- addListener(SWT.DefaultSelection, typedListener);
- }
-
- /**
- *
- * @param event
- */
- void arrowEvent(Event event) {
- switch (event.type) {
- case SWT.FocusIn: {
- if (gtk) {
- setFocus();
-
- return;
- }
-
- handleFocus(SWT.FocusIn);
-
- break;
- }
-
- case SWT.Selection: {
- if (gtk) {
- if (!dontDrop) {
- dropDown(!isDropped());
- }
-
- dontDrop = false;
- } else {
- dropDown(!isDropped());
- }
-
- break;
- }
- }
- }
-
- /**
- *
- * @param event
- */
- void comboEvent(Event event) {
- switch (event.type) {
- case SWT.Dispose:
-
- if ((popup != null) && !popup.isDisposed()) {
- table.removeListener(SWT.Dispose, listener);
- popup.dispose();
- }
-
- Shell shell = getShell();
- shell.removeListener(SWT.Deactivate, listener);
-
- Display display = getDisplay();
- display.removeFilter(SWT.FocusIn, filter);
- popup = null;
- text = null;
- table = null;
- arrowButton = null;
-
- break;
-
- case SWT.Move:
- dropDown(false);
-
- break;
-
- case SWT.Resize:
- internalLayout(false);
-
- break;
- }
- }
-
- /**
- * Method for computing size for widget
- *
- * @param wHint
- * width
- * @param hHint
- * height
- * @return Point
- */
- public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
-
- int width = 0;
- int height = 0;
- String[] items = getStringsFromTable();
- int textWidth = 0;
- GC gc = new GC(text);
- int spacer = gc.stringExtent(Constants.WHITE_SPACE).x;
-
- for (int i = 0; i < items.length; i++) {
- textWidth = Math.max(gc.stringExtent(items[i]).x, textWidth);
- }
-
- gc.dispose();
-
- Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- Point arrowSize = arrowButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
- Point listSize = table.computeSize(wHint, SWT.DEFAULT, changed);
- int borderWidth = getBorderWidth();
-
- height = Math.max(hHint, Math.max(textSize.y, arrowSize.y) + (2 * borderWidth));
- width = Math.max(wHint,
- Math.max(textWidth + (2 * spacer) + arrowSize.x + (2 * borderWidth), listSize.x));
-
- return new Point(width, height);
- }
-
- /**
- * Method for creating popup table
- *
- * @param selectionIndex
- */
- void createPopup(int selectionIndex) {
- // create shell and list
- popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
-
- int style = getStyle();
- int listStyle = SWT.SINGLE | SWT.V_SCROLL;
-
- if ((style & SWT.FLAT) != 0) {
- listStyle |= SWT.FLAT;
- }
-
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- listStyle |= SWT.RIGHT_TO_LEFT;
- }
-
- if ((style & SWT.LEFT_TO_RIGHT) != 0) {
- listStyle |= SWT.LEFT_TO_RIGHT;
- }
-
- // create a table instead of a list.
- table = new Table(popup, listStyle);
- table.setToolTipText(JstUIMessages.IMAGE_COMBO_TABLE_TOOL_TIP);
-
- int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
-
- for (int i = 0; i < popupEvents.length; i++)
- popup.addListener(popupEvents[i], listener);
-
- int[] listEvents = {
- SWT.Traverse, SWT.MouseDoubleClick, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose
- };
-
- for (int i = 0; i < listEvents.length; i++)
- table.addListener(listEvents[i], listener);
-
- if (selectionIndex != -1) {
- table.setSelection(selectionIndex);
- }
- }
-
- /**
- *
- * @param drop
- */
- void dropDown(boolean drop) {
- if (drop == isDropped()) {
- return;
- }
-
- if (!drop) {
- popup.setVisible(false);
-
- if (!isDisposed() && arrowButton.isFocusControl()) {
- text.setFocus();
- }
-
- return;
- }
-
- if (getShell() != popup.getParent()) {
- int selectionIndex = table.getSelectionIndex();
- table.removeListener(SWT.Dispose, listener);
- popup.dispose();
- popup = null;
- table = null;
- createPopup(selectionIndex);
- }
-
- Point size = getSize();
- int itemCount = table.getItemCount();
- itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
-
- int itemHeight = table.getItemHeight() * itemCount;
- Point listSize = table.computeSize(SWT.DEFAULT, itemHeight, false);
- table.setBounds(1, 1, Math.max(size.x - 2, listSize.x), listSize.y);
-
- int index = table.getSelectionIndex();
-
- if (index != -1) {
- table.setTopIndex(index);
- }
-
- Display display = getDisplay();
- Rectangle listRect = table.getBounds();
- Rectangle parentRect = display.map(getParent(), null, getBounds());
- Point comboSize = getSize();
- Rectangle displayRect = getMonitor().getClientArea();
- int width = Math.max(comboSize.x, listRect.width + 2);
- int height = listRect.height + 2;
- int x = parentRect.x;
- int y = parentRect.y + comboSize.y;
-
- if ((y + height) > (displayRect.y + displayRect.height)) {
- y = parentRect.y - height;
- }
-
- popup.setBounds(x, y, width, height);
- popup.setVisible(true);
- table.setFocus();
- }
-
- /**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public int getItemCount() {
- checkWidget();
-
- return table.getItemCount();
- }
-
- String[] getStringsFromTable() {
- String[] items = new String[this.table.getItems().length];
-
- for (int i = 0, n = items.length; i < n; i++) {
- items[i] = this.table.getItem(i).getText();
- }
-
- return items;
- }
-
- /**
- * Returns the zero-relative index of the item which is currently selected
- * in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public int getSelectionIndex() {
- checkWidget();
-
- return table.getSelectionIndex();
- }
-
- /**
- * Method for getting widget style
- */
- public int getStyle() {
- int style = super.getStyle();
- style &= ~SWT.READ_ONLY;
-
- if (!text.getEditable()) {
- style |= SWT.READ_ONLY;
- }
-
- return style;
- }
-
- /**
- * Returns a string containing a copy of the contents of the receiver's text
- * field.
- *
- * @return the receiver's text
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public String getText() {
- checkWidget();
-
- return text.getText();
- }
-
- /**
- *
- * @param type
- */
- void handleFocus(int type) {
- if (isDisposed()) {
- return;
- }
-
- switch (type) {
- case SWT.FocusIn: {
- if (hasFocus) {
- return;
- }
-
- hasFocus = true;
-
- Shell shell = getShell();
- shell.removeListener(SWT.Deactivate, listener);
- shell.addListener(SWT.Deactivate, listener);
-
- Display display = getDisplay();
- display.removeFilter(SWT.FocusIn, filter);
- display.addFilter(SWT.FocusIn, filter);
-
- Event e = new Event();
- notifyListeners(SWT.FocusIn, e);
-
- break;
- }
-
- case SWT.FocusOut: {
- if (!hasFocus) {
- return;
- }
-
- Control focusControl = getDisplay().getFocusControl();
-
- if ((focusControl == arrowButton) || (focusControl == table) || (focusControl == text)) {
- return;
- }
-
- hasFocus = false;
-
- Shell shell = getShell();
- shell.removeListener(SWT.Deactivate, listener);
-
- Display display = getDisplay();
- display.removeFilter(SWT.FocusIn, filter);
-
- Event e = new Event();
- notifyListeners(SWT.FocusOut, e);
-
- break;
- }
- }
- }
-
- /**
- * Searches the receiver's list starting at the first item (index 0) until
- * an item is found that is equal to the argument, and returns the index of
- * that item. If no item is found, returns -1.
- *
- * @param string
- * the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public int indexOf(String string) {
- checkWidget();
-
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- return Arrays.asList(getStringsFromTable()).indexOf(string);
- }
-
- /**
- *
- * @return
- */
- boolean isDropped() {
- return popup.getVisible();
- }
-
- /**
- *
- * @param changed
- */
- void internalLayout(boolean changed) {
- if (isDropped()) {
- dropDown(false);
- }
-
- Rectangle rect = getClientArea();
- int width = rect.width;
- int height = rect.height;
- Point arrowSize = arrowButton.computeSize(SWT.DEFAULT, height, changed);
- text.setBounds(0, 0, width - arrowSize.x, height);
- arrowButton.setBounds(width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
- }
-
- /**
- *
- * @param event
- */
- void listEvent(Event event) {
- switch (event.type) {
- case SWT.Dispose:
-
- if (getShell() != popup.getParent()) {
- int selectionIndex = table.getSelectionIndex();
- popup = null;
- table = null;
- createPopup(selectionIndex);
- }
-
- break;
-
- case SWT.FocusIn: {
- handleFocus(SWT.FocusIn);
-
- break;
- }
-
- case SWT.MouseDoubleClick: {
- int index = table.getSelectionIndex();
-
- if (index == -1) {
- return;
- }
-
- text.setText(table.getItem(index).getText());
- table.setSelection(index);
-
- Event e = new Event();
- e.time = event.time;
- e.stateMask = event.stateMask;
- e.doit = event.doit;
- notifyListeners(SWT.Selection, e);
- event.doit = e.doit;
- dropDown(false);
-
- break;
- }
-
- case SWT.Traverse: {
- switch (event.detail) {
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_ESCAPE:
- case SWT.TRAVERSE_ARROW_PREVIOUS:
- case SWT.TRAVERSE_ARROW_NEXT:
- event.doit = false;
-
- break;
- }
-
- Event e = new Event();
- e.time = event.time;
- e.detail = event.detail;
- e.doit = event.doit;
- e.character = event.character;
- e.keyCode = event.keyCode;
- notifyListeners(SWT.Traverse, e);
- event.doit = e.doit;
- event.detail = e.detail;
-
- break;
- }
-
- case SWT.KeyUp: {
- Event e = new Event();
- e.time = event.time;
- e.character = event.character;
- e.keyCode = event.keyCode;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.KeyUp, e);
-
- break;
- }
-
- case SWT.KeyDown: {
- if (event.character == SWT.ESC) {
- // Escape key cancels popup list
- dropDown(false);
- }
-
- if (((event.stateMask & SWT.ALT) != 0) &&
- ((event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_DOWN))) {
- dropDown(false);
- }
-
- if (event.character == SWT.CR) {
- // Enter causes default selection
- dropDown(false);
-
- Event e = new Event();
- e.time = event.time;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.DefaultSelection, e);
- }
-
- if (isDisposed()) {
- break;
- }
-
- Event e = new Event();
- e.time = event.time;
- e.character = event.character;
- e.keyCode = event.keyCode;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.KeyDown, e);
-
- int index = table.getSelectionIndex();
-
- if (index == -1) {
- return;
- }
-
- text.setText(table.getItem(index).getText());
- table.setSelection(index);
-
- break;
- }
- }
- }
-
- /**
- *
- * @param event
- */
- void popupEvent(Event event) {
- switch (event.type) {
- case SWT.Paint:
-
- // draw black rectangle around list
- Rectangle listRect = table.getBounds();
- Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
- event.gc.setForeground(black);
- event.gc.drawRectangle(X, Y, listRect.width + 1, listRect.height + 1);
-
- break;
-
- case SWT.Close:
- event.doit = false;
- dropDown(false);
-
- break;
-
- case SWT.Deactivate:
-
- // when the popup shell is deactivated by clicking the button,
- // we receive two Deactivate events on Win32, whereas on GTK
- // we first receive one Deactivation event from the shell and
- // then a Selection event from the button.
- // as a work-around, set a flag (dontDrop) if running GTK
- if (gtk) {
- Point loc = arrowButton.toControl(getDisplay().getCursorLocation());
- Point size = arrowButton.getSize();
-
- if ((loc.x >= 0) && (loc.y >= 0) && (loc.x < size.x) && (loc.y < size.y)) {
- dontDrop = true;
- }
- }
-
- dropDown(false);
-
- break;
- }
- }
-
- /**
- * Method for redrawing widget
- */
- public void redraw() {
- super.redraw();
- text.redraw();
- arrowButton.redraw();
-
- if (popup.isVisible()) {
- table.redraw();
- }
- }
-
- /**
- * Selects the item at the given zero-relative index in the receiver's list.
- * If the item at the index was already selected, it remains selected.
- * Indices that are out of range are ignored.
- *
- * @param index
- * the index of the item to select
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public void select(int index) {
- checkWidget();
-
- if (index == -1) {
- table.deselectAll();
- text.setText(Constants.EMPTY);
-
- return;
- }
-
- if ((0 <= index) && (index < table.getItemCount())) {
- if (index != getSelectionIndex()) {
- text.setText(table.getItem(index).getText());
- text.selectAll();
- table.select(index);
- table.showSelection();
- }
- }
- }
-
- /**
- * Method for setting focus in text widget
- */
- public boolean setFocus() {
- checkWidget();
-
- return text.setFocus();
- }
-
- /**
- * Sets the contents of the receiver's text field to the given string.
- * <p>
- * Note: The text field in a <code>Combo</code> is typically only capable of
- * displaying a single line of text. Thus, setting the text to a string
- * containing line breaks or other special characters will probably cause it
- * to display incorrectly.
- * </p>
- *
- * @param string
- * the new text
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- public void setText(String string) {
- checkWidget();
-
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- int index = -1;
-
- for (int i = 0, n = table.getItemCount(); i < n; i++) {
- if (table.getItem(i).getText().equals(string)) {
- index = i;
-
- break;
- }
- }
-
- if (index == -1) {
- table.deselectAll();
- text.setText(string);
-
- return;
- }
-
- text.setText(string);
- text.selectAll();
- table.setSelection(index);
- table.showSelection();
- }
-
- /**
- *
- * @param event
- */
- void textEvent(Event event) {
- switch (event.type) {
- case SWT.FocusIn: {
- handleFocus(SWT.FocusIn);
-
- break;
- }
-
- case SWT.KeyDown: {
- if (event.character == SWT.CR) {
- dropDown(false);
-
- Event e = new Event();
- e.time = event.time;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.DefaultSelection, e);
- }
-
- if (isDisposed()) {
- break;
- }
-
- if ((event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_DOWN)) {
- event.doit = false;
-
- if ((event.stateMask & SWT.ALT) != 0) {
- boolean dropped = isDropped();
- text.selectAll();
-
- if (!dropped) {
- setFocus();
- }
-
- dropDown(!dropped);
-
- break;
- }
-
- int oldIndex = getSelectionIndex();
-
- if (event.keyCode == SWT.ARROW_UP) {
- select(Math.max(oldIndex - 1, 0));
- } else {
- select(Math.min(oldIndex + 1, getItemCount() - 1));
- }
-
- if (oldIndex != getSelectionIndex()) {
- Event e = new Event();
- e.time = event.time;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.Selection, e);
- }
-
- if (isDisposed()) {
- break;
- }
- }
-
- Event e = new Event();
- e.time = event.time;
- e.character = event.character;
- e.keyCode = event.keyCode;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.KeyDown, e);
-
- break;
- }
-
- case SWT.KeyUp: {
- Event e = new Event();
- e.time = event.time;
- e.character = event.character;
- e.keyCode = event.keyCode;
- e.stateMask = event.stateMask;
- notifyListeners(SWT.KeyUp, e);
-
- break;
- }
-
- case SWT.Modify: {
- table.deselectAll();
-
- Event e = new Event();
- e.time = event.time;
- notifyListeners(SWT.Modify, e);
-
- break;
- }
-
- case SWT.MouseDown: {
- if (event.button != 1) {
- return;
- }
-
- if (text.getEditable()) {
- return;
- }
-
- boolean dropped = isDropped();
- text.selectAll();
-
- if (!dropped) {
- setFocus();
- }
-
- dropDown(!dropped);
-
- break;
- }
-
- case SWT.MouseUp: {
- if (event.button != 1) {
- return;
- }
-
- if (text.getEditable()) {
- return;
- }
-
- text.selectAll();
-
- break;
- }
-
- case SWT.Traverse: {
- switch (event.detail) {
- case SWT.TRAVERSE_RETURN:
- case SWT.TRAVERSE_ARROW_PREVIOUS:
- case SWT.TRAVERSE_ARROW_NEXT:
- event.doit = false;
-
- break;
- }
-
- Event e = new Event();
- e.time = event.time;
- e.detail = event.detail;
- e.doit = event.doit;
- e.character = event.character;
- e.keyCode = event.keyCode;
- notifyListeners(SWT.Traverse, e);
- event.doit = e.doit;
- event.detail = e.detail;
-
- break;
- }
- }
- }
-}
Copied: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/StyleAttributes.java (from rev 15064, 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/common/StyleAttributes.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/StyleAttributes.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.eclipse.core.databinding.observable.map.WritableMap;
+
+/**
+ * Class is used to store an array of style attributes and support listeners.
+ */
+public class StyleAttributes {
+
+ private Map<String, String> attributeMap = null;
+ /**
+ * Default constructor.
+ */
+ public StyleAttributes() {
+ this.attributeMap = new WritableMap();
+ }
+
+ /**
+ * Gets attribute map.
+ *
+ * @return map of attributes
+ */
+ public Map<String, String> getAttributeMap() {
+ return attributeMap;
+ }
+
+
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Remove attribute with the given name.
+ *
+ * @param name the name of attribute to be removed
+ */
+ public void removeAttribute(String name) {
+ attributeMap.remove(name);
+ }
+
+ /**
+ * @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) {
+ String value = attributeMap.get(name);
+ return value != null ? value : Constants.EMPTY;
+ }
+
+ /**
+ * @see java.util.HashMap#keySet()
+ */
+ public Set<String> keySet() {
+ return attributeMap.keySet();
+ }
+
+ /**
+ * Clear cache of attributes.
+ */
+ public void clear() {
+ attributeMap.clear();
+ }
+
+ /**
+ *
+ */
+ public void setStyleProperties(Map<String, String> properties){
+ attributeMap.clear();
+ attributeMap.putAll(properties);
+ }
+
+ /**
+ * String representation of style attributes.
+ *
+ * @return style string representation
+ */
+ public String getStyle() {
+ // update newStyle value
+ StringBuffer buf = new StringBuffer();
+ Set<Entry<String, String>> set = entrySet();
+ for (Map.Entry<String, String> me : set) {
+ buf.append(me.getKey() + Constants.COLON + me.getValue() + Constants.SEMICOLON);
+ }
+ return buf.toString();
+ }
+}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Util.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -11,8 +11,8 @@
package org.jboss.tools.jst.jsp.outline.cssdialog.common;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
@@ -29,18 +29,12 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.internal.EditorAreaHelper;
-import org.eclipse.ui.internal.WorkbenchPage;
-import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.texteditor.ITextEditor;
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.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
/**
* Utility class
@@ -100,7 +94,7 @@
* @return true - find, or else - don't find
*/
public static boolean searchInElement(String name,
- HashMap<String, ArrayList<String>> elementMap) {
+ Map<String, ArrayList<String>> elementMap) {
Set<String> set = elementMap.keySet();
@@ -163,7 +157,7 @@
return convertColorRGB(color);
}
} else {
- HashMap<String, String> colorMap = ColorParser.getInstance().getMap();
+ Map<String, String> colorMap = CSSConstants.COLORS;
for (String key : colorMap.keySet()) {
if (colorMap.get(key).equalsIgnoreCase(color)) {
@@ -285,8 +279,8 @@
: Constants.EMPTY)
+ Integer.toHexString(rgb.blue);
colorStr = colorStr.toUpperCase();
- if (ColorParser.getInstance().getMap().get(colorStr) != null) {
- return ColorParser.getInstance().getMap().get(colorStr);
+ if (CSSConstants.COLORS.get(colorStr) != null) {
+ return CSSConstants.COLORS.get(colorStr);
}
return colorStr;
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/BaseListener.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/BaseListener.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/BaseListener.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -7,11 +7,12 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.parsers;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Map;
import org.xml.sax.helpers.DefaultHandler;
@@ -23,26 +24,26 @@
*/
public class BaseListener extends DefaultHandler {
- protected HashMap<String, ArrayList<String>> map;
+ protected Map<String, ArrayList<String>> map;
- /**
- *
- * Constructor for listener
- *
- * @param map
- * Map for writing
- */
- public BaseListener(HashMap<String, ArrayList<String>> map) {
- this.map = map;
- }
+ /**
+ *
+ * Constructor for listener
+ *
+ * @param map
+ * Map for writing
+ */
+ public BaseListener(Map<String, ArrayList<String>> map) {
+ this.map = map;
+ }
- /**
- *
- * Getter for map
- *
- * @return Map
- */
- public HashMap<String, ArrayList<String>> getMap() {
- return map;
- }
+ /**
+ *
+ * Getter for map
+ *
+ * @return Map
+ */
+ public Map<String, ArrayList<String>> getMap() {
+ return map;
+ }
}
\ No newline at end of file
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSElementsParser.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSElementsParser.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSElementsParser.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,61 +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.jst.jsp.outline.cssdialog.parsers;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.xml.sax.SAXException;
-
-public class CSSElementsParser {
-
- private String FILE_NAME = "cssdialog/cssElements.xml";
-
- private BaseListener listener;
-
- private SAXParserFactory fact;
-
- private SAXParser saxParser;
-
- public CSSElementsParser() {
-
- try {
- fact = SAXParserFactory.newInstance();
- saxParser = fact.newSAXParser();
-
- } catch (ParserConfigurationException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void parse() {
- try {
- InputStream is = JspEditorPlugin.getDefault().getBundle().getResource(FILE_NAME).openStream();
- saxParser.parse(is, listener);
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- }
-
- public void setListener(BaseListener listener) {
- this.listener = listener;
- }
-}
\ No newline at end of file
Copied: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSParser.java (from rev 15064, trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ComboParser.java)
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSParser.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/CSSParser.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.parsers;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * @author ezheleznyakov
+ *
+ */
+public class CSSParser {
+
+ private BaseListener listener;
+
+ private SAXParser saxParser;
+
+ public CSSParser() {
+
+ try {
+ saxParser = SAXParserFactory.newInstance().newSAXParser();
+
+ } catch (ParserConfigurationException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } catch (SAXException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void parse(String file) {
+ try {
+ InputStream is = JspEditorPlugin.getDefault().getBundle()
+ .getResource(file).openStream();
+ saxParser.parse(is, listener);
+ } catch (SAXException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } catch (IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+
+ public void setListener(BaseListener listener) {
+ this.listener = listener;
+ }
+}
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ColorParser.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ColorParser.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ColorParser.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,110 +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.jst.jsp.outline.cssdialog.parsers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- *
- * Parser for parse colors elements
- *
- * --==Singleton==--
- *
- * @author Evgeny Zheleznyakov
- *
- */
-public class ColorParser {
-
- private SAXParserFactory fact;
-
- private SAXParser saxParser;
-
- private HashMap<String, String> map;
-
- private static ColorParser colorParser = null;
-
- private static final String NODE_NAME_COLOR = "color"; //$NON-NLS-1$
-
- private static final String NODE_ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
-
- private static final String NODE_ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
-
- private static final String FILE_NAME = "cssdialog/colors.xml"; //$NON-NLS-1$
-
- public static ColorParser getInstance() {
- return ColorParserHolder.INSTANCE;
- }
- /**
- * Constructor for Color parser
- */
- private ColorParser() {
-
- try {
- fact = SAXParserFactory.newInstance();
- saxParser = fact.newSAXParser();
- } catch (ParserConfigurationException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
-
- parse();
- }
-
- /**
- * Parse the content of the file specified as XML using the specified
- */
- private void parse() {
-
- try {
- InputStream is = JspEditorPlugin.getDefault().getBundle().getResource(FILE_NAME).openStream();
- saxParser.parse(is, new DefaultHandler()
- {
- public void startElement(String uri, String localName, String nodeName,
- Attributes attrs) {
-
- if (nodeName.trim().equalsIgnoreCase(NODE_NAME_COLOR)) {
- getMap().put(attrs.getValue(NODE_ATTRIBUTE_NAME).trim().toUpperCase(),
- attrs.getValue(NODE_ATTRIBUTE_VALUE).trim());
- }
- }
- });
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
- /**
- * @return the map
- */
- public HashMap<String, String> getMap() {
- if(map==null) {
- map = new HashMap<String, String>();
- }
- return map;
- }
-
- private static class ColorParserHolder {
- private static final ColorParser INSTANCE = new ColorParser();
- }
-}
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ComboParser.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ComboParser.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ComboParser.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,62 +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.jst.jsp.outline.cssdialog.parsers;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.xml.sax.SAXException;
-
-/**
- *
- * @author ezheleznyakov
- *
- */
-public class ComboParser {
-
- private String FILE_NAME = "cssdialog/cssElementsWithCombo.xml";
-
- private BaseListener listener;
-
- private SAXParser saxParser;
-
- public ComboParser() {
-
- try {
- saxParser = SAXParserFactory.newInstance().newSAXParser();
-
- } catch (ParserConfigurationException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void parse() {
- try {
- InputStream is = JspEditorPlugin.getDefault().getBundle().getResource(FILE_NAME).openStream();
- saxParser.parse(is, listener);
- } catch (SAXException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch (IOException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- }
-
- public void setListener(BaseListener listener) {
- this.listener = listener;
- }
-}
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/IListener.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/IListener.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/IListener.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,32 +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.jst.jsp.outline.cssdialog.parsers;
-
-/**
- *
- * Interface for listenrs
- *
- * @author Evgeny Zheleznyakov
- *
- */
-public interface IListener {
-
- /**
- *
- * Invoke when getting new pair name, value
- *
- * @param name
- * Name css attribute
- * @param value
- * Value css attribute
- */
- public void nextElement(String name, String value);
-}
\ No newline at end of file
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/Parser.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/Parser.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/Parser.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,92 +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.jst.jsp.outline.cssdialog.parsers;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.StringTokenizer;
-
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
-
-/**
- *
- * Parser for input style string
- *
- * @author Evgeny Zheleznyakov
- *
- */
-public class Parser {
-
- private static String SEPARATE_SYMBOLS = ":;";
-
- private ArrayList<IListener> list;
-
- private HashMap<String, ArrayList<String>> elementsMap;
-
- public Parser(HashMap<String, ArrayList<String>> elementsMap) {
- this.elementsMap = elementsMap;
- list = new ArrayList<IListener>();
- }
-
- public void parse(String str) {
-
- if (str == null)
- return;
- if (str.trim().equals(Constants.EMPTY))
- return;
-
- StringTokenizer st = new StringTokenizer(str, SEPARATE_SYMBOLS);
-
- while (st.hasMoreTokens()) {
- String name = null;
- String value = null;
-
- name = st.nextToken().trim().toLowerCase();
- if (!Util.searchInElement(name, elementsMap))
- continue;
- if (st.hasMoreTokens())
- value = st.nextToken().trim();
- else
- continue;
-
- if (name.equals(Constants.EMPTY)
- || value.equals(Constants.EMPTY))
- continue;
-
- for (IListener listener : list) {
- listener.nextElement(name, value);
- }
- }
- }
-
- /**
- *
- * Add listener for parser
- *
- * @param listener
- * Listener
- */
- public void addListener(IListener listener) {
- list.add(listener);
- }
-
- /**
- *
- * Remove listener from parser
- *
- * @param listener
- * Listener
- */
- public void removeListener(IListener listener) {
- list.remove(listener);
- }
-}
\ No newline at end of file
Deleted: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ParserListener.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ParserListener.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/parsers/ParserListener.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,37 +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.jst.jsp.outline.cssdialog.parsers;
-
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-
-/**
- *
- * ParserListener for input style string
- *
- * @author Evgeny Zheleznyakov
- *
- */
-public class ParserListener implements IListener {
-
- private StyleAttributes attributes;
-
- public ParserListener(StyleAttributes styleAttributes) {
- this.attributes = styleAttributes;
- }
-
- public void nextElement(String name, String value) {
- attributes.addAttribute(name, value);
- }
-
- public StyleAttributes getStyleAttributes() {
- return attributes;
- }
-}
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/BaseTabControl.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/BaseTabControl.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/BaseTabControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -1,95 +1,512 @@
/*******************************************************************************
- * 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
- ******************************************************************************/
+ * 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.tabs;
-import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.observable.Observables;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-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.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
+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;
+import org.jboss.tools.jst.jsp.outline.cssdialog.ImageSelectionDialog;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSStyleValueValidator;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.CSSTreeItemWidgetValueProperty;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.CSSWidget;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.CSSWidgetValueProperty;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.ImageCombo;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.SizeCombo;
+import org.jboss.tools.jst.jsp.outline.cssdialog.widgets.SizeText;
/**
- * This is base tab control component that should be re-implemented by successor.
- *
+ * This is base tab control component that should be re-implemented by
+ * successor.
+ *
* @author Igor Zhukov
*/
-public abstract class BaseTabControl extends Composite {
+public abstract class BaseTabControl extends Composite implements
+ ICSSTabControl {
- protected StyleAttributes styleAttributes = null;
- protected boolean updateDataFromStyleAttributes = false;
+ private StyleAttributes styleAttributes = null;
- private ArrayList<ManualChangeStyleListener> listeners = new ArrayList<ManualChangeStyleListener>();
+ private DataBindingContext bindingContext;
+ final static protected int NAME_ATTRIBUTE_COLUMN = 0;
+ final static protected int VALUE_ATTRIBUTE_COLUMN = 1;
+ final static protected int COMPOSITE_NUM_COLUMNS = 2;
+
+ private static final int COLUMNS = 3;
+
/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- *
- * @param parent a widget which will be the parent of the new instance (cannot be null)
- * @param style the style of widget to construct
+ * Constructs a new instance of this class given its parent and a style
+ * value describing its behavior and appearance.
+ *
+ * @param parent
+ * a widget which will be the parent of the new instance (cannot
+ * be null)
+ * @param style
+ * the style of widget to construct
*/
- public BaseTabControl(Composite parent, int style) {
+ public BaseTabControl(DataBindingContext bindingContext,
+ StyleAttributes styleAttributes, Composite parent, int style) {
super(parent, style);
+ setLayout(new GridLayout(COLUMNS, false));
+ this.styleAttributes = styleAttributes;
+ this.bindingContext = bindingContext;
}
- /**
- * Sets updateDataFromStyleAttributes parameter.
- *
- * @return the updateDataFromStyleAttributes value
- */
- public boolean isUpdateDataFromStyleAttributes() {
- return updateDataFromStyleAttributes;
- }
-
- /**
+ /**
* @return the styleAttributes
*/
public StyleAttributes getStyleAttributes() {
return styleAttributes;
}
- /**
- * Add ManualChangeStyleListener object.
- *
- * @param listener ManualChangeStyleListener object to be added
- */
- public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
- listeners.add(listener);
- }
+ public void setStyleAttributes(StyleAttributes styleAttributes) {
+ this.styleAttributes = styleAttributes;
+ }
- /**
- * Gets an array of ChangeStyleListener object.
- *
- * @return an array of ChangeStyleListener object
- */
- public ManualChangeStyleListener[] getManualChangeStyleListeners() {
- return listeners.toArray(new ManualChangeStyleListener[listeners.size()]);
- }
+ public DataBindingContext getBindingContext() {
+ return this.bindingContext;
+ }
- /**
- * Remove ManualChangeStyleListener object passed by parameter.
- *
- * @param listener ManualChangeStyleListener object to be removed
- */
- public void removeManualChangeStyleListener(ManualChangeStyleListener listener) {
- listeners.remove(listener);
- }
+ public void setBindingContext(DataBindingContext bindingContext) {
+ this.bindingContext = bindingContext;
+ }
- /**
- * Method is used to notify all subscribed listeners about any changes within style attribute map.
- */
- public void notifyListeners() {
- ChangeStyleEvent event = new ChangeStyleEvent(this);
- for (ManualChangeStyleListener listener : listeners) {
- listener.styleChanged(event);
- }
- }
+ /**
+ *
+ * @param parent
+ * @param label
+ */
+ protected Label addLabel(Composite parent, String label) {
+ Label labelControl = new Label(parent, SWT.LEFT);
+ labelControl.setLayoutData(new GridData(GridData.END, GridData.CENTER,
+ false, false));
+ labelControl.setText(label);
+ return labelControl;
+ }
+
+ /**
+ *
+ * @param parent
+ * @param label
+ */
+ protected Label addSectionLabel(Composite parent, String label) {
+
+ Label labelControl = new Label(parent, SWT.NONE);
+ labelControl.setLayoutData(new GridData(GridData.BEGINNING,
+ GridData.CENTER, false, false, 3, 1));
+ labelControl.setFont(JFaceResources.getFontRegistry().get(
+ JFaceResources.BANNER_FONT));
+ labelControl.setText(label);
+
+ return labelControl;
+ }
+
+ /**
+ *
+ * @param parent
+ * @param attribute
+ */
+ protected Composite addFontComposite(Composite parent, String attribute) {
+
+ Composite wrapper = createWrapperComposite(parent);
+
+ final Text fontFamilyText = new Text(wrapper, SWT.BORDER | SWT.SINGLE);
+ fontFamilyText.setLayoutData(new GridData(GridData.FILL,
+ GridData.CENTER, true, false));
+
+ Button button = createButton(wrapper,
+ Constants.IMAGE_FONTLARGE_FILE_LOCATION,
+ JstUIMessages.FONT_FAMILY_TIP);
+ 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());
+ }
+ }
+ });
+
+ bind(fontFamilyText, attribute);
+
+ return wrapper;
+
+ }
+
+ /**
+ *
+ * @param parent
+ * @param attribute
+ */
+ protected Composite addColorComposite(Composite parent, String attribute) {
+
+ Composite wrapper = createWrapperComposite(parent);
+
+ final ImageCombo colorCombo = new ImageCombo(wrapper, SWT.BORDER);
+
+ colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false));
+
+ for (Map.Entry<String, String> me : CSSConstants.COLORS.entrySet()) {
+ RGB rgb = Util.getColor(me.getKey());
+ colorCombo.add(me.getValue(), rgb);
+ }
+
+ Button button = createButton(wrapper,
+ Constants.IMAGE_COLORLARGE_FILE_LOCATION,
+ JstUIMessages.COLOR_TIP);
+
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ ColorDialog dlg = new ColorDialog(getShell());
+
+ dlg
+ .setRGB((Util.getColor((colorCombo.getText().trim())) == null) ? Constants.RGB_BLACK
+ : Util.getColor((colorCombo.getText().trim())));
+ dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
+
+ RGB rgb = dlg.open();
+ if (rgb != null) {
+ String colorStr = Util.createColorString(rgb);
+ colorCombo.setText(colorStr);
+ }
+ }
+ });
+
+ bind(colorCombo, attribute);
+
+ return wrapper;
+ }
+
+ protected Composite addImageFileComposite(Composite parent,
+ List<String> comboValues, final String attribute) {
+
+ Composite wrapper = createWrapperComposite(parent);
+
+ final Combo combo = new Combo(wrapper, SWT.BORDER);
+ combo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
+ false));
+
+ for (String string : comboValues) {
+ combo.add(string);
+ }
+
+ Button button = createButton(wrapper,
+ Constants.IMAGE_FOLDERLARGE_FILE_LOCATION,
+ JstUIMessages.BACKGROUND_IMAGE);
+
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ IAdaptable project = Util.getCurrentProject();
+ ImageSelectionDialog dialog = new ImageSelectionDialog(
+ getShell(), new WorkbenchLabelProvider(),
+ new WorkbenchContentProvider());
+ dialog.setTitle(JstUIMessages.IMAGE_DIALOG_TITLE);
+ dialog.setMessage(JstUIMessages.IMAGE_DIALOG_MESSAGE);
+ dialog
+ .setEmptyListMessage(JstUIMessages.IMAGE_DIALOG_EMPTY_MESSAGE);
+ dialog.setAllowMultiple(false);
+ dialog.setInput(project);
+
+ if (dialog.open() == ImageSelectionDialog.OK) {
+ IFile file = (IFile) dialog.getFirstResult();
+ String value = file.getFullPath().toString();
+ combo.add(value);
+ combo.setText(value);
+ }
+ }
+ });
+
+ bind(combo, attribute, new UpdateValueStrategy() {
+
+ @Override
+ protected IStatus doSet(IObservableValue observableValue,
+ Object value) {
+
+ List<String> values = CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(attribute);
+
+ if ((values != null) && !values.contains(value))
+ value = adjustBackgroundURL((String) value);
+
+ return super.doSet(observableValue, value);
+ }
+ }, null);
+
+ return wrapper;
+ }
+
+ protected Composite createWrapperComposite(Composite parent) {
+ Composite wrapper = new Composite(parent, SWT.None);
+ GridLayout layout = new GridLayout(COMPOSITE_NUM_COLUMNS, false);
+
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ wrapper.setLayout(layout);
+ wrapper.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false, 2, 1));
+ return wrapper;
+ }
+
+ /**
+ *
+ * @param parent
+ * @param comboValues
+ * @param attribute
+ */
+ protected Composite addSizeCombo(Composite parent,
+ List<String> comboValues, String attribute) {
+
+ SizeCombo combo = new SizeCombo(parent, comboValues);
+
+ bind(combo, attribute);
+
+ return combo;
+
+ }
+
+ /**
+ *
+ * @param parent
+ * @param comboValues
+ * @param attribute
+ */
+ protected Composite addSizeText(Composite parent, String attribute) {
+
+ SizeText combo = new SizeText(parent);
+
+ bind(combo, attribute);
+
+ return combo;
+
+ }
+
+ /**
+ *
+ * @param parent
+ * @param attribute
+ */
+ protected Text addText(Composite parent, String attribute) {
+
+ GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true,
+ false);
+ gridData.horizontalSpan = 2;
+
+ Text text = new Text(parent, SWT.BORDER);
+ text.setLayoutData(gridData);
+
+ bind(text, attribute);
+
+ return text;
+
+ }
+
+ /**
+ *
+ * @param parent
+ * @param comboValues
+ * @param attribute
+ */
+ protected Combo addCombo(Composite parent, List<String> comboValues,
+ String attribute) {
+
+ GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true,
+ false);
+ gridData.horizontalSpan = 2;
+
+ Combo combo = new Combo(parent, SWT.BORDER);
+ combo.setLayoutData(gridData);
+
+ for (String str : comboValues) {
+ combo.add(str);
+ }
+
+ bind(combo, attribute);
+
+ return combo;
+ }
+
+ protected TreeItem createBindedTreeItem(TreeItem parent, String attribute) {
+
+ TreeItem item = new TreeItem(parent, SWT.NONE);
+ item.setText(NAME_ATTRIBUTE_COLUMN, attribute);
+ bind(item, attribute);
+
+ return item;
+ }
+
+ protected TreeItem createTreeItem(Tree parent, String text) {
+
+ TreeItem item = new TreeItem(parent, SWT.NONE);
+ item.setText(text);
+
+ return item;
+ }
+
+ /**
+ *
+ * @param parent
+ * @param imageFile
+ * @param tooltip
+ * @return
+ */
+ private Button createButton(Composite parent, String imageFile,
+ String tooltip) {
+ Button button = new Button(parent, SWT.PUSH);
+ button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false,
+ false));
+ button.setToolTipText(tooltip);
+
+ button.setImage(JspEditorPlugin.getImageDescriptor(imageFile)
+ .createImage());
+ button.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Button button = (Button) e.getSource();
+ button.getImage().dispose();
+ }
+ });
+
+ return button;
+ }
+
+ /**
+ * create control by css property
+ *
+ * @param parent
+ * @param key
+ * @return
+ */
+ protected Control createControl(Composite parent, String property) {
+
+ Control control = null;
+ if (CSSConstants.CSS_STYLE_VALUES_MAP.keySet().contains(property)) {
+
+ if (property.indexOf(CSSConstants.COLOR) != Constants.DONT_CONTAIN) {
+ control = addColorComposite(parent, property);
+ } else if (Constants.elemFolder.contains(property)) {
+ control = addImageFileComposite(parent,
+ CSSConstants.CSS_STYLE_VALUES_MAP.get(property),
+ property);
+ } else if (Constants.extElem.contains(property)) {
+ control = addSizeCombo(parent,
+ CSSConstants.CSS_STYLE_VALUES_MAP.get(property),
+ property);
+ } else {
+ control = addCombo(parent, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(property), property);
+ }
+
+ } else {
+ if (property.equalsIgnoreCase(CSSConstants.FONT_FAMILY)) {
+ control = addFontComposite(parent, property);
+ } else if (Constants.extElem.contains(property)) {
+ control = addSizeText(parent, property);
+ } else {
+ control = addText(parent, property);
+ }
+ }
+ return control;
+ }
+
+ private static String adjustBackgroundURL(String backgroundURL) {
+ if ((backgroundURL != null && !backgroundURL.trim().equals(
+ Constants.EMPTY))
+ && (backgroundURL.matches("(url)\\(.*\\)") == false)) { //$NON-NLS-1$
+ return "url(" + backgroundURL + ")"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ return backgroundURL;
+ }
+
+ private IObservableValue createAttributeObservableValue(String attributeName) {
+ return Observables.observeMapEntry(
+ (IObservableMap) getStyleAttributes().getAttributeMap(),
+ attributeName, String.class);
+ }
+
+ private void bind(Widget widget, String attribute) {
+ bind(widget, attribute, null, null);
+ }
+
+ private void bind(Widget widget, String attribute,
+ UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) {
+
+ IObservableValue attributeValue = createAttributeObservableValue(attribute);
+
+ if (targetToModel == null) {
+ targetToModel = new UpdateValueStrategy();
+ }
+
+ targetToModel.setBeforeSetValidator(CSSStyleValueValidator
+ .getInstance());
+
+ if (widget instanceof Text) {
+ getBindingContext().bindValue(
+ SWTObservables.observeText((Text) widget, SWT.Modify),
+ attributeValue, targetToModel, modelToTarget);
+ } else if ((widget instanceof Combo)) {
+ getBindingContext().bindValue(SWTObservables.observeText(widget),
+ attributeValue, targetToModel, modelToTarget);
+ } else if (widget instanceof CSSWidget) {
+ getBindingContext().bindValue(
+ new CSSWidgetValueProperty().observe(widget),
+ attributeValue, targetToModel, modelToTarget);
+ } else if (widget instanceof TreeItem) {
+ getBindingContext().bindValue(
+ new CSSTreeItemWidgetValueProperty(VALUE_ATTRIBUTE_COLUMN)
+ .observe(widget), attributeValue, targetToModel,
+ modelToTarget);
+ }
+
+ }
+
+ public void tabSelected() {
+
+ }
+
}
\ No newline at end of file
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/ICSSTabControl.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/ICSSTabControl.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/ICSSTabControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,6 @@
+package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
+
+public interface ICSSTabControl {
+
+ public void tabSelected();
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/ICSSTabControl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBackgroundControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,223 +10,52 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-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.ImageSelectionDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
-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.AttributeModifyListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
-
/**
* Class for creating control in Background tab
- *
+ *
* @author Igor Zhukov (izhukov(a)exadel.com)
*/
public class TabBackgroundControl extends BaseTabControl {
- private static final int numColumns = 3;
- private ImageCombo colorCombo;
- private Combo backgroundImageCombo;
- private Combo backgroundRepeatCombo;
- /**
- * Constructor for creating controls
- *
- * @param composite Composite element
- * @param comboMap
- * @param styleAttributes the StyleAttributes object
- */
- public TabBackgroundControl(final Composite composite, HashMap<String, ArrayList<String>> comboMap,
- final StyleAttributes styleAttributes) {
- super(composite, SWT.NONE);
- this.styleAttributes = styleAttributes;
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = numColumns;
- setLayout(gridLayout);
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * Composite element
+ * @param comboMap
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabBackgroundControl(final Composite composite,
+ final StyleAttributes styleAttributes,
+ DataBindingContext bindingContext) {
+ super(bindingContext, styleAttributes, composite, SWT.NONE);
- // =====================================================================================
- // Add BACKGROUND_COLOR element
- // =====================================================================================
- Label label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.BACKGROUND_COLOR);
+ // Add BACKGROUND_COLOR element
+ addLabel(this, JstUIMessages.BACKGROUND_COLOR);
+ addColorComposite(this, CSSConstants.BACKGROUND_COLOR);
- colorCombo = new ImageCombo(this, SWT.BORDER);
- colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- colorCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.BACKGROUND_COLOR,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- Set<Entry<String, String>> set = ColorParser.getInstance().getMap().entrySet();
- for (Map.Entry<String, String> me : set) {
- RGB rgb = Util.getColor(me.getKey());
- colorCombo.add(me.getValue(), rgb);
- }
+ // Add BACKGROUND_IMAGE element
+ addLabel(this, JstUIMessages.BACKGROUND_IMAGE);
+ addImageFileComposite(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.BACKGROUND_IMAGE),
+ CSSConstants.BACKGROUND_IMAGE);
- Button button = new Button(this, SWT.PUSH);
- button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- button.setToolTipText(JstUIMessages.BACKGROUND_COLOR_TIP);
+ // Add BACKGROUND_REPEAT element
+ addLabel(this, JstUIMessages.BACKGROUND_REPEAT);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.BACKGROUND_REPEAT),
+ CSSConstants.BACKGROUND_REPEAT);
- ImageDescriptor colorDesc = JspEditorPlugin.getImageDescriptor(Constants.IMAGE_COLORLARGE_FILE_LOCATION);
- Image im = colorDesc.createImage();
- button.setImage(im);
- button.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- ColorDialog dlg = new ColorDialog(getShell());
+ }
- dlg.setRGB((Util.getColor((colorCombo.getText().trim())) == null) ? new RGB(0, 0, 0)
- : Util.getColor((colorCombo.getText().trim())));
- dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
-
- RGB rgb = dlg.open();
- if (rgb != null) {
- String colorStr = Util.createColorString(rgb);
- colorCombo.setText(colorStr);
- }
- }
- });
-
- // =====================================================================================
- // Add BACKGROUND_IMAGE element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- 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 AttributeModifyListener(this, CSSConstants.BACKGROUND_IMAGE,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD) {
- @Override
- protected String adjustAttributeValue(String attribute) {
- return adjustBackgroundURL(attribute);
- }
- });
-
- button = new Button(this, SWT.PUSH);
- button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- button.setToolTipText(JstUIMessages.BACKGROUND_IMAGE);
-
- ImageDescriptor imageDesc = JspEditorPlugin.getImageDescriptor(Constants.IMAGE_FOLDERLARGE_FILE_LOCATION);
- Image image = imageDesc.createImage();
- button.setImage(image);
- button.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- IAdaptable project = Util.getCurrentProject();
- ImageSelectionDialog dialog = new ImageSelectionDialog(getShell(),
- new WorkbenchLabelProvider(), new WorkbenchContentProvider());
- dialog.setTitle(JstUIMessages.IMAGE_DIALOG_TITLE);
- dialog.setMessage(JstUIMessages.IMAGE_DIALOG_MESSAGE);
- dialog.setEmptyListMessage(JstUIMessages.IMAGE_DIALOG_EMPTY_MESSAGE);
- dialog.setAllowMultiple(false);
- dialog.setInput(project);
-
- if (dialog.open() == ImageSelectionDialog.OK) {
- IFile file = (IFile) dialog.getFirstResult();
- String value = file.getFullPath().toString();
- backgroundImageCombo.add(value);
- value = adjustBackgroundURL(value);
- backgroundImageCombo.setText(value);
- }
- }
- });
-
- // =====================================================================================
- // Add BACKGROUND_REPEAT element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.BACKGROUND_REPEAT);
-
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- backgroundRepeatCombo = new Combo(this, SWT.BORDER);
- backgroundRepeatCombo.setLayoutData(gridData);
- backgroundRepeatCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.BACKGROUND_REPEAT,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- ArrayList<String> list = comboMap.get(CSSConstants.BACKGROUND_REPEAT);
- for (String str : list) {
- backgroundRepeatCombo.add(str);
- }
- }
-
- /**
- * Method for get data in controls (if param equal true ), or set data (if
- * param equal false).
- *
- * @param param
- */
- public void updateData(boolean param) {
- updateDataFromStyleAttributes = true;
- // set BACKGROUND_COLOR attribute
- String tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_COLOR);
- if (!tmp.equals(colorCombo.getText())) {
- colorCombo.setText(tmp);
- }
- // set BACKGROUND_IMAGE attribute
- tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_IMAGE);
- if (!tmp.equals(backgroundImageCombo.getText())) {
- backgroundImageCombo.setText(tmp);
- }
- // set BACKGROUND_REPEAT attribute
- tmp = styleAttributes.getAttribute(CSSConstants.BACKGROUND_REPEAT);
- if (!tmp.equals(backgroundRepeatCombo.getText())) {
- backgroundRepeatCombo.setText(tmp);
- }
- updateDataFromStyleAttributes = false;
- }
-
- // Fix for JBIDE-3084
- // in css background image should always be wrapped into url(*);
- private static String adjustBackgroundURL(String backgroundURL) {
- if ((backgroundURL != null && !backgroundURL.trim().equals(Constants.EMPTY))
- && (backgroundURL.matches("(url)\\(.*\\)") == false)) { //$NON-NLS-1$
- return "url(" + backgroundURL + ")"; //$NON-NLS-1$//$NON-NLS-2$
- }
-
- return backgroundURL;
- }
}
\ 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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabBoxesControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,337 +10,73 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
-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.AttributeModifyListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
/**
* Class for creating control in Boxes tab
- *
+ *
* @author Igor Zhukov (izhukov(a)exadel.com)
*/
public class TabBoxesControl extends BaseTabControl {
- private static final int numColumns = 3;
- private Combo extWidthCombo;
- private Combo extHeightCombo;
- private Combo borderWidthCombo;
- private Combo extPaddingCombo;
- private Combo extBorderWidthCombo;
- private Combo borderStyleCombo;
- private Combo extMarginCombo;
- private ImageCombo borderColorCombo;
- private Text widthText;
- private Text heightText;
- private Text marginText;
- private Text paddingText;
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * Composite element
+ * @param comboMap
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabBoxesControl(final Composite composite,
+ final StyleAttributes styleAttributes,
+ DataBindingContext bindingContext) {
+ super(bindingContext, styleAttributes, composite, SWT.NONE);
- /**
- * Constructor for creating controls
- *
- * @param composite Composite element
- * @param comboMap
- * @param styleAttributes the StyleAttributes object
- */
- public TabBoxesControl(final Composite composite, final HashMap<String, ArrayList<String>> comboMap,
- final StyleAttributes styleAttributes) {
- super(composite, SWT.NONE);
- this.styleAttributes = styleAttributes;
+ // Dimension section
+ addSectionLabel(this, JstUIMessages.DIMENSION_TITLE);
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = numColumns;
- setLayout(gridLayout);
+ // Add WIDTH element
+ addLabel(this, JstUIMessages.WIDTH);
+ addSizeText(this, CSSConstants.WIDTH);
- Label label = new Label(this, SWT.NONE);
- label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
- label.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT));
- label.setText(JstUIMessages.DIMENSION_TITLE);
+ // Add HEIGHT element
+ addLabel(this, JstUIMessages.HEIGHT);
+ addSizeText(this, CSSConstants.HEIGHT);
- // =====================================================================================
- // Add WIDTH element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.WIDTH);
+ // border section
+ addSectionLabel(this, JstUIMessages.BORDER_TITLE);
- 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 AttributeModifyListener(this, extWidthCombo, CSSConstants.WIDTH,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- extWidthCombo.addModifyListener(new AttributeModifyListener(this, widthText, CSSConstants.WIDTH,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extWidthCombo.add(Constants.extSizes[i]);
- }
+ // Add BORDER_STYLE element
+ addLabel(this, JstUIMessages.BORDER_STYLE);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.BORDER_STYLE), CSSConstants.BORDER_STYLE);
- // =====================================================================================
- // Add HEIGHT element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.HEIGHT);
+ // Add BORDER_COLOR element
+ addLabel(this, JstUIMessages.BORDER_COLOR);
+ addColorComposite(this, CSSConstants.BORDER_COLOR);
- 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 AttributeModifyListener(this, extHeightCombo, CSSConstants.HEIGHT,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- extHeightCombo.addModifyListener(new AttributeModifyListener(this, heightText, CSSConstants.HEIGHT,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extHeightCombo.add(Constants.extSizes[i]);
- }
+ // Add BORDER_WIDTH element
+ addLabel(this, JstUIMessages.BORDER_WIDTH);
+ addSizeCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.BORDER_WIDTH), CSSConstants.BORDER_WIDTH);
- label = new Label(this, SWT.NONE);
- label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
- label.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT));
- label.setText(JstUIMessages.BORDER_TITLE);
+ // margin/padding section
+ addSectionLabel(this, JstUIMessages.MARGIN_PADDING_TITLE);
- // =====================================================================================
- // Add BORDER_STYLE element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.BORDER_STYLE);
+ // Add MARGIN element
+ addLabel(this, JstUIMessages.MARGIN);
+ addSizeText(this, CSSConstants.MARGIN);
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- borderStyleCombo = new Combo(this, SWT.BORDER);
- borderStyleCombo.setLayoutData(gridData);
- borderStyleCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.BORDER_STYLE,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- ArrayList<String> list = comboMap.get(CSSConstants.BORDER_STYLE);
- for (String str : list) {
- borderStyleCombo.add(str);
- }
+ // Add PADDING element
+ addLabel(this, JstUIMessages.PADDING);
+ addSizeText(this, CSSConstants.PADDING);
- // =====================================================================================
- // Add BORDER_COLOR element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.BORDER_COLOR);
+ }
- Composite tmpComposite = getCompositeElement();
- borderColorCombo = new ImageCombo(tmpComposite, SWT.BORDER);
- borderColorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- borderColorCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.BORDER_COLOR,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- Set<Entry<String, String>> set = ColorParser.getInstance().getMap().entrySet();
- for (Map.Entry<String, String> me : set) {
- RGB rgb = Util.getColor(me.getKey());
- borderColorCombo.add(me.getValue(), rgb);
- }
-
- final Button button = new Button(tmpComposite, SWT.PUSH);
- button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- button.setToolTipText(JstUIMessages.BORDER_COLOR_TIP);
-
- ImageDescriptor colorDesc = JspEditorPlugin.getImageDescriptor(Constants.IMAGE_COLORLARGE_FILE_LOCATION);
- Image im = colorDesc.createImage();
- button.setImage(im);
- button.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- ColorDialog dlg = new ColorDialog(getShell());
- 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);
- borderColorCombo.setText(colorStr);
- }
- }
- });
-
- // =====================================================================================
- // Add BORDER_WIDTH element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.BORDER_WIDTH);
-
- borderWidthCombo = new Combo(this, SWT.BORDER | SWT.SINGLE);
- borderWidthCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- 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));
- borderWidthCombo.addModifyListener(new AttributeModifyListener(this, extBorderWidthCombo,
- CSSConstants.BORDER_WIDTH, AttributeModifyListener.MODIFY_COMBO_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- extBorderWidthCombo.addModifyListener(new AttributeModifyListener(this, borderWidthCombo,
- CSSConstants.BORDER_WIDTH, AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extBorderWidthCombo.add(Constants.extSizes[i]);
- }
-
- label = new Label(this, SWT.NONE);
- label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1));
- label.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT));
- label.setText(JstUIMessages.MARGIN_PADDING_TITLE);
-
- // =====================================================================================
- // Add MARGIN element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.MARGIN);
-
- 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 AttributeModifyListener(this, extMarginCombo, CSSConstants.MARGIN,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- extMarginCombo.addModifyListener(new AttributeModifyListener(this, marginText, CSSConstants.MARGIN,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extMarginCombo.add(Constants.extSizes[i]);
- }
-
- // =====================================================================================
- // Add PADDING element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.PADDING);
-
- 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 AttributeModifyListener(this, extPaddingCombo, CSSConstants.PADDING,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- extPaddingCombo.addModifyListener(new AttributeModifyListener(this, paddingText, CSSConstants.PADDING,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extPaddingCombo.add(Constants.extSizes[i]);
- }
- }
-
- /**
- * Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
- */
- private Composite getCompositeElement() {
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- GridLayout gridLayoutTmp = new GridLayout(2, false);
- gridLayoutTmp.marginHeight = 0;
- gridLayoutTmp.marginWidth = 0;
- Composite classComposite = new Composite(this, SWT.NONE);
- classComposite.setLayoutData(gridData);
- classComposite.setLayout(gridLayoutTmp);
-
- return classComposite;
- }
-
- /**
- * 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;
- // set WIDTH and EXTENSION_WIDTH attributes
- String tmp = styleAttributes.getAttribute(CSSConstants.WIDTH);
- String[] str = Util.convertExtString(tmp);
- if (!str[0].equals(widthText.getText())) {
- widthText.setText(str[0]);
- if (extWidthCombo.indexOf(str[1]) != -1) {
- extWidthCombo.setText(str[1]);
- extWidthCombo.select(extWidthCombo.indexOf(str[1]));
- }
- }
- // set HEIGHT and EXTENSION_HEIGHT attributes
- tmp = styleAttributes.getAttribute(CSSConstants.HEIGHT);
- str = Util.convertExtString(tmp);
- if (!str[0].equals(heightText.getText())) {
- heightText.setText(str[0]);
- if (extHeightCombo.indexOf(str[1]) != -1) {
- extHeightCombo.setText(str[1]);
- extHeightCombo.select(extHeightCombo.indexOf(str[1]));
- }
- }
- // set BORDER_STYLE attribute
- tmp = styleAttributes.getAttribute(CSSConstants.BORDER_STYLE);
- if (!tmp.equals(borderStyleCombo.getText())) {
- borderStyleCombo.setText(tmp);
- }
- // set BORDER_COLOR attribute
- tmp = styleAttributes.getAttribute(CSSConstants.BORDER_COLOR);
- if (!tmp.equals(borderColorCombo.getText())) {
- borderColorCombo.setText(tmp);
- }
- // set BORDER_WIDTH and EXTENSION_BORDER_WIDTH attributes
- tmp = styleAttributes.getAttribute(CSSConstants.BORDER_WIDTH);
- str = Util.convertExtString(tmp);
- if (!str[0].equals(borderWidthCombo.getText())) {
- borderWidthCombo.setText(str[0]);
- if (extBorderWidthCombo.indexOf(str[1]) != -1) {
- extBorderWidthCombo.setText(str[1]);
- extBorderWidthCombo.select(extBorderWidthCombo.indexOf(str[1]));
- }
- }
- // set MARGIN and EXTENSION_MARGIN attributes
- tmp = styleAttributes.getAttribute(CSSConstants.MARGIN);
- str = Util.convertExtString(tmp);
- if (!str[0].equals(marginText.getText())) {
- marginText.setText(str[0]);
- if (extMarginCombo.indexOf(str[1]) != -1) {
- extMarginCombo.setText(str[1]);
- extMarginCombo.select(extMarginCombo.indexOf(str[1]));
- }
- }
- // set PADDING and EXTENSION_PADDING attributes
- tmp = styleAttributes.getAttribute(CSSConstants.PADDING);
- str = Util.convertExtString(tmp);
- if (!str[0].equals(paddingText.getText())) {
- paddingText.setText(str[0]);
- if (extPaddingCombo.indexOf(str[1]) != -1) {
- extPaddingCombo.setText(str[1]);
- extPaddingCombo.select(extPaddingCombo.indexOf(str[1]));
- }
- }
- updateDataFromStyleAttributes = false;
- }
}
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPreviewControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -15,52 +15,55 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSModel;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.ICSSDialogModel;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
/**
* Class for creating Preview sheet tab
*/
-public class TabPreviewControl extends Composite {
+public class TabPreviewControl extends Composite implements ICSSTabControl {
- /** Editor in which we open visual page. */
- SourceViewer viewer = null;
- private CSSModel cssModel = null;
+ /** Editor in which we open visual page. */
+ SourceViewer viewer = null;
+ private ICSSDialogModel cssModel = null;
+ private String selector = null;
+ private StyleAttributes styleAttributes;
- /**
- * Constructor for creating controls
- *
- * @param composite The parent composite for tab
- * @param styleAttributes the StyleAttributes object
- */
- public TabPreviewControl(Composite tabFolder, StyleAttributes styleAttributes) {
- super(tabFolder, SWT.NONE);
- setLayout(new FillLayout());
- Label label = new Label(this, SWT.CENTER);
- label.setText(JstUIMessages.DEFAULT_PREVIEW_TEXT);
- }
+ public void setSelector(String selector) {
+ this.selector = selector;
+ }
- /**
- * Method update preview tab with information from the CSS file passed by parameter.
- *
- * @param cssFile CSS file to be displayed in preview area
- */
- public void initPreview(CSSModel cssModel) {
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * The parent composite for tab
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabPreviewControl(Composite tabFolder,
+ StyleAttributes styleAttributes, ICSSDialogModel cssModel) {
+ super(tabFolder, SWT.NONE);
+ setLayout(new FillLayout());
this.cssModel = cssModel;
+ this.styleAttributes = styleAttributes;
+ initPreview(cssModel);
+ }
+
+ /**
+ * Method update preview tab with information from the CSS file passed by
+ * parameter.
+ *
+ * @param cssFile
+ * CSS file to be displayed in preview area
+ */
+ public void initPreview(ICSSDialogModel cssModel) {
+ this.cssModel = cssModel;
if (cssModel != null) {
- IEditorInput input = new FileEditorInput(cssModel.getStyleFile());
- for (Control control : getChildren()) {
- control.dispose();
- }
StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationCSS();
@@ -70,46 +73,42 @@
JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
viewer.configure(baseConfiguration);
- viewer.setDocument(cssModel.getStructuredDocument());
+ viewer.setDocument(cssModel.getDocument());
viewer.setEditable(false);
layout();
}
}
- public void doRevertToSaved() {
-
- cssModel.reload();
-
+ public void reinit(ICSSDialogModel cssModel) {
+ viewer.setDocument(cssModel.getDocument());
}
-
- /**
- * TODO redesign method : remove "index" param
- * Method is used to select area that corresponds to specific selector.
- *
- * @param selector the selector that should be selected in editor area
- * @param index if CSS file contains more then one elements with the same selector name,
- * then index is serial number of this selector
- */
- public void selectEditorArea(String selector, int index) {
+
+ /**
+ *
+ * @param selector
+ */
+ public void selectClass(String selector) {
if (cssModel != null) {
- IndexedRegion indexedRegion = cssModel.getSelectorRegion(selector,
- index);
- if (/* editor */viewer != null) {
+ IndexedRegion indexedRegion = cssModel.getIndexedRegion(selector);
+ if (viewer != null) {
if (indexedRegion != null) {
- // editor.selectAndReveal(indexedRegion.getStartOffset(),
- // indexedRegion.getLength());
viewer.setSelectedRange(indexedRegion.getStartOffset(),
indexedRegion.getLength());
viewer.revealRange(indexedRegion.getStartOffset(),
indexedRegion.getLength());
} else {
- // editor.selectAndReveal(0, 0);
viewer.setSelectedRange(0, 0);
- viewer.revealRange(0,0);
+ viewer.revealRange(0, 0);
}
}
}
}
+ public void tabSelected() {
+ cssModel.updateCSSStyle(selector, styleAttributes);
+ selectClass(selector);
+
+ }
+
}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabPropertySheetControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -11,174 +11,124 @@
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Set;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TreeEditor;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
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;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
/**
* Class for creating Property sheet tab
- *
+ *
* @author Evgeny Zheleznyakov
*/
public class TabPropertySheetControl extends BaseTabControl {
- private String[] columns = new String[] { "Attribute", "Value" };
- private Tree tree;
+ final static private String[] COLUMNS = new String[] {
+ JstUIMessages.PROPERTY_NAME_COLUMN,
+ JstUIMessages.PROPERTY_VALUE_COLUMN };
+ final static private int COLUMNS_WIDTH = 200;
- private TabPropertySheetMouseAdapter propertySheetMouseAdapter = null;
+ private Tree tree;
- /**
- * Constructor for creating controls
- *
- * @param composite The parent composite for tab
- * @param elementMap
- * @param comboMap
- * @param styleAttributes the StyleAttributes object
- */
- public TabPropertySheetControl(Composite parent, HashMap<String, ArrayList<String>> elementMap,
- HashMap<String, ArrayList<String>> comboMap, StyleAttributes styleAttributes) {
- super(parent, SWT.NONE);
- this.styleAttributes = styleAttributes;
- setLayout(new FillLayout());
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * The parent composite for tab
+ * @param elementMap
+ * @param comboMap
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabPropertySheetControl(Composite parent,
+ StyleAttributes styleAttributes, DataBindingContext bindingContext) {
+ super(bindingContext, styleAttributes, parent, SWT.NONE);
+ setLayout(new FillLayout());
- tree = new Tree(this, SWT.NONE);
- tree.setHeaderVisible(true);
- tree.setLinesVisible(true);
+ tree = new Tree(this, SWT.NONE);
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
- // Create NUM columns
- for (int i = 0; i < columns.length; i++) {
- TreeColumn column = new TreeColumn(tree, SWT.LEFT | SWT.COLOR_BLACK);
- column.setText(columns[i]);
- }
+ // Create columns
+ for (int i = 0; i < COLUMNS.length; i++) {
+ TreeColumn column = new TreeColumn(tree, SWT.LEFT | SWT.COLOR_BLACK);
- Set<String> set = elementMap.keySet();
- for (String str : set) {
- TreeItem item = new TreeItem(tree, SWT.NONE);
- item.setText(str);
-// item.setFont(Constants.FIRST_COLUMN, JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
+ column.setText(COLUMNS[i]);
+ column.setWidth(COLUMNS_WIDTH);
+ }
- ArrayList<String> list = elementMap.get(str);
- for (String strList : list) {
- TreeItem subItem = new TreeItem(item, SWT.NONE);
- subItem.setText(Constants.FIRST_COLUMN, strList);
- }
- }
+ Set<String> sections = CSSConstants.CSS_STYLES_MAP.keySet();
+ for (String sectionKey : sections) {
- updateData(false);
+ TreeItem sectionTreeItem = createTreeItem(tree, sectionKey);
+ sectionTreeItem.setExpanded(true);
+ ArrayList<String> attributeKeys = CSSConstants.CSS_STYLES_MAP
+ .get(sectionKey);
- propertySheetMouseAdapter = new TabPropertySheetMouseAdapter(tree, elementMap, comboMap, this);
- tree.addMouseListener(propertySheetMouseAdapter);
- for (int i = 0; i < tree.getColumnCount(); i++) {
- tree.getColumn(i).pack();
- }
- }
+ for (String attribute : attributeKeys) {
+ TreeItem item = createBindedTreeItem(sectionTreeItem, attribute);
+ item.setExpanded(true);
+ }
+ }
- /**
- * Method for get data in controls (if param equal true ), or set data (if param equal false).
- *
- * @param update
- */
- public void updateData(boolean update) {
- if (update) {
- for (int i = 0; i < tree.getItemCount(); i++) {
- for (int j = 0; j < tree.getItem(i).getItemCount(); j++) {
- if (tree.getItem(i).getItem(j).getText(Constants.SECOND_COLUMN) == null) {
- styleAttributes.removeAttribute(tree.getItem(i).getItem(j)
- .getText(Constants.FIRST_COLUMN));
- } else if (tree.getItem(i).getItem(j).getText(Constants.SECOND_COLUMN).trim()
- .equals(Constants.EMPTY)) {
- styleAttributes.removeAttribute(tree.getItem(i).getItem(j)
- .getText(Constants.FIRST_COLUMN));
- } else {
- styleAttributes.addAttribute(tree.getItem(i).getItem(j)
- .getText(Constants.FIRST_COLUMN),
- tree.getItem(i).getItem(j).getText(Constants.SECOND_COLUMN));
- }
- }
- }
- } else {
- 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);
- }
- }
+ final TreeEditor editor = new TreeEditor(tree);
+ editor.horizontalAlignment = SWT.LEFT;
+ editor.grabHorizontal = true;
+ editor.minimumHeight = 0;
+ editor.minimumWidth = 0;
- Set<String> set = styleAttributes.keySet();
- for (String str : set) {
- for (int i = 0; i < tree.getItemCount(); i++) {
- for (int j = 0; j < tree.getItem(i).getItemCount(); j++) {
- if (tree.getItem(i).getItem(j).getText(Constants.FIRST_COLUMN).equals(str)) {
- tree.getItem(i).getItem(j)
- .setText(Constants.SECOND_COLUMN, styleAttributes.getAttribute(str));
- }
- }
- }
- }
- setExpanded();
- updateDataFromStyleAttributes = false;
- }
- }
+ tree.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ // Clean up any previous editor control
+ Control oldEditor = editor.getEditor();
+ if (oldEditor != null)
+ oldEditor.dispose();
- /**
- * Set expanded item for not empty css attributes.
- */
- 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();
- }
- }
+ // Identify the selected row
+ TreeItem item = (TreeItem) e.item;
+ if (item == null)
+ return;
- /**
- * Find tree item for expand
- *
- * @param attr Name of css attributes
- * @return Tree item which will expand
- */
- 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;
- }
- }
- }
+ // The control that will be the editor must be a child of the
+ // Tree
+ Control newEditor = null;
+ if (!CSSConstants.CSS_STYLES_MAP.containsKey((item
+ .getText(NAME_ATTRIBUTE_COLUMN)))) {
+ newEditor = createControl(tree, item
+ .getText(NAME_ATTRIBUTE_COLUMN));
+ }
- return null;
- }
+ if (newEditor != null) {
- /**
- * Add ManualChangeStyleListener object.
- *
- * @param listener ChangeStyleListener object to be added
- */
- public void addManualChangeStyleListener(ManualChangeStyleListener listener) {
- if (propertySheetMouseAdapter != null) {
- propertySheetMouseAdapter.addManualChangeStyleListener(listener);
- }
- }
+ newEditor.setFocus();
+
+ // Compute the width for the editor
+ // Also, compute the column width, so that the dropdown fits
+ Point size = newEditor
+ .computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ editor.minimumWidth = size.x;
+ editor.minimumHeight = size.y;
+
+ tree.getColumn(VALUE_ATTRIBUTE_COLUMN).setWidth(
+ editor.minimumWidth);
+
+ editor.setEditor(newEditor, item, VALUE_ATTRIBUTE_COLUMN);
+ }
+ }
+ });
+
+ }
}
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabQuickEditControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -12,397 +12,88 @@
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.runtime.IAdaptable;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
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;
-import org.jboss.tools.jst.jsp.outline.cssdialog.ImageSelectionDialog;
-import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
-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.AttributeModifyListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
/**
* Class for creating control in Quick edit tab
- *
+ *
* @author Evgeny Zheleznyakov
*/
public class TabQuickEditControl extends BaseTabControl {
- private static int FIRST_INDEX = 0;
- private static int SECOND_INDEX = 1;
- private static int GRID_NUM_COLUMNS = 3;
- private static int VALUE_NUMBER = 0;
- private static int EXT_VALUE_NUMBER = 1;
- private Label label = null;
- private HashMap<String, ArrayList<String>> comboMap;
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * The parent composite for tab
+ * @param comboMap
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabQuickEditControl(Composite sc, StyleAttributes styleAttributes,
+ DataBindingContext bindingContext) {
+ super(bindingContext, styleAttributes, sc, SWT.NONE);
- /**
- * Constructor for creating controls
- *
- * @param composite The parent composite for tab
- * @param comboMap
- * @param styleAttributes the StyleAttributes object
- */
- public TabQuickEditControl(Composite sc, HashMap<String, ArrayList<String>> comboMap,
- StyleAttributes styleAttributes) {
- super(sc, SWT.NONE);
+ addContent();
+ }
- this.styleAttributes = styleAttributes;
- this.comboMap = comboMap;
+ /**
+ * Update data method.
+ */
+ protected void updateData() {
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = GRID_NUM_COLUMNS;
- setLayout(gridLayout);
+ Control[] controls = this.getChildren();
+ if (controls != null) {
+ for (int i = 0; i < controls.length; i++) {
+ if (!controls[i].isDisposed()) {
+ controls[i].dispose();
+ }
+ }
+ }
- init();
- }
+ addContent();
+ this.layout();
+ }
- /**
- * Update data method.
- */
- public void updateData() {
- Control[] controls = this.getChildren();
- if (controls != null) {
- for (int i = 0; i < controls.length; i++) {
- if (!controls[i].isDisposed()) {
- controls[i].dispose();
- }
- }
- }
+ /**
+ * Initialize method.s
+ */
+ private void addContent() {
- init();
- this.layout();
- }
+ ArrayList<String> listKeys = new ArrayList<String>(getStyleAttributes()
+ .keySet());
- /**
- * Initialize method.
- */
- private void init() {
- ArrayList<String> listKeys = new ArrayList<String>();
- for (String key : styleAttributes.keySet()) {
- listKeys.add(key);
- }
-
- if(listKeys.size()==0) {
- label = new Label(this, SWT.CENTER);
- label.setText(JstUIMessages.CSS_NO_EDITED_PROPERTIES);
- }
- 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));
- }
- }
- updateDataFromStyleAttributes = false;
- }
+ if (listKeys.size() == 0) {
+ Label label = new Label(this, SWT.CENTER);
+ label.setText(JstUIMessages.CSS_NO_EDITED_PROPERTIES);
+ }
- /**
- * Method for creating combo controls.
- *
- * @param composite The parent composite for tab
- * @param name Name of css element
- * @param value Value of css element
- */
- private void createCombo(final String name, final String value) {
- Button btn = null;
- // if css attribute with color combo
- if (name.indexOf(CSSConstants.COLOR) != Constants.DONT_CONTAIN) {
- Composite tmpComposite = getCompositeElement();
+ Collections.sort(listKeys);
- final ImageCombo colorCombo = new ImageCombo(tmpComposite, SWT.BORDER);
- colorCombo.setText(value);
- colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
+ for (String key : listKeys) {
- btn = new Button(tmpComposite, SWT.NONE);
- btn.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
+ String value = getStyleAttributes().getAttribute(key);
+ if (value != null && value.length() > 0) {
+ addLabel(this, getLabel(key));
+ createControl(this, key);
+ }
+ }
+ }
- ImageDescriptor imageDes = JspEditorPlugin
- .getImageDescriptor(/* Constants.IMAGE_COLOR_FILE_LOCATION */Constants.IMAGE_COLORLARGE_FILE_LOCATION);
- Image colorImage = imageDes.createImage();
- btn.setImage(colorImage);
- btn.setToolTipText(JstUIMessages.COLOR_DIALOG_TITLE);
- btn.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- btn.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- RGB startRgb = Util.getColor((colorCombo.getText().toLowerCase().trim()));
- if (startRgb == null) {
- startRgb = Constants.RGB_BLACK;
- }
+ @Override
+ public void tabSelected() {
+ updateData();
+ }
- ColorDialog colorDialog = new ColorDialog(getShell());
- colorDialog.setRGB(startRgb);
- colorDialog.setText(JstUIMessages.COLOR_DIALOG_TITLE);
+ private String getLabel(String key) {
+ return key;
+ }
- 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 {
- colorCombo.setText(str);
- }
- }
- }
- });
- 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);
- colorCombo.addModifyListener(new AttributeModifyListener(this, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- // if css attribute contain choose_folder button
- } else if (Util.containFolder(name)) {
- Composite tmpComposite = getCompositeElement();
-
- final Combo combo = new Combo(tmpComposite, SWT.NONE);
- combo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- btn = new Button(tmpComposite, SWT.NONE);
- btn.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
-
- ImageDescriptor imageDes = JspEditorPlugin
- .getImageDescriptor(/* Constants.IMAGE_FOLDER_FILE_LOCATION */Constants.IMAGE_FOLDERLARGE_FILE_LOCATION);
- Image chooserImage = imageDes.createImage();
- btn.setImage(chooserImage);
- btn.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- btn.setToolTipText(JstUIMessages.COLOR_DIALOG_TITLE);
-
- ArrayList<String> list = comboMap.get(name);
- for (String str : list) {
- combo.add(str);
- }
-
- btn.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- IAdaptable project = Util.getCurrentProject();
- ImageSelectionDialog dialog = new ImageSelectionDialog(getShell(),
- new WorkbenchLabelProvider(), new WorkbenchContentProvider());
- String title = JstUIMessages.IMAGE_DIALOG_TITLE;
- dialog.setTitle(title);
- dialog.setMessage(title);
- dialog.setEmptyListMessage(JstUIMessages.IMAGE_DIALOG_EMPTY_MESSAGE);
- dialog.setAllowMultiple(false);
- dialog.setInput(project);
-
- if (dialog.open() == ImageSelectionDialog.OK) {
- IFile file = (IFile) dialog.getFirstResult();
- String value = file.getFullPath().toString();
- combo.setText(value);
- }
- }
- });
-
- combo.setText(value);
- combo.addModifyListener(new AttributeModifyListener(this, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- } else {
- final Combo combo = new Combo(this, SWT.CENTER);
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- if (!Util.searchInExtElement(name)) {
- gridData.horizontalSpan = 2;
- }
- combo.setLayoutData(gridData);
-
- ArrayList<String> list = comboMap.get(name);
- for (String str : list) {
- combo.add(str);
- }
- final Combo extCombo;
- String[] values = null;
- boolean ext = false;
- if (Util.searchInExtElement(name)) {
- ext = true;
- values = Util.convertExtString(value);
- extCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extCombo.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extCombo.add(Constants.extSizes[i]);
- }
-
- extCombo.select(extCombo.indexOf(values[EXT_VALUE_NUMBER]));
- extCombo.addModifyListener(new AttributeModifyListener(this, combo, name,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- combo.addModifyListener(new AttributeModifyListener(this, extCombo, name,
- AttributeModifyListener.MODIFY_COMBO_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- } else {
- combo.addModifyListener(new AttributeModifyListener(this, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- }
- if (ext) {
- combo.setText(values[VALUE_NUMBER]);
- } else {
- combo.setText(value);
- }
- }
- }
-
- /**
- * Method for creating text controls
- *
- * @param composite The parent composite for tab
- * @param name Name of css element
- * @param value Value of css element
- */
- private void createText(final String name, final String value) {
- Button btn = null;
- final Text text;
-
- String[] values = null;
- boolean ext = false;
- // create "button" in case of FONT_FAMILY style property
- if (name.equalsIgnoreCase(CSSConstants.FONT_FAMILY)) {
- Composite tmpComposite = getCompositeElement();
- text = new Text(tmpComposite, SWT.BORDER);
- text.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
-
- btn = new Button(tmpComposite, SWT.NONE);
- btn.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
-
- ImageDescriptor imageDes = JspEditorPlugin
- .getImageDescriptor(/* Constants.IMAGE_FONT_FILE_LOCATION */Constants.IMAGE_FONTLARGE_FILE_LOCATION);
- Image fontImage = imageDes.createImage();
- btn.setImage(fontImage);
- btn.setToolTipText(JstUIMessages.FONT_FAMILY_TIP);
- btn.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- 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());
- }
- }
- });
- text.addModifyListener(new AttributeModifyListener(this, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- } else {
- if (Util.searchInExtElement(name)) {
- text = new Text(this, SWT.BORDER);
- text.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
-
- values = Util.convertExtString(value);
- ext = true;
- final Combo extCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
- extCombo.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
-
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extCombo.add(Constants.extSizes[i]);
- }
-
- extCombo.select(extCombo.indexOf(values[EXT_VALUE_NUMBER]));
- extCombo.addModifyListener(new AttributeModifyListener(this, text, name,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- text.addModifyListener(new AttributeModifyListener(this, extCombo, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- } else {
- Composite tmpComposite = getCompositeElement();
- text = new Text(tmpComposite, SWT.BORDER);
- text.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- text.addModifyListener(new AttributeModifyListener(this, name,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- }
- }
-
- if (ext) {
- text.setText(values[VALUE_NUMBER]);
- } else {
- text.setText(value);
- }
- }
-
- /**
- * Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
- */
- private Composite getCompositeElement() {
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- GridLayout gridLayoutTmp = new GridLayout(2, false);
- gridLayoutTmp.marginHeight = 0;
- gridLayoutTmp.marginWidth = 0;
- Composite classComposite = new Composite(this, SWT.NONE);
- classComposite.setLayoutData(gridData);
- classComposite.setLayout(gridLayoutTmp);
-
- return classComposite;
- }
-
- /**
- * Method for format css names (text-decoration : Text Decoration)
- *
- * @param str CSS name
- * @return Format ss name
- */
- private String format(String str) {
- StringTokenizer st = new StringTokenizer(str, Constants.DASH);
- String finalStr = Constants.EMPTY;
-
- while (st.hasMoreTokens()) {
- StringBuffer sb = new StringBuffer(st.nextToken());
- String upper = sb.substring(FIRST_INDEX, SECOND_INDEX).toUpperCase();
- sb.replace(FIRST_INDEX, SECOND_INDEX, upper);
- finalStr += sb;
-
- if (st.hasMoreTokens()) {
- finalStr += Constants.WHITE_SPACE;
- } else {
- finalStr += Constants.COLON;
- }
- }
-
- return finalStr;
- }
}
\ No newline at end of file
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/tabs/TabTextControl.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -10,317 +10,69 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.outline.cssdialog.tabs;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.window.Window;
+import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
-import org.jboss.tools.jst.jsp.outline.cssdialog.FontFamilyDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
-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.AttributeModifyListener;
-import org.jboss.tools.jst.jsp.outline.cssdialog.events.StyleAttributes;
-import org.jboss.tools.jst.jsp.outline.cssdialog.parsers.ColorParser;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.StyleAttributes;
/**
* Class for creating Text tab controls
- *
+ *
* @author Igor Zhukov (izhukov(a)exadel.com)
*/
public class TabTextControl extends BaseTabControl {
- private static final int numColumns = 3;
- private Text fontFamilyText;
- private ImageCombo colorCombo;
- private Combo fontSizeCombo;
- private Combo extFontSizeCombo;
- private Combo fontStyleCombo;
- private Combo fontWeigthCombo;
- private Combo textDecorationCombo;
- private Combo textAlignCombo;
- private ArrayList<String> list;
+ /**
+ * Constructor for creating controls
+ *
+ * @param composite
+ * Composite element
+ * @param comboMap
+ * @param styleAttributes
+ * the StyleAttributes object
+ */
+ public TabTextControl(final Composite composite,
+ final StyleAttributes styleAttributes,
+ DataBindingContext bindingContext) {
- /**
- * Constructor for creating controls
- *
- * @param composite Composite element
- * @param comboMap
- * @param styleAttributes the StyleAttributes object
- */
- public TabTextControl(final Composite composite, final HashMap<String, ArrayList<String>> comboMap,
- final StyleAttributes styleAttributes) {
- super(composite, SWT.NONE);
- this.styleAttributes = styleAttributes;
+ super(bindingContext, styleAttributes, composite, SWT.NONE);
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = numColumns;
- setLayout(gridLayout);
+ // Add FONT_FAMILY element
+ addLabel(this, JstUIMessages.FONT_FAMILY);
+ addFontComposite(this, CSSConstants.FONT_FAMILY);
- // =====================================================================================
- // Add FONT_FAMILY element
- // =====================================================================================
- Label label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.FONT_FAMILY);
+ // Add COLOR element
+ addLabel(this, JstUIMessages.COLOR);
+ addColorComposite(this, CSSConstants.COLOR);
- fontFamilyText = new Text(this, SWT.BORDER | SWT.SINGLE);
- fontFamilyText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- fontFamilyText.addModifyListener(new AttributeModifyListener(this, CSSConstants.FONT_FAMILY,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- Button button = new Button(this, SWT.PUSH);
- button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- button.setToolTipText(JstUIMessages.FONT_FAMILY_TIP);
+ // Add FONT_SIZE element
+ addLabel(this, JstUIMessages.FONT_SIZE);
+ addSizeCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.FONT_SIZE), CSSConstants.FONT_SIZE);
- ImageDescriptor fontDesc = JspEditorPlugin.getImageDescriptor(Constants.IMAGE_FONTLARGE_FILE_LOCATION);
- Image fontImage = fontDesc.createImage();
- button.setImage(fontImage);
- button.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- 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());
- }
- }
- });
+ // Add FONT_STYLE element
+ addLabel(this, JstUIMessages.FONT_STYLE);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.FONT_STYLE), CSSConstants.FONT_STYLE);
- // =====================================================================================
- // Add COLOR element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.COLOR);
+ // Add FONT_WEIGHT element
+ addLabel(this, JstUIMessages.FONT_WEIGHT);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.FONT_WEIGHT), CSSConstants.FONT_WEIGHT);
- colorCombo = new ImageCombo(this, SWT.BORDER);
- colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
- colorCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.COLOR,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- Set<Entry<String, String>> set = ColorParser.getInstance().getMap().entrySet();
- for (Map.Entry<String, String> me : set) {
- RGB rgb = Util.getColor(me.getKey());
- colorCombo.add(me.getValue(), rgb);
- }
+ // Add TEXT_DECORATION element
+ addLabel(this, JstUIMessages.TEXT_DECORATION);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.TEXT_DECORATION),
+ CSSConstants.TEXT_DECORATION);
- button = new Button(this, SWT.PUSH);
- button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- button.setToolTipText(JstUIMessages.COLOR_TIP);
+ // Add TEXT_ALIGN element
+ addLabel(this, JstUIMessages.TEXT_ALIGN);
+ addCombo(this, CSSConstants.CSS_STYLE_VALUES_MAP
+ .get(CSSConstants.TEXT_ALIGN), CSSConstants.TEXT_ALIGN);
- ImageDescriptor colorDesc = JspEditorPlugin.getImageDescriptor(Constants.IMAGE_COLORLARGE_FILE_LOCATION);
- Image im = colorDesc.createImage();
- button.setImage(im);
- button.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- Button button = (Button) e.getSource();
- button.getImage().dispose();
- }
- });
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- ColorDialog dlg = new ColorDialog(getShell());
+ }
- dlg.setRGB((Util.getColor((colorCombo.getText().trim())) == null)
- ? Constants.RGB_BLACK : Util.getColor((colorCombo.getText().trim())));
- dlg.setText(JstUIMessages.COLOR_DIALOG_TITLE);
-
- RGB rgb = dlg.open();
- if (rgb != null) {
- String colorStr = Util.createColorString(rgb);
- colorCombo.setText(colorStr);
- }
- }
- });
-
- // =====================================================================================
- // Add FONT_SIZE element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.FONT_SIZE);
-
- // Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
- // Is created for correct layout.
- Composite tmpComposite = getCompositeElement();
- fontSizeCombo = new Combo(tmpComposite, SWT.BORDER | SWT.SINGLE);
- fontSizeCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
-
- extFontSizeCombo = new Combo(tmpComposite, SWT.BORDER | SWT.READ_ONLY);
- extFontSizeCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
- extFontSizeCombo.addModifyListener(new AttributeModifyListener(this, fontSizeCombo, CSSConstants.FONT_SIZE,
- AttributeModifyListener.MODIFY_COMBO_EXTENSION_ATTRIBUTE_FIELD));
- for (int i = 0; i < Constants.extSizes.length; i++) {
- extFontSizeCombo.add(Constants.extSizes[i]);
- }
-
- fontSizeCombo.addModifyListener(new AttributeModifyListener(this, extFontSizeCombo, CSSConstants.FONT_SIZE,
- AttributeModifyListener.MODIFY_COMBO_ATTRIBUTE_FIELD_WITH_COMBO_EXTENSION));
- list = comboMap.get(CSSConstants.FONT_SIZE);
- for (String str : list) {
- fontSizeCombo.add(str);
- }
-
- // =====================================================================================
- // Add FONT_STYLE element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.FONT_STYLE);
-
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- fontStyleCombo = new Combo(this, SWT.BORDER);
- fontStyleCombo.setLayoutData(gridData);
- fontStyleCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.FONT_STYLE,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- list = comboMap.get(CSSConstants.FONT_STYLE);
- for (String str : list) {
- fontStyleCombo.add(str);
- }
-
- // =====================================================================================
- // Add FONT_WEIGHT element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.FONT_WEIGHT);
-
- gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- fontWeigthCombo = new Combo(this, SWT.BORDER);
- fontWeigthCombo.setLayoutData(gridData);
- fontWeigthCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.FONT_WEIGHT,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- list = comboMap.get(CSSConstants.FONT_WEIGHT);
- for (String str : list) {
- fontWeigthCombo.add(str);
- }
-
- // =====================================================================================
- // Add TEXT_DECORATION element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.TEXT_DECORATION);
-
- gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- textDecorationCombo = new Combo(this, SWT.BORDER);
- textDecorationCombo.setLayoutData(gridData);
- textDecorationCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.TEXT_DECORATION,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- list = comboMap.get(CSSConstants.TEXT_DECORATION);
- for (String str : list) {
- textDecorationCombo.add(str);
- }
-
- // =====================================================================================
- // Add TEXT_ALIGN element
- // =====================================================================================
- label = new Label(this, SWT.LEFT);
- label.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
- label.setText(JstUIMessages.TEXT_ALIGN);
-
- gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- textAlignCombo = new Combo(this, SWT.BORDER);
- textAlignCombo.setLayoutData(gridData);
- textAlignCombo.addModifyListener(new AttributeModifyListener(this, CSSConstants.TEXT_ALIGN,
- AttributeModifyListener.MODIFY_SIMPLE_ATTRIBUTE_FIELD));
- list = comboMap.get(CSSConstants.TEXT_ALIGN);
- for (String str : list) {
- textAlignCombo.add(str);
- }
- }
-
- /**
- * Create container that take up 2 cells and contains fontSizeCombo and extFontSizeCombo elements.
- */
- private Composite getCompositeElement() {
- GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
- gridData.horizontalSpan = 2;
- GridLayout gridLayoutTmp = new GridLayout(2, false);
- gridLayoutTmp.marginHeight = 0;
- gridLayoutTmp.marginWidth = 0;
- Composite classComposite = new Composite(this, SWT.NONE);
- classComposite.setLayoutData(gridData);
- classComposite.setLayout(gridLayoutTmp);
-
- return classComposite;
- }
-
- /**
- * 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;
- // set FONT_FAMILY attribute
- String tmp = styleAttributes.getAttribute(CSSConstants.FONT_FAMILY);
- if (!tmp.equals(fontFamilyText.getText())) {
- fontFamilyText.setText(tmp);
- }
- // set COLOR attribute
- tmp = styleAttributes.getAttribute(CSSConstants.COLOR);
- if (!tmp.equals(colorCombo.getText())) {
- colorCombo.setText(tmp);
- }
- // set FONT_SIZE and EXTENSION_FONT_SIZE attributes
- tmp = styleAttributes.getAttribute(CSSConstants.FONT_SIZE);
- String[] str = Util.convertExtString(tmp);
- if (!str[0].equals(fontSizeCombo.getText())) {
- fontSizeCombo.setText(str[0]);
- if (extFontSizeCombo.indexOf(str[1]) != -1) {
- extFontSizeCombo.setText(str[1]);
- extFontSizeCombo.select(extFontSizeCombo.indexOf(str[1]));
- }
- }
- // set TEXT_DECORATION attribute
- tmp = styleAttributes.getAttribute(CSSConstants.TEXT_DECORATION);
- if (!tmp.equals(textDecorationCombo.getText())) {
- textDecorationCombo.setText(tmp);
- }
- // set FONT_STYLE attribute
- tmp = styleAttributes.getAttribute(CSSConstants.FONT_STYLE);
- if (!tmp.equals(fontStyleCombo.getText())) {
- fontStyleCombo.setText(tmp);
- }
- // set FONT_WEIGHT attribute
- tmp = styleAttributes.getAttribute(CSSConstants.FONT_WEIGHT);
- if (!tmp.equals(fontWeigthCombo.getText())) {
- fontWeigthCombo.setText(tmp);
- }
- // set TEXT_ALIGN attribute
- tmp = styleAttributes.getAttribute(CSSConstants.TEXT_ALIGN);
- if (!tmp.equals(textAlignCombo.getText())) {
- textAlignCombo.setText(tmp);
- }
- updateDataFromStyleAttributes = false;
- }
}
\ No newline at end of file
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSTreeItemWidgetValueProperty.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSTreeItemWidgetValueProperty.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSTreeItemWidgetValueProperty.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.widgets;
+
+import org.eclipse.jface.databinding.swt.WidgetValueProperty;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class CSSTreeItemWidgetValueProperty extends WidgetValueProperty {
+
+ int column = 0;
+
+ public CSSTreeItemWidgetValueProperty(int column) {
+ super();
+ this.column = column;
+ }
+
+ protected Object doGetValue(Object source) {
+ return ((TreeItem) source).getText(column);
+ }
+
+ @Override
+ protected void doSetValue(Object source, Object value) {
+ ((TreeItem) source).setText(column, (String) (value != null ? value
+ : "")); //$NON-NLS-1$
+ }
+
+ public Object getValueType() {
+ return String.class;
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSTreeItemWidgetValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidget.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidget.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidget.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.widgets;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public interface CSSWidget {
+
+ abstract public void setText(String text);
+
+ abstract public String getText();
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidget.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidgetValueProperty.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidgetValueProperty.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidgetValueProperty.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.widgets;
+
+import org.eclipse.jface.databinding.swt.WidgetValueProperty;
+import org.eclipse.swt.SWT;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class CSSWidgetValueProperty extends WidgetValueProperty {
+
+ public CSSWidgetValueProperty() {
+ super(SWT.Modify);
+ }
+
+ protected Object doGetValue(Object source) {
+ return ((CSSWidget) source).getText();
+ }
+
+ @Override
+ protected void doSetValue(Object source, Object value) {
+ ((CSSWidget) source).setText((String) (value != null ? value : "")); //$NON-NLS-1$
+ }
+
+ public Object getValueType() {
+ return String.class;
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/CSSWidgetValueProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/ImageCombo.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/ImageCombo.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/ImageCombo.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,1278 @@
+/*******************************************************************************
+ * 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.widgets;
+
+import java.util.Arrays;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TypedListener;
+import org.eclipse.swt.widgets.Widget;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+
+
+/**
+ * The ImageCombo Combo-Widget class with images represents a selectable user
+ * interface object that combines a text field and a list and issues
+ * notification when an item is selected from the list.
+ *
+ * @author dsakovich(a)exadel.com
+ */
+public final class ImageCombo extends Composite implements CSSWidget {
+ private static final boolean gtk = "gtk".equals(SWT.getPlatform());
+ private static final int X = 0;
+ private static final int Y = 0;
+ private static final int WIDTH = 20;
+ private static final int HEIGHT = 15;
+ private static final int DEPTH = 1;
+ private static final int DEFAULT_SELECTION = -1;
+ private boolean dontDrop = false;
+ private int visibleItemCount = 10;
+ private Text text;
+ private Table table;
+ private Shell popup;
+ private Button arrowButton;
+ private boolean hasFocus;
+ private Listener listener;
+ private Listener filter;
+
+ /**
+ * Constructs a new instance of this class given its parent and a style
+ * value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in class
+ * <code>SWT</code> which is applicable to instances of this class, or must
+ * be built by <em>bitwise OR</em>'ing together (that is, using the
+ * <code>int</code> "|" operator) two or more of those <code>SWT</code>
+ * style constants. The class description lists the style constants that are
+ * applicable to the class. Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent
+ * a widget which will be the parent of the new instance (cannot
+ * be null)
+ * @param style
+ * the style of widget to construct
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the parent</li>
+ * </ul>
+ *
+ * @see SWT#BORDER
+ * @see SWT#READ_ONLY
+ * @see SWT#FLAT
+ * @see Widget#getStyle()
+ */
+ public ImageCombo(Composite parent, int style) {
+ super(parent, style = checkStyle(style));
+
+ int textStyle = SWT.SINGLE;
+
+ if (gtk) {
+ textStyle |= SWT.BORDER;
+ }
+
+ if ((style & SWT.READ_ONLY) != 0) {
+ textStyle |= SWT.READ_ONLY;
+ }
+
+ if ((style & SWT.FLAT) != 0) {
+ textStyle |= SWT.FLAT;
+ }
+
+ text = new Text(this, textStyle);
+
+ int arrowStyle = SWT.ARROW | SWT.DOWN;
+
+ if ((style & SWT.FLAT) != 0) {
+ arrowStyle |= SWT.FLAT;
+ }
+
+ arrowButton = new Button(this, arrowStyle);
+ listener = new Listener() {
+ public void handleEvent(Event event) {
+ if (popup == event.widget) {
+ popupEvent(event);
+
+ return;
+ }
+ if (text == event.widget) {
+ textEvent(event);
+
+ return;
+ }
+ if (table == event.widget) {
+ listEvent(event);
+
+ return;
+ }
+ if (arrowButton == event.widget) {
+ arrowEvent(event);
+
+ return;
+ }
+ if (ImageCombo.this == event.widget) {
+ comboEvent(event);
+
+ return;
+ }
+ if (getShell() == event.widget) {
+ handleFocus(SWT.FocusOut);
+ }
+ }
+ };
+ filter = new Listener() {
+ public void handleEvent(Event event) {
+ Shell shell = ((Control) event.widget).getShell();
+
+ if (shell == ImageCombo.this.getShell()) {
+ handleFocus(SWT.FocusOut);
+ }
+ }
+ };
+
+ int[] comboEvents = { SWT.Dispose, SWT.Move, SWT.Resize };
+ for (int i = 0; i < comboEvents.length; i++)
+ this.addListener(comboEvents[i], listener);
+
+ int[] textEvents = {
+ SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn
+ };
+
+ for (int i = 0; i < textEvents.length; i++) {
+ text.addListener(textEvents[i], listener);
+ }
+ int[] arrowEvents = { SWT.Selection, SWT.FocusIn };
+
+ for (int i = 0; i < arrowEvents.length; i++) {
+ arrowButton.addListener(arrowEvents[i], listener);
+ }
+ createPopup(DEFAULT_SELECTION);
+ }
+
+ /**
+ * Check style.
+ * @param style
+ * @return
+ */
+ static int checkStyle(int style) {
+ int mask = gtk ? (SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)
+ : (SWT.BORDER | SWT.READ_ONLY | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
+
+ return style & mask;
+ }
+
+ /**
+ * Adds the argument to the end of the receiver's list.
+ *
+ * @param string
+ * the new item
+ *
+ * @param image
+ * image for the item
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ *
+ * @see #add(String,int)
+ */
+ public void add(String string, Image image) {
+ checkWidget();
+
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ TableItem newItem = new TableItem(this.table, SWT.NONE);
+ newItem.setText(string);
+
+ if (image != null) {
+ newItem.setImage(image);
+ }
+
+ newItem.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ TableItem item = (TableItem) e.getSource();
+ item.getImage().dispose();
+ }
+ });
+ }
+
+ /**
+ * Adds the argument to the receiver's list at the given zero-relative
+ * index.
+ * <p>
+ * Note: To add an item at the end of the list, use the result of calling
+ * <code>getItemCount()</code> as the index or use <code>add(String)</code>.
+ * </p>
+ *
+ * @param string
+ * the new item
+ *
+ * @param image
+ * image for the item
+ *
+ * @param index
+ * the index for the item
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * <li>ERROR_INVALID_RANGE - if the index is not between 0
+ * and the number of elements in the list (inclusive)</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ *
+ * @see #add(String)
+ */
+ public void add(String string, Image image, int index) {
+ checkWidget();
+
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ TableItem newItem = new TableItem(this.table, SWT.NONE, index);
+
+ if (image != null) {
+ newItem.setImage(image);
+ newItem.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ TableItem item = (TableItem) e.getSource();
+ item.getImage().dispose();
+ }
+ });
+ }
+ }
+
+ /**
+ * Adds the argument to the end of the receiver's list.
+ *
+ * @param string
+ * the new item
+ * @param rgb
+ * RGB color image for the item
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ *
+ * @see #add(String,int)
+ */
+ public void add(String string, RGB rgb) {
+ Color white = new Color(getDisplay(), Constants.RGB_WHITE);
+ Color black = new Color(getDisplay(), Constants.RGB_BLACK);
+ Color color = new Color(getDisplay(), rgb);
+
+ Image image = new Image(getDisplay(), WIDTH, HEIGHT);
+ GC gc = new GC(image);
+ gc.setBackground(color);
+ gc.fillRectangle(X, Y, WIDTH, HEIGHT);
+ gc.setBackground(black);
+ gc.drawRectangle(X, Y, WIDTH, HEIGHT);
+ gc.dispose();
+
+ ImageData imageData = image.getImageData();
+ image.dispose();
+ color.dispose();
+
+ PaletteData palette = new PaletteData(new RGB[] { Constants.RGB_BLACK, Constants.RGB_WHITE, });
+ ImageData maskData = new ImageData(WIDTH, HEIGHT, DEPTH, palette);
+ Image mask = new Image(getDisplay(), maskData);
+ gc = new GC(mask);
+ gc.setBackground(black);
+ gc.fillRectangle(X, Y, WIDTH, HEIGHT);
+ gc.setBackground(white);
+ gc.fillRectangle(X, Y, WIDTH, HEIGHT);
+ gc.dispose();
+ maskData = mask.getImageData();
+ mask.dispose();
+
+ Image icon = new Image(getDisplay(), imageData, maskData);
+ color.dispose();
+ black.dispose();
+ white.dispose();
+ add(string, icon);
+ }
+
+ /**
+ * Adds the listener to the collection of listeners who will be notified
+ * when the receiver's text is modified, by sending it one of the messages
+ * defined in the <code>ModifyListener</code> interface.
+ *
+ * @param listener
+ * the listener which should be notified
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ *
+ * @see ModifyListener
+ * @see #removeModifyListener
+ */
+ public void addModifyListener(ModifyListener listener) {
+ checkWidget();
+
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Modify, typedListener);
+ }
+
+ /**
+ * Adds the listener to the collection of listeners who will be notified
+ * when the receiver's selection changes, by sending it one of the messages
+ * defined in the <code>SelectionListener</code> interface.
+ * <p>
+ * <code>widgetSelected</code> is called when the combo's list selection
+ * changes. <code>widgetDefaultSelected</code> is typically called when
+ * ENTER is pressed the combo's text area.
+ * </p>
+ *
+ * @param listener
+ * the listener which should be notified
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ *
+ * @see SelectionListener
+ * @see #removeSelectionListener
+ * @see SelectionEvent
+ */
+ public void addSelectionListener(SelectionListener listener) {
+ checkWidget();
+
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection, typedListener);
+ addListener(SWT.DefaultSelection, typedListener);
+ }
+
+ /**
+ *
+ * @param event
+ */
+ void arrowEvent(Event event) {
+ switch (event.type) {
+ case SWT.FocusIn: {
+ if (gtk) {
+ setFocus();
+
+ return;
+ }
+
+ handleFocus(SWT.FocusIn);
+
+ break;
+ }
+
+ case SWT.Selection: {
+ if (gtk) {
+ if (!dontDrop) {
+ dropDown(!isDropped());
+ }
+
+ dontDrop = false;
+ } else {
+ dropDown(!isDropped());
+ }
+
+ break;
+ }
+ }
+ }
+
+ /**
+ *
+ * @param event
+ */
+ void comboEvent(Event event) {
+ switch (event.type) {
+ case SWT.Dispose:
+
+ if ((popup != null) && !popup.isDisposed()) {
+ table.removeListener(SWT.Dispose, listener);
+ popup.dispose();
+ }
+
+ Shell shell = getShell();
+ shell.removeListener(SWT.Deactivate, listener);
+
+ Display display = getDisplay();
+ display.removeFilter(SWT.FocusIn, filter);
+ popup = null;
+ text = null;
+ table = null;
+ arrowButton = null;
+
+ break;
+
+ case SWT.Move:
+ dropDown(false);
+
+ break;
+
+ case SWT.Resize:
+ internalLayout(false);
+
+ break;
+ }
+ }
+
+ /**
+ * Method for computing size for widget
+ *
+ * @param wHint
+ * width
+ * @param hHint
+ * height
+ * @return Point
+ */
+ public Point computeSize(int wHint, int hHint, boolean changed) {
+ checkWidget();
+
+ int width = 0;
+ int height = 0;
+ String[] items = getStringsFromTable();
+ int textWidth = 0;
+ GC gc = new GC(text);
+ int spacer = gc.stringExtent(Constants.WHITE_SPACE).x;
+
+ for (int i = 0; i < items.length; i++) {
+ textWidth = Math.max(gc.stringExtent(items[i]).x, textWidth);
+ }
+
+ gc.dispose();
+
+ Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
+ Point arrowSize = arrowButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
+ Point listSize = table.computeSize(wHint, SWT.DEFAULT, changed);
+ int borderWidth = getBorderWidth();
+
+ height = Math.max(hHint, Math.max(textSize.y, arrowSize.y) + (2 * borderWidth));
+ width = Math.max(wHint,
+ Math.max(textWidth + (2 * spacer) + arrowSize.x + (2 * borderWidth), listSize.x));
+
+ return new Point(width, height);
+ }
+
+ /**
+ * Method for creating popup table
+ *
+ * @param selectionIndex
+ */
+ void createPopup(int selectionIndex) {
+ // create shell and list
+ popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
+
+ int style = getStyle();
+ int listStyle = SWT.SINGLE | SWT.V_SCROLL;
+
+ if ((style & SWT.FLAT) != 0) {
+ listStyle |= SWT.FLAT;
+ }
+
+ if ((style & SWT.RIGHT_TO_LEFT) != 0) {
+ listStyle |= SWT.RIGHT_TO_LEFT;
+ }
+
+ if ((style & SWT.LEFT_TO_RIGHT) != 0) {
+ listStyle |= SWT.LEFT_TO_RIGHT;
+ }
+
+ // create a table instead of a list.
+ table = new Table(popup, listStyle);
+ table.setToolTipText(JstUIMessages.IMAGE_COMBO_TABLE_TOOL_TIP);
+
+ int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
+
+ for (int i = 0; i < popupEvents.length; i++)
+ popup.addListener(popupEvents[i], listener);
+
+ int[] listEvents = {
+ SWT.Traverse, SWT.MouseDoubleClick, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose
+ };
+
+ for (int i = 0; i < listEvents.length; i++)
+ table.addListener(listEvents[i], listener);
+
+ if (selectionIndex != -1) {
+ table.setSelection(selectionIndex);
+ }
+ }
+
+ /**
+ *
+ * @param drop
+ */
+ void dropDown(boolean drop) {
+ if (drop == isDropped()) {
+ return;
+ }
+
+ if (!drop) {
+ popup.setVisible(false);
+
+ if (!isDisposed() && arrowButton.isFocusControl()) {
+ text.setFocus();
+ }
+
+ return;
+ }
+
+ if (getShell() != popup.getParent()) {
+ int selectionIndex = table.getSelectionIndex();
+ table.removeListener(SWT.Dispose, listener);
+ popup.dispose();
+ popup = null;
+ table = null;
+ createPopup(selectionIndex);
+ }
+
+ Point size = getSize();
+ int itemCount = table.getItemCount();
+ itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
+
+ int itemHeight = table.getItemHeight() * itemCount;
+ Point listSize = table.computeSize(SWT.DEFAULT, itemHeight, false);
+ table.setBounds(1, 1, Math.max(size.x - 2, listSize.x), listSize.y);
+
+ int index = table.getSelectionIndex();
+
+ if (index != -1) {
+ table.setTopIndex(index);
+ }
+
+ Display display = getDisplay();
+ Rectangle listRect = table.getBounds();
+ Rectangle parentRect = display.map(getParent(), null, getBounds());
+ Point comboSize = getSize();
+ Rectangle displayRect = getMonitor().getClientArea();
+ int width = Math.max(comboSize.x, listRect.width + 2);
+ int height = listRect.height + 2;
+ int x = parentRect.x;
+ int y = parentRect.y + comboSize.y;
+
+ if ((y + height) > (displayRect.y + displayRect.height)) {
+ y = parentRect.y - height;
+ }
+
+ popup.setBounds(x, y, width, height);
+ popup.setVisible(true);
+ table.setFocus();
+ }
+
+ /**
+ * Returns the number of items contained in the receiver's list.
+ *
+ * @return the number of items
+ *
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public int getItemCount() {
+ checkWidget();
+
+ return table.getItemCount();
+ }
+
+ String[] getStringsFromTable() {
+ String[] items = new String[this.table.getItems().length];
+
+ for (int i = 0, n = items.length; i < n; i++) {
+ items[i] = this.table.getItem(i).getText();
+ }
+
+ return items;
+ }
+
+ /**
+ * Returns the zero-relative index of the item which is currently selected
+ * in the receiver's list, or -1 if no item is selected.
+ *
+ * @return the index of the selected item
+ *
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public int getSelectionIndex() {
+ checkWidget();
+
+ return table.getSelectionIndex();
+ }
+
+ /**
+ * Method for getting widget style
+ */
+ public int getStyle() {
+ int style = super.getStyle();
+ style &= ~SWT.READ_ONLY;
+
+ if (!text.getEditable()) {
+ style |= SWT.READ_ONLY;
+ }
+
+ return style;
+ }
+
+ /**
+ * Returns a string containing a copy of the contents of the receiver's text
+ * field.
+ *
+ * @return the receiver's text
+ *
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public String getText() {
+ checkWidget();
+
+ return text.getText();
+ }
+
+ /**
+ *
+ * @param type
+ */
+ void handleFocus(int type) {
+ if (isDisposed()) {
+ return;
+ }
+
+ switch (type) {
+ case SWT.FocusIn: {
+ if (hasFocus) {
+ return;
+ }
+
+ hasFocus = true;
+
+ Shell shell = getShell();
+ shell.removeListener(SWT.Deactivate, listener);
+ shell.addListener(SWT.Deactivate, listener);
+
+ Display display = getDisplay();
+ display.removeFilter(SWT.FocusIn, filter);
+ display.addFilter(SWT.FocusIn, filter);
+
+ Event e = new Event();
+ notifyListeners(SWT.FocusIn, e);
+
+ break;
+ }
+
+ case SWT.FocusOut: {
+ if (!hasFocus) {
+ return;
+ }
+
+ Control focusControl = getDisplay().getFocusControl();
+
+ if ((focusControl == arrowButton) || (focusControl == table) || (focusControl == text)) {
+ return;
+ }
+
+ hasFocus = false;
+
+ Shell shell = getShell();
+ shell.removeListener(SWT.Deactivate, listener);
+
+ Display display = getDisplay();
+ display.removeFilter(SWT.FocusIn, filter);
+
+ Event e = new Event();
+ notifyListeners(SWT.FocusOut, e);
+
+ break;
+ }
+ }
+ }
+
+ /**
+ * Searches the receiver's list starting at the first item (index 0) until
+ * an item is found that is equal to the argument, and returns the index of
+ * that item. If no item is found, returns -1.
+ *
+ * @param string
+ * the search item
+ * @return the index of the item
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public int indexOf(String string) {
+ checkWidget();
+
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ return Arrays.asList(getStringsFromTable()).indexOf(string);
+ }
+
+ /**
+ *
+ * @return
+ */
+ boolean isDropped() {
+ return popup.getVisible();
+ }
+
+ /**
+ *
+ * @param changed
+ */
+ void internalLayout(boolean changed) {
+ if (isDropped()) {
+ dropDown(false);
+ }
+
+ Rectangle rect = getClientArea();
+ int width = rect.width;
+ int height = rect.height;
+ Point arrowSize = arrowButton.computeSize(SWT.DEFAULT, height, changed);
+ text.setBounds(0, 0, width - arrowSize.x, height);
+ arrowButton.setBounds(width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
+ }
+
+ /**
+ *
+ * @param event
+ */
+ void listEvent(Event event) {
+ switch (event.type) {
+ case SWT.Dispose:
+
+ if (getShell() != popup.getParent()) {
+ int selectionIndex = table.getSelectionIndex();
+ popup = null;
+ table = null;
+ createPopup(selectionIndex);
+ }
+
+ break;
+
+ case SWT.FocusIn: {
+ handleFocus(SWT.FocusIn);
+
+ break;
+ }
+
+ case SWT.MouseDoubleClick: {
+ int index = table.getSelectionIndex();
+
+ if (index == -1) {
+ return;
+ }
+
+ text.setText(table.getItem(index).getText());
+ table.setSelection(index);
+
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ e.doit = event.doit;
+ notifyListeners(SWT.Selection, e);
+ event.doit = e.doit;
+ dropDown(false);
+
+ break;
+ }
+
+ case SWT.Traverse: {
+ switch (event.detail) {
+ case SWT.TRAVERSE_RETURN:
+ case SWT.TRAVERSE_ESCAPE:
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ case SWT.TRAVERSE_ARROW_NEXT:
+ event.doit = false;
+
+ break;
+ }
+
+ Event e = new Event();
+ e.time = event.time;
+ e.detail = event.detail;
+ e.doit = event.doit;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ notifyListeners(SWT.Traverse, e);
+ event.doit = e.doit;
+ event.detail = e.detail;
+
+ break;
+ }
+
+ case SWT.KeyUp: {
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyUp, e);
+
+ break;
+ }
+
+ case SWT.KeyDown: {
+ if (event.character == SWT.ESC) {
+ // Escape key cancels popup list
+ dropDown(false);
+ }
+
+ if (((event.stateMask & SWT.ALT) != 0) &&
+ ((event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_DOWN))) {
+ dropDown(false);
+ }
+
+ if (event.character == SWT.CR) {
+ // Enter causes default selection
+ dropDown(false);
+
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.DefaultSelection, e);
+ }
+
+ if (isDisposed()) {
+ break;
+ }
+
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyDown, e);
+
+ int index = table.getSelectionIndex();
+
+ if (index == -1) {
+ return;
+ }
+
+ text.setText(table.getItem(index).getText());
+ table.setSelection(index);
+
+ break;
+ }
+ }
+ }
+
+ /**
+ *
+ * @param event
+ */
+ void popupEvent(Event event) {
+ switch (event.type) {
+ case SWT.Paint:
+
+ // draw black rectangle around list
+ Rectangle listRect = table.getBounds();
+ Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
+ event.gc.setForeground(black);
+ event.gc.drawRectangle(X, Y, listRect.width + 1, listRect.height + 1);
+
+ break;
+
+ case SWT.Close:
+ event.doit = false;
+ dropDown(false);
+
+ break;
+
+ case SWT.Deactivate:
+
+ // when the popup shell is deactivated by clicking the button,
+ // we receive two Deactivate events on Win32, whereas on GTK
+ // we first receive one Deactivation event from the shell and
+ // then a Selection event from the button.
+ // as a work-around, set a flag (dontDrop) if running GTK
+ if (gtk) {
+ Point loc = arrowButton.toControl(getDisplay().getCursorLocation());
+ Point size = arrowButton.getSize();
+
+ if ((loc.x >= 0) && (loc.y >= 0) && (loc.x < size.x) && (loc.y < size.y)) {
+ dontDrop = true;
+ }
+ }
+
+ dropDown(false);
+
+ break;
+ }
+ }
+
+ /**
+ * Method for redrawing widget
+ */
+ public void redraw() {
+ super.redraw();
+ text.redraw();
+ arrowButton.redraw();
+
+ if (popup.isVisible()) {
+ table.redraw();
+ }
+ }
+
+ /**
+ * Selects the item at the given zero-relative index in the receiver's list.
+ * If the item at the index was already selected, it remains selected.
+ * Indices that are out of range are ignored.
+ *
+ * @param index
+ * the index of the item to select
+ *
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public void select(int index) {
+ checkWidget();
+
+ if (index == -1) {
+ table.deselectAll();
+ text.setText(Constants.EMPTY);
+
+ return;
+ }
+
+ if ((0 <= index) && (index < table.getItemCount())) {
+ if (index != getSelectionIndex()) {
+ text.setText(table.getItem(index).getText());
+ text.selectAll();
+ table.select(index);
+ table.showSelection();
+ }
+ }
+ }
+
+ /**
+ * Method for setting focus in text widget
+ */
+ public boolean setFocus() {
+ checkWidget();
+
+ return text.setFocus();
+ }
+
+ /**
+ * Sets the contents of the receiver's text field to the given string.
+ * <p>
+ * Note: The text field in a <code>Combo</code> is typically only capable of
+ * displaying a single line of text. Thus, setting the text to a string
+ * containing line breaks or other special characters will probably cause it
+ * to display incorrectly.
+ * </p>
+ *
+ * @param string
+ * the new text
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * </ul>
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
+ * disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public void setText(String string) {
+ checkWidget();
+
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ int index = -1;
+
+ for (int i = 0, n = table.getItemCount(); i < n; i++) {
+ if (table.getItem(i).getText().equals(string)) {
+ index = i;
+
+ break;
+ }
+ }
+
+ if (index == -1) {
+ table.deselectAll();
+ text.setText(string);
+
+ return;
+ }
+
+ text.setText(string);
+ text.selectAll();
+ table.setSelection(index);
+ table.showSelection();
+ }
+
+ /**
+ *
+ * @param event
+ */
+ void textEvent(Event event) {
+ switch (event.type) {
+ case SWT.FocusIn: {
+ handleFocus(SWT.FocusIn);
+
+ break;
+ }
+
+ case SWT.KeyDown: {
+ if (event.character == SWT.CR) {
+ dropDown(false);
+
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.DefaultSelection, e);
+ }
+
+ if (isDisposed()) {
+ break;
+ }
+
+ if ((event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_DOWN)) {
+ event.doit = false;
+
+ if ((event.stateMask & SWT.ALT) != 0) {
+ boolean dropped = isDropped();
+ text.selectAll();
+
+ if (!dropped) {
+ setFocus();
+ }
+
+ dropDown(!dropped);
+
+ break;
+ }
+
+ int oldIndex = getSelectionIndex();
+
+ if (event.keyCode == SWT.ARROW_UP) {
+ select(Math.max(oldIndex - 1, 0));
+ } else {
+ select(Math.min(oldIndex + 1, getItemCount() - 1));
+ }
+
+ if (oldIndex != getSelectionIndex()) {
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.Selection, e);
+ }
+
+ if (isDisposed()) {
+ break;
+ }
+ }
+
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyDown, e);
+
+ break;
+ }
+
+ case SWT.KeyUp: {
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyUp, e);
+
+ break;
+ }
+
+ case SWT.Modify: {
+ table.deselectAll();
+
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.Modify, e);
+
+ break;
+ }
+
+ case SWT.MouseDown: {
+ if (event.button != 1) {
+ return;
+ }
+
+ if (text.getEditable()) {
+ return;
+ }
+
+ boolean dropped = isDropped();
+ text.selectAll();
+
+ if (!dropped) {
+ setFocus();
+ }
+
+ dropDown(!dropped);
+
+ break;
+ }
+
+ case SWT.MouseUp: {
+ if (event.button != 1) {
+ return;
+ }
+
+ if (text.getEditable()) {
+ return;
+ }
+
+ text.selectAll();
+
+ break;
+ }
+
+ case SWT.Traverse: {
+ switch (event.detail) {
+ case SWT.TRAVERSE_RETURN:
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ case SWT.TRAVERSE_ARROW_NEXT:
+ event.doit = false;
+
+ break;
+ }
+
+ Event e = new Event();
+ e.time = event.time;
+ e.detail = event.detail;
+ e.doit = event.doit;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ notifyListeners(SWT.Traverse, e);
+ event.doit = e.doit;
+ event.detail = e.detail;
+
+ break;
+ }
+ }
+ }
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/ImageCombo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeCombo.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeCombo.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeCombo.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.widgets;
+
+
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class SizeCombo extends Composite implements Listener, CSSWidget {
+
+ private Combo sizeCombo;
+
+ private Combo unitCombo;
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public SizeCombo(Composite parent, List<String> values) {
+
+ super(parent, SWT.None);
+
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = 0;
+
+ setLayout(layout);
+ setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false,
+ 2, 1));
+
+ sizeCombo = new Combo(this, SWT.BORDER | SWT.SINGLE);
+ sizeCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false));
+ sizeCombo.addListener(SWT.Modify, this);
+
+ for (String value : values) {
+ sizeCombo.add(value);
+ }
+
+ unitCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ unitCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ false, false));
+
+ for (String unit : Constants.extSizes) {
+ unitCombo.add(unit);
+ }
+
+ unitCombo.addListener(SWT.Modify, this);
+
+ }
+
+ public void setText(String text) {
+
+ String[] parsedValue = Util.convertExtString(text);
+
+ sizeCombo.setText(parsedValue[0]);
+
+ unitCombo.select(unitCombo.indexOf(parsedValue[1]));
+
+ }
+
+ public String getText() {
+ return sizeCombo.getText() + unitCombo.getText();
+ }
+
+ public void handleEvent(Event event) {
+
+ if (event.widget == sizeCombo) {
+ if (sizeCombo.indexOf(sizeCombo.getText()) != -1) {
+ unitCombo.setEnabled(false);
+ unitCombo.select(0);
+ } else {
+ unitCombo.setEnabled(true);
+ }
+ }
+
+ notifyListeners(event.type, event);
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeCombo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeText.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeText.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeText.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 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.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Util;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class SizeText extends Composite implements Listener, CSSWidget {
+
+ private Text sizeText;
+
+ private Combo unitCombo;
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public SizeText(Composite parent) {
+
+ super(parent,SWT.None);
+
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = 0;
+
+ setLayout(layout);
+ setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false,
+ 2, 1));
+
+ sizeText = new Text(this, SWT.BORDER | SWT.SINGLE);
+ sizeText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false));
+ sizeText.addListener(SWT.Modify, this);
+
+ unitCombo = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
+ unitCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ false, false));
+
+ for (String unit : Constants.extSizes) {
+
+ unitCombo.add(unit);
+ }
+
+ unitCombo.addListener(SWT.Modify, this);
+
+ }
+
+ public void setText(String text) {
+
+ String[] parsedValue = Util.convertExtString(text);
+
+ sizeText.setText(parsedValue[0]);
+
+ unitCombo.select(unitCombo.indexOf(parsedValue[1]));
+
+ }
+
+ public String getText() {
+ return sizeText.getText() + unitCombo.getText();
+ }
+
+ public void handleEvent(Event event) {
+ notifyListeners(event.type, event);
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/widgets/SizeText.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
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 2009-05-23 09:44:35 UTC (rev 15461)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2009-05-23 09:52:55 UTC (rev 15462)
@@ -21,14 +21,13 @@
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
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;
import org.jboss.tools.jst.web.ui.wizards.messages.WebUIMessages;
/**
@@ -36,7 +35,7 @@
*/
public class NewCSSClassWizard extends Wizard implements INewWizard {
- private CSSClassDescription classDescription = new CSSClassDescription();
+ private CSSClassDescription classDescription = new CSSClassDescription();
// workbench selection when the wizard was started
protected IStructuredSelection selection;
@@ -56,14 +55,13 @@
setWindowTitle(WebUIMessages.WIZARD_WINDOW_TITLE);
}
-
/**
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbench = workbench;
this.selection = selection;
-
+
IResource selectedResource = (IResource) selection.getFirstElement();
if (selectedResource != null) {
if (selectedResource.getType() == IFile.FILE
@@ -73,7 +71,7 @@
}
classDescription.setCssFile(selectedResource);
}
-
+
}
/**
@@ -94,8 +92,8 @@
*/
@Override
public boolean performFinish() {
- editFilePage.saveChanges();
-
+ editFilePage.dialog.save();
+ editFilePage.dialog.releaseResources();
return true;
}
@@ -114,22 +112,26 @@
*/
@Override
public boolean performCancel() {
- editFilePage.cancel();
+ editFilePage.dialog.releaseResources();
return true;
}
-
- public class CSSClassDescription{
+
+ public class CSSClassDescription {
private IResource cssFile;
private String cssClassName;
+
public IResource getCssFile() {
return cssFile;
}
+
public void setCssFile(IResource cssFile) {
this.cssFile = cssFile;
}
+
public String getCssClassName() {
return cssClassName;
}
+
public void setCssClassName(String cssClassName) {
this.cssClassName = cssClassName;
}
@@ -142,7 +144,7 @@
private CSSClassDialog dialog;
- boolean canFinish = false;
+ boolean canFinish = true;
/**
* Constructor for SampleNewWizardPage.
@@ -153,100 +155,67 @@
super("newCSSClassWizard"); //$NON-NLS-1$
setTitle(WebUIMessages.WIZARD_TITLE);
setDescription(WebUIMessages.WIZARD_DESCRIPTION);
-
+
}
/**
* @see IDialogPage#createControl(Composite)
*/
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
+ public void createControl(final Composite parent) {
- // 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() {
- public void throwMessage(MessageDialogEvent event) {
- if (event != null) {
- IStatus status = event.getOperationStatus();
- if (status != null) {
- applyToStatusLine(status);
- }
- if(getWizard().getContainer().getCurrentPage()!=null) {
- getWizard().getContainer().updateButtons();
- }
- }
- }
- });
-
- dialog.createDialog(container);
- setControl(container);
+ final Composite container = new Composite(parent, SWT.NONE);
- if (getWizard().getContainer() instanceof WizardDialog){
- WizardDialog wd = (WizardDialog) getWizard().getContainer();
- wd.addPageChangedListener(new IPageChangedListener(){
+ container.setLayout(new GridLayout(1, true));
+ GridData gridData = new GridData(GridData.FILL,GridData.FILL,true,true);
+ container.setLayoutData(gridData);
- //set console configuration as treeViewer input
+ if (getWizard().getContainer() instanceof WizardDialog) {
+ final WizardDialog wd = (WizardDialog) getWizard()
+ .getContainer();
+ wd.addPageChangedListener(new IPageChangedListener() {
+
+ // set console configuration as treeViewer input
public void pageChanged(PageChangedEvent event) {
- if (event.getSelectedPage() == editFilePage){
- dialog.setCurrentFile((IFile) classDescription.getCssFile());
+ if (event.getSelectedPage() == editFilePage) {
+
+ if (dialog == null) {
+ dialog = new CSSClassDialog(getShell(),
+ (IFile) classDescription.getCssFile(),
+ selection) {
+ protected void handleStatusChanged(
+ IStatus newStatus) {
+ if (newStatus.isOK()
+ && !getStatus().isOK()) {
+ NewCSSClassWizardPage.this
+ .setErrorMessage(null);
+ canFinish = true;
+ } else if (newStatus.getSeverity() == IStatus.ERROR) {
+ NewCSSClassWizardPage.this
+ .setErrorMessage(newStatus
+ .getMessage());
+ canFinish = false;
+ }
+
+ setStatus(newStatus);
+ };
+ };
+ dialog.createControlPane(container);
+ container.layout();
+ }else {
+ dialog.setFile((IFile) classDescription
+ .getCssFile());
+ }
dialog.reinit();
- dialog.addNewStyleClass(classDescription.cssClassName);
+ dialog.addNewClass(classDescription.cssClassName);
}
- }});
+ }
+ });
}
- }
+ setControl(container);
- /**
- * Save page model.
- */
- public void saveChanges() {
-// dialog.saveChanges(true);
- dialog.close();
}
- /**
- * 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);
- canFinish = true;
- break;
- case IStatus.WARNING:
- setErrorMessage(null);
- canFinish = true;
- setMessage(message, WizardPage.WARNING);
- break;
- case IStatus.INFO:
- setErrorMessage(null);
- canFinish = true;
- setMessage(message, WizardPage.INFORMATION);
- break;
- default:
- setErrorMessage(message);
- setMessage(null);
- canFinish = false;
- break;
- }
- }
}
}
15 years, 4 months
JBoss Tools SVN: r15461 - trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 05:44:35 -0400 (Sat, 23 May 2009)
New Revision: 15461
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties
Log:
https://jira.jboss.org/jira/browse/JBIDE-4204
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java 2009-05-23 09:41:32 UTC (rev 15460)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java 2009-05-23 09:44:35 UTC (rev 15461)
@@ -14,6 +14,9 @@
public static String WIZARD_TITLE;
public static String WIZARD_DESCRIPTION;
public static String WIZARD_ERROR_FILE_SELECTION;
+ public static String WIZARD_ERROR_EMPTY_CLASSNAME;
+ public static String WIZARD_ERROR_INVALID_CLASSNAME;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, WebUIMessages.class);
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties 2009-05-23 09:41:32 UTC (rev 15460)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties 2009-05-23 09:44:35 UTC (rev 15461)
@@ -8,4 +8,5 @@
WIZARD_TITLE=CSS Class
WIZARD_DESCRIPTION=Create New CSS Class
WIZARD_ERROR_FILE_SELECTION=No file specified
-
+WIZARD_ERROR_EMPTY_CLASSNAME=Class name is empty
+WIZARD_ERROR_INVALID_CLASSNAME = Class name is not valid
15 years, 4 months
JBoss Tools SVN: r15460 - trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css.
by jbosstools-commits@lists.jboss.org
Author: sdzmitrovich
Date: 2009-05-23 05:41:32 -0400 (Sat, 23 May 2009)
New Revision: 15460
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4204
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java 2009-05-22 19:12:48 UTC (rev 15459)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java 2009-05-23 09:41:32 UTC (rev 15460)
@@ -34,6 +34,7 @@
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSSelectorValidator;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.FileExtensionFilter;
import org.jboss.tools.jst.web.ui.wizards.css.NewCSSClassWizard.CSSClassDescription;
import org.jboss.tools.jst.web.ui.wizards.messages.WebUIMessages;
@@ -84,7 +85,6 @@
selectFileText = new Text(container, SWT.SINGLE | SWT.BORDER);
selectFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
selectFileText.setFont(parent.getFont());
-
Button selectFileButton = new Button(container, SWT.NONE);
selectFileButton.setText(WebUIMessages.FILE_SELECT_BUTTON);
@@ -113,8 +113,7 @@
}
return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
IStatus.ERROR,
- WebUIMessages.WIZARD_ERROR_FILE_SELECTION,
- null);
+ WebUIMessages.WIZARD_ERROR_FILE_SELECTION, null);
}
});
if (classDescription.getCssFile() != null) {
@@ -162,7 +161,21 @@
public void modifyText(ModifyEvent e) {
classDescription.setCssClassName(classNameText.getText());
+
classDescription.setCssFile(getResource(selectFileText.getText()));
+
+ if (getCssFile(selectFileText.getText()) == null) {
+ setErrorMessage(WebUIMessages.WIZARD_ERROR_FILE_SELECTION);
+ } else if ((classNameText.getText() == null)
+ || (classNameText.getText().length() == 0)) {
+ setErrorMessage(WebUIMessages.WIZARD_ERROR_EMPTY_CLASSNAME);
+ } else if (!CSSSelectorValidator.getInstance().isValidSelector(
+ classNameText.getText())) {
+ setErrorMessage(WebUIMessages.WIZARD_ERROR_INVALID_CLASSNAME);
+ } else {
+ setErrorMessage(null);
+ }
+
getContainer().updateButtons();
}
15 years, 4 months
JBoss Tools SVN: r15458 - in trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml: internal and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2009-05-22 15:11:21 -0400 (Fri, 22 May 2009)
New Revision: 15458
Removed:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/internal/ui/
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java
Log:
Clean code
Modified: trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java 2009-05-22 19:09:05 UTC (rev 15457)
+++ trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java 2009-05-22 19:11:21 UTC (rev 15458)
@@ -14,17 +14,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
15 years, 4 months