Author: yzhishko
Date: 2010-03-04 10:18:43 -0500 (Thu, 04 Mar 2010)
New Revision: 20671
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_class.gif
trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_sheet.gif
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSSelectorPartComposite.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSStyleClassSelector.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTableDragListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTreeDragListener.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSJSPRecognizer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTableModel.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTreeModel.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorUtils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSTreeNode.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorFilter.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableContentProvider.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableViewer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTransfer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeContentProvider.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeLabelProvider.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeViewer.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/StyleAttributes.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3288 ,
https://jira.jboss.org/jira/browse/JBIDE-5965 ,
https://jira.jboss.org/jira/browse/JBIDE-5966 the first version of CSS Style Class
selector
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_class.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_class.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_sheet.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/images/cssdialog/style_sheet.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
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 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -105,6 +105,7 @@
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 CSS_SELECTOR_TITLE;
public static String JspContentAssistProcessor_CloseELExpression;
public static String JspContentAssistProcessor_CloseELExpressionInfo;
public static String JspContentAssistProcessor_NewELExpression;
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 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2010-03-04
15:18:43 UTC (rev 20671)
@@ -2,6 +2,7 @@
CSS_STYLE_CLASS_EDITOR_DESCRIPTION=Create New CSS Class
CSS_STYLE_CLASS_EDITOR_TITLE=CSS Class
CSS_STYLE_EDITOR_TITLE=CSS Style
+CSS_SELECTOR_TITLE=CSS Selector
CSS_EMPTY_FILE_PATH_MESSAGE=Choose any CSS file
CSS_EMPTY_STYLE_CLASS_MESSAGE=Style class field is empty
CSS_INVALID_STYLE_PROPERTY=Invalid Style class property has been entered.
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 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -37,6 +37,7 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSStyleDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.CSSConstants;
import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.CSSStyleClassSelector;
/**
* @author Kabanovich Cell Editor for JSP attributes, of which values can be
@@ -132,17 +133,17 @@
context.put("value", value); //$NON-NLS-1$
attributeName = attributeName.toLowerCase();
-// if (attributeName.equalsIgnoreCase(CSSConstants.CLASS)
-// || attributeName.endsWith(CSSConstants.CLASS.toLowerCase())) {
-// CSSClassDialog dialog = new CSSClassDialog(cellEditorWindow.getShell(),
null, false);
-// dialog.setCurrentStyleClass(value);
-//
-// if (dialog.open() == Window.OK) {
-// externalEditing = false;
-//
-// return dialog.getSelectorName();
-// }
-// } else
+ if (attributeName.equalsIgnoreCase(CSSConstants.CLASS)
+ || attributeName.endsWith(CSSConstants.CLASS.toLowerCase())) {
+ CSSStyleClassSelector dialog = new
CSSStyleClassSelector(cellEditorWindow.getShell());
+ dialog.setCurrentStyleClass(value);
+
+ if (dialog.open() == Window.OK) {
+ externalEditing = false;
+
+ return dialog.getCSSStyleClasses();
+ }
+ } else
if (attributeName.equalsIgnoreCase(CSSConstants.STYLE)
|| attributeName.endsWith(CSSConstants.STYLE.toLowerCase())) {
CSSStyleDialog dialog = new CSSStyleDialog(cellEditorWindow.getShell(),
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 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/AbstractCSSDialog.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -17,7 +17,6 @@
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;
@@ -92,18 +91,7 @@
}
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));
-
+
getStyleAttributes().addChangeListener(new IChangeListener() {
public void handleChange(ChangeEvent event) {
@@ -122,7 +110,18 @@
handleStatusChanged((IStatus) event.diff.getNewValue());
}
});
+
+ // 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));
+
return dialogContainer;
}
@@ -226,7 +225,7 @@
* @return String html text representation
*/
public String generateBrowserPage() {
- StringBuffer html = new StringBuffer(Constants.OPEN_DIV_TAG);
+ StringBuffer html = new StringBuffer("<style>span{"); //$NON-NLS-1$
for (Map.Entry<String, String> styleItem : getStyleAttributes()
.entrySet()) {
@@ -235,7 +234,7 @@
+ styleItem.getValue() + Constants.SEMICOLON);
}
- html.append("\">" + getPreviewContent() + Constants.CLOSE_DIV_TAG);
//$NON-NLS-1$
+ html.append("}</style><span>" + getPreviewContent() +
"</span>"); //$NON-NLS-1$ //$NON-NLS-2$
return html.toString();
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/Constants.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -61,7 +61,9 @@
public static final String IMAGE_LEFT_FILE_LOCATION =
"images/cssdialog/left.gif"; //$NON-NLS-1$
public static final String IMAGE_RIGHT_FILE_LOCATION =
"images/cssdialog/right.gif"; //$NON-NLS-1$
public static final String IMAGE_SAMPLE_FILE_LOCATION =
"images/cssdialog/sample.gif"; //$NON-NLS-1$
-
+ public static final String IMAGE_STYLE_SHEET_LOCATION =
"images/cssdialog/style_sheet.gif"; //$NON-NLS-1$
+ public static final String IMAGE_STYLE_CLASS_LOCATION =
"images/cssdialog/style_class.gif"; //$NON-NLS-1$
+
public static final int FIRST_COLUMN = 0;
public static final int SECOND_COLUMN = 1;
Modified:
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/common/StyleAttributes.java 2010-03-04
14:47:34 UTC (rev 20670)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/common/StyleAttributes.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -44,6 +44,10 @@
public String put(String name, String value) {
return (String) attributeMap.put(name.toLowerCase(), value);
}
+
+ public void putAll(Map<String, String> t) {
+ attributeMap.putAll(t);
+ }
/**
* Remove attribute with the given name.
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSSelectorPartComposite.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSSelectorPartComposite.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSSelectorPartComposite.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,430 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetAdapter;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+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.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+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;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSJSPRecognizer;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSSelectorTableModel;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSSelectorTreeModel;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSTreeNode;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers.CSSSelectorFilter;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers.CSSSelectorTableViewer;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers.CSSSelectorTreeViewer;
+import org.w3c.dom.css.CSSRule;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorPartComposite extends Composite implements
+ SelectionListener {
+
+ private static final int LIST_HEIGHT = 500;
+ private static final int BUTTOND_WIDTH = 50;
+ private static final int LIST_WIDTH = 175;
+
+ /** Existing font family */
+ Composite buttonsContainer;
+ private Button rightButton;
+ private Button leftButton;
+ private String setClasses;
+ private CSSSelectorTreeViewer allCSSStyleClassViewer;
+ private CSSSelectorTableViewer selectedClassesTableViewer;
+ private Map<String, Map<String, String>> allCSSClassStyles;
+ private StyleAttributes styleAttributes;
+ private CSSSelectorTreeModel styleClassTreeModel;
+ private CSSSelectorFilter filter;
+
+ public CSSSelectorPartComposite(StyleAttributes styleAttributes,
+ Composite parentComposite, String setClasses) {
+ super(parentComposite, SWT.NONE);
+ this.setClasses = setClasses;
+ this.styleAttributes = styleAttributes;
+ creatSelectorPart();
+ }
+
+ private void creatSelectorPart() {
+ initControls();
+ createLayout();
+ initListeners();
+ initDND();
+ initDefaultContent();
+ }
+
+ private void initDefaultContent() {
+ IEditorPart editorPart = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (!(editorPart instanceof JSPMultiPageEditor)) {
+ return;
+ }
+ CSSJSPRecognizer recognizer = new CSSJSPRecognizer(
+ (JSPMultiPageEditor) editorPart);
+ if (recognizer.parseCSS() == CSSJSPRecognizer.VOID_RESULT) {
+ return;
+ }
+ styleClassTreeModel = recognizer.getCssStyleClassTreeModel();
+ allCSSClassStyles = recognizer.getCSSStyleMap();
+ allCSSStyleClassViewer.setModel(styleClassTreeModel);
+ String[] selectedClasses = parseSetClasses();
+ selectedClassesTableViewer.setModel(new CSSSelectorTableModel(
+ selectedClasses));
+ updateStyles();
+ }
+
+ private void initDND() {
+ Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
+
+ allCSSStyleClassViewer.addDragSupport(DND.DROP_MOVE, types,
+ new CSSTreeDragListener(this, allCSSStyleClassViewer,
+ selectedClassesTableViewer));
+
+ selectedClassesTableViewer.addDragSupport(DND.DROP_MOVE, types,
+ new CSSTableDragListener(this, allCSSStyleClassViewer,
+ selectedClassesTableViewer));
+
+ allCSSStyleClassViewer.addDropSupport(DND.DROP_MOVE, types, new DropTargetAdapter(){
+ @Override
+ public void drop(DropTargetEvent event) {
+ if (event.data == null ||
event.data.equals(CSSSelectorTreeViewer.CSS_SELECTOR_TREE_VIWER_ID)) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ }
+ });
+
+ selectedClassesTableViewer.addDropSupport(DND.DROP_MOVE, types, new
DropTargetAdapter(){
+ @Override
+ public void drop(DropTargetEvent event) {
+ if (event.data == null ||
event.data.equals(CSSSelectorTableViewer.CSS_SELECTOR_TABLE_VIWER_ID)) {
+ event.detail = DND.DROP_NONE;
+ return;
+ }
+ }
+ });
+
+ }
+
+ private void initListeners() {
+
+ final Tree tree = allCSSStyleClassViewer.getTree();
+ final Table table = selectedClassesTableViewer.getTable();
+ allCSSStyleClassViewer
+ .addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+ TreeItem[] selectedItems = tree.getSelection();
+ if (selectedItems != null && selectedItems.length > 0) {
+ TreeItem selectedItem = selectedItems[selectedItems.length - 1];
+ CSSTreeNode treeNode = (CSSTreeNode) selectedItem
+ .getData();
+ if (!(treeNode.getCssResource() instanceof CSSRule)) {
+ if (allCSSStyleClassViewer
+ .getExpandedState(treeNode)) {
+ allCSSStyleClassViewer.collapseToLevel(
+ treeNode, 1);
+ return;
+ }
+ allCSSStyleClassViewer.expandToLevel(treeNode,
+ 1);
+ return;
+ }
+ selectedClassesTableViewer.add(treeNode.toString());
+ updateStyles();
+ }
+ }
+ });
+
+ tree.addMouseListener(new MouseAdapter() {
+
+ public void mouseDown(MouseEvent e) {
+ if (tree.getSelectionCount() > 0) {
+ selectedClassesTableViewer.getTable().deselectAll();
+ leftButton.setEnabled(false);
+ rightButton.setEnabled(true);
+ }
+ }
+ });
+
+ selectedClassesTableViewer
+ .addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+ TableItem[] selectedItems = table.getSelection();
+ if (selectedItems != null && selectedItems.length > 0) {
+ TableItem selectedItem = selectedItems[selectedItems.length - 1];
+ selectedClassesTableViewer.remove(selectedItem
+ .getData());
+ updateStyles();
+ }
+ }
+
+ });
+
+ table.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if (table.getSelectionCount() > 0) {
+ tree.deselectAll();
+ rightButton.setEnabled(false);
+ leftButton.setEnabled(true);
+ }
+ }
+
+ });
+
+ rightButton.addSelectionListener(this);
+ leftButton.addSelectionListener(this);
+ }
+
+ private void initControls() {
+ allCSSStyleClassViewer = new CSSSelectorTreeViewer(this, SWT.MULTI
+ | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+ filter = new CSSSelectorFilter();
+ allCSSStyleClassViewer.addFilter(filter);
+ buttonsContainer = new Composite(this, SWT.NONE);
+ rightButton = new Button(buttonsContainer, SWT.PUSH);
+ leftButton = new Button(buttonsContainer, SWT.PUSH);
+ selectedClassesTableViewer = new CSSSelectorTableViewer(this, SWT.MULTI
+ | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ rightButton.setToolTipText(JstUIMessages.ADD_FONT_FAMILY_TIP);
+ ImageDescriptor rightDesc = JspEditorPlugin
+ .getImageDescriptor(Constants.IMAGE_RIGHT_FILE_LOCATION);
+ Image rightImage = rightDesc.createImage();
+ rightButton.setImage(rightImage);
+ rightButton.setEnabled(false);
+ rightButton.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Button button = (Button) e.getSource();
+ button.getImage().dispose();
+ }
+ });
+
+ leftButton.setToolTipText(JstUIMessages.REMOVE_FONT_FAMILY_TIP);
+
+ ImageDescriptor leftDesc = JspEditorPlugin
+ .getImageDescriptor(Constants.IMAGE_LEFT_FILE_LOCATION);
+ Image leftImage = leftDesc.createImage();
+ leftButton.setImage(leftImage);
+ leftButton.setEnabled(false);
+ leftButton.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ Button button = (Button) e.getSource();
+ button.getImage().dispose();
+ }
+ });
+ }
+
+ private String[] parseSetClasses() {
+ if (setClasses == null || setClasses.length() == 0) {
+ return new String[0];
+ }
+ StringTokenizer stringTokenizer = new StringTokenizer(
+ setClasses.trim(), " ", false); //$NON-NLS-1$
+ java.util.List<String> list = new ArrayList<String>(0);
+ while (stringTokenizer.hasMoreTokens()) {
+ String token = stringTokenizer.nextToken();
+ list.add(token.trim());
+ }
+ return list.toArray(new String[0]);
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ Object ob = e.getSource();
+ if (ob.equals(leftButton)) {
+ handleLeftButtonSelection();
+ } else if (ob.equals(rightButton)) {
+ handleRightButtonSelection();
+ } else if (ob.equals(allCSSStyleClassViewer.getTree())) {
+ selectedClassesTableViewer.getTable().deselectAll();
+ leftButton.setEnabled(false);
+ rightButton.setEnabled(true);
+ } else if (ob.equals(selectedClassesTableViewer.getTable())) {
+ allCSSStyleClassViewer.getTree().deselectAll();
+ rightButton.setEnabled(false);
+ leftButton.setEnabled(true);
+ }
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ Object ob = e.getSource();
+ if (ob.equals(leftButton)) {
+ handleLeftButtonSelection();
+ } else if (ob.equals(rightButton)) {
+ handleRightButtonSelection();
+ }
+ }
+
+ private void handleLeftButtonSelection() {
+ TableItem[] selectedItems = selectedClassesTableViewer.getTable()
+ .getSelection();
+
+ for (int i = 0; i < selectedItems.length; i++) {
+ selectedClassesTableViewer.remove(selectedItems[i].getData());
+ }
+ updateStyles();
+ }
+
+ private void handleRightButtonSelection() {
+ TreeItem[] selectedItems = allCSSStyleClassViewer.getTree()
+ .getSelection();
+ if (selectedItems != null && selectedItems.length > 0) {
+ for (int i = 0; i < selectedItems.length; i++) {
+ TreeItem item = selectedItems[i];
+ if (!(((CSSTreeNode) item.getData()).getCssResource() instanceof CSSRule)) {
+ continue;
+ }
+ selectedClassesTableViewer.add(((CSSTreeNode) item.getData())
+ .toString());
+ }
+ }
+ updateStyles();
+ }
+
+ private void createLayout() {
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ setLayout(gridLayout);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ setLayoutData(gridData);
+
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.heightHint = LIST_HEIGHT;
+ gridData.widthHint = LIST_WIDTH;
+ allCSSStyleClassViewer.getTree().setLayoutData(gridData);
+
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.heightHint = LIST_HEIGHT;
+ gridData.widthHint = LIST_WIDTH;
+ selectedClassesTableViewer.getTable().setLayoutData(gridData);
+
+ final GridLayout btmContGridLayout = new GridLayout();
+ btmContGridLayout.numColumns = 1;
+ buttonsContainer.setLayout(btmContGridLayout);
+
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.widthHint = BUTTOND_WIDTH;
+ rightButton.setLayoutData(gridData);
+
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.widthHint = BUTTOND_WIDTH;
+ leftButton.setLayoutData(gridData);
+
+ }
+
+ void updateStyles() {
+ String[] selectedItems = getItemsFromSelectedTable();
+ styleAttributes.clear();
+ if (filter == null) {
+ filter = new CSSSelectorFilter();
+ allCSSStyleClassViewer.addFilter(filter);
+ }
+ filter.removeAllFilters();
+ if (selectedItems != null && selectedItems.length != 0) {
+ selectedItems = getSortedStyleClasses(selectedItems);
+ for (int i = 0; i < selectedItems.length; i++) {
+ if (selectedItems[i] != null) {
+ styleAttributes.putAll(allCSSClassStyles
+ .get(selectedItems[i]));
+ filter.addFilterName(selectedItems[i]);
+ }
+ }
+ }
+ allCSSStyleClassViewer.refresh();
+ allCSSStyleClassViewer.getTree().deselectAll();
+ selectedClassesTableViewer.getTable().deselectAll();
+ rightButton.setEnabled(false);
+ leftButton.setEnabled(false);
+ }
+
+ public String getCSSStyleClasses() {
+ StringBuilder stringBuilder = new StringBuilder(""); //$NON-NLS-1$
+ String[] selectedItems = getItemsFromSelectedTable();
+ if (selectedItems != null && selectedItems.length != 0) {
+ for (int i = 0; i < selectedItems.length - 1; i++) {
+ stringBuilder.append(selectedItems[i] + " "); //$NON-NLS-1$
+ }
+ stringBuilder.append(selectedItems[selectedItems.length - 1]);
+ }
+ return stringBuilder.toString();
+ }
+
+ private String[] getSortedStyleClasses(String[] unsortedClasses) {
+ String[] sortedStyleClasses = new String[unsortedClasses.length];
+ if (allCSSClassStyles != null) {
+ Set<String> keySet = allCSSClassStyles.keySet();
+ int iter = 0;
+ for (Iterator<String> iterator = keySet.iterator(); iterator
+ .hasNext();) {
+ String styleClassName = iterator.next();
+ for (int i = 0; i < unsortedClasses.length; i++) {
+ if (unsortedClasses[i].equals(styleClassName)) {
+ sortedStyleClasses[iter] = styleClassName;
+ iter++;
+ continue;
+ }
+ }
+ }
+ }
+ return sortedStyleClasses;
+ }
+
+ private String[] getItemsFromSelectedTable() {
+ TableItem[] selectedTableItems = selectedClassesTableViewer.getTable()
+ .getItems();
+ java.util.List<String> selectedItemsList = new ArrayList<String>(0);
+ if (selectedTableItems != null) {
+ for (int i = 0; i < selectedTableItems.length; i++) {
+ selectedItemsList.add((String) selectedTableItems[i].getData());
+ }
+ }
+ return selectedItemsList.toArray(new String[0]);
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSStyleClassSelector.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSStyleClassSelector.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSStyleClassSelector.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector;
+
+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.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.outline.cssdialog.AbstractCSSDialog;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSStyleClassSelector extends AbstractCSSDialog{
+
+ private String currentCSSStyleClass;
+ private CSSSelectorPartComposite cssClassComposite;
+ private String selectesCSSStylesClasses;
+
+ public CSSStyleClassSelector(Shell shell) {
+ super(shell);
+ setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX
+ | SWT.APPLICATION_MODAL);
+ }
+
+ @Override
+ 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));
+ cssClassComposite = createCSSClassComposite(controlsContainer);
+ return controlsContainer;
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = (Composite)super.createContents(parent);
+ return composite;
+ }
+
+ private CSSSelectorPartComposite createCSSClassComposite(Composite parent) {
+ return new CSSSelectorPartComposite(getStyleAttributes(), parent,
currentCSSStyleClass);
+ }
+
+ public void setCurrentStyleClass(String value) {
+ currentCSSStyleClass = value;
+ }
+
+ public String getCSSStyleClasses (){
+ return selectesCSSStylesClasses;
+ }
+
+ @Override
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == OK) {
+ selectesCSSStylesClasses = cssClassComposite.getCSSStyleClasses();
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(JstUIMessages.CSS_SELECTOR_TITLE);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ setTitle(JstUIMessages.CSS_SELECTOR_TITLE);
+ return super.createDialogArea(parent);
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTableDragListener.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTableDragListener.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTableDragListener.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers.CSSSelectorTableViewer;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("unused")
+public class CSSTableDragListener implements DragSourceListener {
+
+ private Table table;
+ private Tree tree;
+ private CSSSelectorPartComposite parent;
+ private TreeViewer treeViewer;
+ private TableViewer tableViewer;
+
+ public CSSTableDragListener (CSSSelectorPartComposite parent, TreeViewer treeViewer,
TableViewer tableViewer){
+ this.table = tableViewer.getTable();
+ this.tree = treeViewer.getTree();
+ this.treeViewer = treeViewer;
+ this.tableViewer = tableViewer;
+ this.parent = parent;
+ }
+
+ public void dragStart(DragSourceEvent event) {
+ event.doit = table.getSelectionCount() > 0;
+ }
+
+ public void dragSetData(DragSourceEvent event) {
+ List<String> selectedItems = new ArrayList<String>(0);
+ TableItem[] selectedTableItems = table.getSelection();
+ if (selectedTableItems != null) {
+ for (int i = 0; i < selectedTableItems.length; i++) {
+ selectedItems.add(selectedTableItems[i].getData()
+ .toString());
+ }
+ }
+ event.data = CSSSelectorTableViewer.CSS_SELECTOR_TABLE_VIWER_ID;
+ }
+
+ public void dragFinished(DragSourceEvent event) {
+ if (event.detail == DND.DROP_MOVE) {
+ TableItem[] selectedTableItems = table.getSelection();
+ if (selectedTableItems != null && selectedTableItems.length > 0) {
+ for (int i = 0; i < selectedTableItems.length; i++) {
+ tableViewer.remove(selectedTableItems[i].getData());
+ }
+ }
+ parent.updateStyles();
+ }
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTreeDragListener.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTreeDragListener.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/CSSTreeDragListener.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSTreeNode;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers.CSSSelectorTreeViewer;
+import org.w3c.dom.css.CSSRule;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("unused")
+public class CSSTreeDragListener implements DragSourceListener {
+
+ private Table table;
+ private Tree tree;
+ private CSSSelectorPartComposite parent;
+ private TreeViewer treeViewer;
+ private TableViewer tableViewer;
+
+ public CSSTreeDragListener (CSSSelectorPartComposite parent, TreeViewer treeViewer,
TableViewer tableViewer){
+ this.table = tableViewer.getTable();
+ this.tree = treeViewer.getTree();
+ this.treeViewer = treeViewer;
+ this.tableViewer = tableViewer;
+ this.parent = parent;
+ }
+
+
+ public void dragStart(DragSourceEvent event) {
+ event.doit = tree.getSelectionCount() > 0;
+ }
+
+ public void dragSetData(DragSourceEvent event) {
+ List<String> selectedItems = new ArrayList<String>(0);
+ TreeItem[] selectedTreeItems = tree.getSelection();
+ if (selectedTreeItems != null) {
+ for (int i = 0; i < selectedTreeItems.length; i++) {
+ selectedItems.add(selectedTreeItems[i].getData()
+ .toString());
+ }
+ }
+
+ event.data = CSSSelectorTreeViewer.CSS_SELECTOR_TREE_VIWER_ID;
+ }
+
+ public void dragFinished(DragSourceEvent event) {
+ if (event.detail == DND.DROP_MOVE) {
+ List<String> selectedItems = new ArrayList<String>(0);
+ TreeItem[] selectedTreeItems = tree.getSelection();
+ if (selectedTreeItems != null) {
+ for (int i = 0; i < selectedTreeItems.length; i++) {
+ if (((CSSTreeNode) selectedTreeItems[i].getData())
+ .getCssResource() instanceof CSSRule) {
+ selectedItems.add(selectedTreeItems[i]
+ .getData().toString());
+ }
+ }
+ }
+ for (int i = 0; i < selectedItems.size(); i++) {
+ tableViewer.add(selectedItems.get(i));
+ }
+ parent.updateStyles();
+ }
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSJSPRecognizer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSJSPRecognizer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSJSPRecognizer.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.model;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
+import org.w3c.dom.css.CSSRule;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class CSSJSPRecognizer {
+
+ private JSPMultiPageEditor jspMultiPageEditor;
+
+ public static final int OK = 0;
+ public static final int VOID_RESULT = 1;
+ private List<CSSStyleSheet> styleSheets;
+ private List<CSSStyleSheetDescriptor> styleSheetDescriptors;
+ private List<CSSRuleList> cssRuleLists;
+ private CSSRule[] cssRules;
+
+ public CSSJSPRecognizer(JSPMultiPageEditor jspMultiPageEditor) {
+ this.jspMultiPageEditor = jspMultiPageEditor;
+ }
+
+ private List<CSSRuleList> extractCSSRulesLists() {
+ ICSSContainerSupport cssContainerSupport = null;
+ ELContext context = PageContextFactory.createPageContext(getFile());
+ if (!(context instanceof ICSSContainerSupport)) {
+ return null;
+ }
+ cssContainerSupport = (ICSSContainerSupport) context;
+ java.util.List<CSSStyleSheetDescriptor> descrs = cssContainerSupport
+ .getCSSStyleSheetDescriptors();
+ if (descrs == null || descrs.size() == 0) {
+ return null;
+ }
+ styleSheetDescriptors = descrs;
+ java.util.List<CSSRuleList> cssRuleLists = new ArrayList<CSSRuleList>(0);
+ styleSheets = new ArrayList<CSSStyleSheet>(0);
+ for (int i = 0; i < descrs.size(); i++) {
+ styleSheets.add(descrs.get(i).sheet);
+ cssRuleLists.add(descrs.get(i).sheet.getCssRules());
+ }
+ if (cssRuleLists.size() == 0) {
+ return null;
+ }
+ return cssRuleLists;
+ }
+
+ private IFile getFile() {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ try {
+ smw.init(getDocument());
+ return smw.getFile();
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ private IDocument getDocument() {
+ IDocument document = jspMultiPageEditor.getSourceEditor()
+ .getTextViewer().getDocument();
+ return document;
+ }
+
+ private CSSRule[] extractCSSRules(java.util.List<CSSRuleList> cssRuleLists) {
+ if (cssRuleLists == null) {
+ return null;
+ }
+ java.util.List<CSSRule> cssRules = new ArrayList<CSSRule>(0);
+ for (int i = 0; i < cssRuleLists.size(); i++) {
+ CSSRuleList cssRuleList = cssRuleLists.get(i);
+ for (int j = 0; j < cssRuleList.getLength(); j++) {
+ cssRules.add(cssRuleList.item(j));
+ }
+ }
+ if (cssRules.size() == 0) {
+ return null;
+ }
+ return cssRules.toArray(new CSSRule[0]);
+ }
+
+ public Map<String, Map<String, String>> getCSSStyleMap(
+ CSSRule[] cssRules) {
+ if (cssRules == null) {
+ return null;
+ }
+ Map<String, Map<String, String>> styleMap = new LinkedHashMap<String,
Map<String, String>>(
+ 0);
+ for (int i = 0; i < cssRules.length; i++) {
+ ICSSStyleRule styleRule = (ICSSStyleRule) cssRules[i];
+ String styleClassSelector = styleRule.getSelectorText();
+ String[] selectors = CSSSelectorUtils.parseSelectorName(styleClassSelector);
+ for (int j = 0; j < selectors.length; j++) {
+ String styleClassName = selectors[j];
+ ICSSNodeList cssNodeList = styleRule.getChildNodes();
+ if (cssNodeList == null) {
+ continue;
+ }
+ Map<String, String> attrsMap = new LinkedHashMap<String, String>(0);
+ for (int k = 0; k < cssNodeList.getLength(); k++) {
+ ICSSStyleDeclaration styleDeclaration = (ICSSStyleDeclaration) cssNodeList.item(k);
+ ICSSNodeList attrsList = styleDeclaration.getChildNodes();
+ if (attrsList == null) {
+ continue;
+ }
+ for (int l = 0; l < attrsList.getLength(); l++) {
+ ICSSStyleDeclItem styleItem = (ICSSStyleDeclItem) attrsList.item(l);
+ attrsMap.put(styleItem.getPropertyName(), styleItem.getCSSValueText());
+ }
+ }
+ Map<String, String> attrsForCSSStyle = styleMap.get(styleClassName);
+ if (attrsForCSSStyle == null) {
+ styleMap.put(styleClassName, attrsMap);
+ } else {
+ attrsForCSSStyle.putAll(attrsMap);
+ styleMap.remove(styleClassName);
+ styleMap.put(styleClassName, attrsForCSSStyle);
+ }
+ }
+ }
+ return styleMap;
+ }
+
+ public CSSSelectorTreeModel getCssStyleClassTreeModel(CSSStyleSheetDescriptor[]
cssSheets){
+ if (cssSheets != null) {
+ return new CSSSelectorTreeModel(cssSheets);
+ }
+ return null;
+ }
+
+ public CSSSelectorTreeModel getCssStyleClassTreeModel(){
+ return getCssStyleClassTreeModel(styleSheetDescriptors.toArray(new
CSSStyleSheetDescriptor[0]));
+ }
+
+ public Map<String, Map<String, String>> getCSSStyleMap() {
+ return getCSSStyleMap(this.cssRules);
+ }
+
+ public int parseCSS(){
+ this.cssRuleLists = extractCSSRulesLists();
+ this.cssRules = extractCSSRules(this.cssRuleLists);
+ if (cssRules != null && cssRules.length != 0) {
+ return OK;
+ }
+ return VOID_RESULT;
+ }
+
+ public CSSStyleSheet[] getStyleSheets() {
+ return styleSheets.toArray(new CSSStyleSheet[0]);
+ }
+
+ public CSSRule[] getCssRules() {
+ return cssRules;
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTableModel.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTableModel.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTableModel.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTableModel {
+
+ private List<String> containerList = new ArrayList<String>(0);
+
+ public List<String> getContainerList() {
+ return containerList;
+ }
+
+ public CSSSelectorTableModel(String... classNames) {
+ initModel(classNames);
+ }
+
+ private void initModel(String... classNames){
+ if (classNames != null) {
+ for (int i = 0; i < classNames.length; i++) {
+ containerList.add(classNames[i]);
+ }
+ }
+ }
+
+
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTreeModel.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTreeModel.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorTreeModel.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.model;
+
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
+import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
+import org.w3c.dom.css.CSSRule;
+import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+@SuppressWarnings("restriction")
+public class CSSSelectorTreeModel {
+
+ private CSSStyleSheetDescriptor[] cssSheets;
+ private CSSTreeNode invisibleRoot;
+
+ public CSSSelectorTreeModel(CSSStyleSheet[] cssSheets) {
+ }
+
+ public CSSSelectorTreeModel(CSSStyleSheetDescriptor[] cssSheets) {
+ this.cssSheets = cssSheets;
+ setInvisibleRoot(new CSSTreeNode("")); //$NON-NLS-1$
+ initModel(this.cssSheets);
+ }
+
+ private void initModel(CSSStyleSheetDescriptor[] cssStyleSheets){
+ for (int i = 0; i < cssStyleSheets.length; i++) {
+ CSSStyleSheet styleSheet = cssStyleSheets[i].sheet;
+ CSSTreeNode parentSheet = new CSSTreeNode(cssStyleSheets[i].source);
+ parentSheet.setStyleSheetSource(parentSheet.toString());
+ invisibleRoot.addChild(parentSheet);
+ parentSheet.setCssResource(styleSheet);
+ CSSRuleList cssRuleList = styleSheet.getCssRules();
+ for (int j = 0; j < cssRuleList.getLength(); j++) {
+ CSSRule cssRule = cssRuleList.item(j);
+ String[] selectors =
CSSSelectorUtils.parseSelectorName(((ICSSStyleRule)cssRule).getSelectorText());
+ for (int k = 0; k < selectors.length; k++) {
+ CSSTreeNode ruleNode = new CSSTreeNode(selectors[k]);
+ ruleNode.setCssResource(cssRule);
+ ruleNode.setStyleSheetSource(cssStyleSheets[i].source);
+ parentSheet.addChild(ruleNode);
+ }
+ }
+ }
+ }
+
+ public void setInvisibleRoot(CSSTreeNode invisibleRoot) {
+ this.invisibleRoot = invisibleRoot;
+ }
+
+ public CSSTreeNode getInvisibleRoot() {
+ return invisibleRoot;
+ }
+
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorUtils.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorUtils.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSSelectorUtils.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorUtils {
+
+ private static String filterName(String className){
+ className = className.trim();
+ if (className.indexOf(' ') > -1) {
+ return null;
+ }
+ if (className.indexOf('.')==className.lastIndexOf('.')) {
+ if (className.indexOf('.') == 0) {
+ return className.substring(className.indexOf('.')+1);
+ }
+ }
+ return null;
+ }
+
+ public static String[] parseSelectorName(String selectorText){
+ List<String> selectors = new ArrayList<String>(0);
+ StringTokenizer tokenizer = new StringTokenizer(selectorText, ",", false);
//$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String selectorName = tokenizer.nextToken();
+ selectorName = filterName(selectorName);
+ if (selectorName != null) {
+ selectors.add(selectorName);
+ }
+ }
+ return selectors.toArray(new String[0]);
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSTreeNode.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSTreeNode.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/model/CSSTreeNode.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSTreeNode {
+
+ private String name;
+ private List<CSSTreeNode> children = new ArrayList<CSSTreeNode>(0);
+ private CSSTreeNode parent;
+ private Object cssResource;
+ private String styleSheetSource;
+
+ public CSSTreeNode(String n) {
+ name = n;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public CSSTreeNode addChild(CSSTreeNode child) {
+ children.add(child);
+ child.parent = this;
+ return this;
+ }
+
+ public List<CSSTreeNode> getChildren() {
+ return children;
+ }
+
+ public boolean hasChildren() {
+ return children.size() > 0;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public void setCssResource(Object cssResource) {
+ this.cssResource = cssResource;
+ }
+
+ public Object getCssResource() {
+ return cssResource;
+ }
+
+ public void setStyleSheetSource(String source){
+ styleSheetSource = source;
+ }
+
+ public String getStyleSheetSource(){
+ return styleSheetSource;
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorFilter.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorFilter.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorFilter.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSTreeNode;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorFilter extends ViewerFilter{
+
+ private Set<String> filterNames = new HashSet<String>(0);
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (filterNames.contains(((CSSTreeNode)element).toString())) {
+ return false;
+ }
+ return true;
+ }
+
+ public void removeFilterName(String name){
+ filterNames.remove(name);
+ }
+
+ public void addFilterName(String name){
+ filterNames.add(name);
+ }
+
+ public void removeAllFilters(){
+ filterNames.clear();
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableContentProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableContentProvider.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableContentProvider.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.jboss.tools.common.model.ui.attribute.IListContentProvider;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTableContentProvider implements IListContentProvider{
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object inputElement) {
+ return ((List<String>)inputElement).toArray();
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableViewer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableViewer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTableViewer.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import
org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSSelectorTableModel;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTableViewer extends TableViewer{
+
+ public final static String CSS_SELECTOR_TABLE_VIWER_ID =
"css_selector_table_viwer"; //$NON-NLS-1$
+ private final static ImageDescriptor CSS_STYLE_CLASS_DESCR =
JspEditorPlugin.getImageDescriptor(Constants.IMAGE_STYLE_CLASS_LOCATION);
+
+ public CSSSelectorTableViewer(Composite parent, int style) {
+ super(parent, style);
+ setContentProvider(new CSSSelectorTableContentProvider());
+ setLabelProvider(new LabelProvider(){
+ @Override
+ public Image getImage(Object element) {
+ return CSS_STYLE_CLASS_DESCR.createImage();
+ }
+ });
+ }
+
+ public void setModel(CSSSelectorTableModel model){
+ setInput(model.getContainerList());
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTransfer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTransfer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTransfer.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,94 @@
+package org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.viewers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.TransferData;
+
+public class CSSSelectorTransfer extends ByteArrayTransfer {
+
+ private static CSSSelectorTransfer instance = new CSSSelectorTransfer();
+ private static final String TYPE_NAME = "selector-transfer-format";
//$NON-NLS-1$
+ private static final int TYPEID = registerType(TYPE_NAME);
+
+ private CSSSelectorTransfer() {
+
+ }
+
+ public static CSSSelectorTransfer getInstance(){
+ return instance;
+ }
+
+ @Override
+ protected int[] getTypeIds() {
+ return new int[] { TYPEID };
+ }
+
+ @Override
+ protected String[] getTypeNames() {
+ return new String[] { TYPE_NAME };
+ }
+
+ @Override
+ protected Object nativeToJava(TransferData transferData) {
+ byte[] bytes = (byte[]) super.nativeToJava(transferData);
+ return fromByteArray(bytes);
+ }
+
+ @Override
+ protected void javaToNative(Object object, TransferData transferData) {
+ byte[] bytes = toByteArray((String[]) object);
+ if (bytes != null)
+ super.javaToNative(bytes, transferData);
+ }
+
+ protected byte[] toByteArray(String[] strings) {
+
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream(byteOut);
+
+ byte[] bytes = null;
+
+ try {
+ /* write number of markers */
+ out.writeInt(strings.length);
+
+ /* write markers */
+ for (int i = 0; i < strings.length; i++) {
+ out.writeUTF(strings[i]);
+ }
+ out.close();
+ bytes = byteOut.toByteArray();
+ } catch (IOException e) {
+ // when in doubt send nothing
+ }
+ return bytes;
+ }
+
+ protected String[] fromByteArray(byte[] bytes) {
+ DataInputStream in = new DataInputStream(
+ new ByteArrayInputStream(bytes));
+
+ try {
+ /* read number of gadgets */
+ int n = in.readInt();
+ /* read gadgets */
+ String[] strings = new String[n];
+ for (int i = 0; i < n; i++) {
+ String string = in.readUTF();
+ if (string == null) {
+ return null;
+ }
+ strings[i] = string;
+ }
+ return strings;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeContentProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeContentProvider.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeContentProvider.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSTreeNode;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTreeContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ return ((CSSTreeNode)parentElement).getChildren().toArray();
+ }
+
+ public Object getParent(Object element) {
+ return ((CSSTreeNode)element).getParent();
+ }
+
+ public boolean hasChildren(Object element) {
+ return ((CSSTreeNode)element).hasChildren();
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return ((CSSTreeNode)inputElement).getChildren().toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeLabelProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeLabelProvider.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeLabelProvider.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.outline.cssdialog.common.Constants;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSTreeNode;
+import org.w3c.dom.css.CSSRule;
+import org.w3c.dom.css.CSSStyleSheet;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTreeLabelProvider extends LabelProvider {
+
+ private final static ImageDescriptor CSS_STYLE_SHEET_DESCR =
JspEditorPlugin.getImageDescriptor(Constants.IMAGE_STYLE_SHEET_LOCATION);
+ private final static ImageDescriptor CSS_STYLE_CLASS_DESCR =
JspEditorPlugin.getImageDescriptor(Constants.IMAGE_STYLE_CLASS_LOCATION);
+
+ @Override
+ public Image getImage(Object element) {
+ if (((CSSTreeNode) element).getCssResource() instanceof CSSStyleSheet) {
+ return CSS_STYLE_SHEET_DESCR.createImage();
+ }
+ if (((CSSTreeNode) element).getCssResource() instanceof CSSRule) {
+ return CSS_STYLE_CLASS_DESCR.createImage();
+ }
+ return super.getImage(element);
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeViewer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeViewer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/cssselector/viewers/CSSSelectorTreeViewer.java 2010-03-04
15:18:43 UTC (rev 20671)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cssselector.viewers;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.jst.jsp.outline.cssdialog.cssselector.model.CSSSelectorTreeModel;
+
+/**
+ *
+ * @author yzhishko
+ *
+ */
+
+public class CSSSelectorTreeViewer extends TreeViewer {
+
+ public final static String CSS_SELECTOR_TREE_VIWER_ID =
"css_selector_tree_viwer"; //$NON-NLS-1$
+
+ public CSSSelectorTreeViewer(Composite parent, int style) {
+ super(parent, style);
+ setContentProvider(new CSSSelectorTreeContentProvider());
+ setLabelProvider(new CSSSelectorTreeLabelProvider());
+ }
+
+ public void setModel(CSSSelectorTreeModel model){
+ if (model != null) {
+ setInput(model.getInvisibleRoot());
+ }
+ }
+
+}