Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Furnadjiev2016-10-21 08:34:10 +0000
committerGerrit Code Review @ Eclipse.org2016-10-26 13:17:22 +0000
commit1815c7f73b34f361a68fc7c1a7176fc931a6b381 (patch)
treec845526482ad3668be8512a907db155b4c18d57b /bundles
parent77cee2df44c18545361c1e41213ac245c191a906 (diff)
downloadorg.eclipse.rap-1815c7f73b34f361a68fc7c1a7176fc931a6b381.tar.gz
org.eclipse.rap-1815c7f73b34f361a68fc7c1a7176fc931a6b381.tar.xz
org.eclipse.rap-1815c7f73b34f361a68fc7c1a7176fc931a6b381.zip
Add support for markup in ExpandItem header text
415250: [ExpandBar] Add markup support for ExpandBar and ExpandItem headers https://bugs.eclipse.org/bugs/show_bug.cgi?id=415250 Change-Id: I8b6774961a2847840437dcd02145c9f6b0beefdb
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandBarHandler.js3
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandItemHandler.js7
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandBar.js11
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandItem.js10
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java167
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandItem.java33
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java11
7 files changed, 122 insertions, 120 deletions
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandBarHandler.js b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandBarHandler.js
index 7f331c1778..eb77859eaa 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandBarHandler.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandBarHandler.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 EclipseSource and others.
+ * Copyright (c) 2011, 2016 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@ rwt.remote.HandlerRegistry.add( "rwt.widgets.ExpandBar", {
factory : function( properties ) {
var result = new rwt.widgets.ExpandBar();
+ result.setMarkupEnabled( properties.markupEnabled === true );
rwt.remote.HandlerUtil.addStatesForStyles( result, properties.style );
result.setUserData( "isControl", true );
rwt.remote.HandlerUtil.setParent( result, properties.parent );
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandItemHandler.js b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandItemHandler.js
index 18b08d6591..90cfc239e5 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandItemHandler.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/ExpandItemHandler.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 EclipseSource and others.
+ * Copyright (c) 2011, 2016 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,11 +41,6 @@ rwt.remote.HandlerRegistry.add( "rwt.widgets.ExpandItem", {
widget.setTop( value[ 1 ] );
widget.setWidth( value[ 2 ] );
widget.setHeight( value[ 3 ] );
- },
- "text" : function( widget, value ) {
- var EncodingUtil = rwt.util.Encoding;
- var text = EncodingUtil.escapeText( value, false );
- widget.setText( text );
}
}
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandBar.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandBar.js
index 870f8238cd..dc14341f24 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandBar.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandBar.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2016 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@ rwt.qx.Class.define( "rwt.widgets.ExpandBar", {
this.setScrollBarsVisible( false, false );
// This object is needed for proper scrolling behaviour
this._bottomSpacing = new rwt.widgets.base.Parent();
+ this._markupEnabled = false;
this._clientArea.add( this._bottomSpacing );
},
@@ -59,6 +60,14 @@ rwt.qx.Class.define( "rwt.widgets.ExpandBar", {
setVScrollBarMax : function( value ) {
this._vertScrollBar.setMaximum( value );
+ },
+
+ setMarkupEnabled : function( value ) {
+ this._markupEnabled = value;
+ },
+
+ isMarkupEnabled : function() {
+ return this._markupEnabled;
}
}
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandItem.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandItem.js
index a696eb6a6d..1397d0354a 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandItem.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/ExpandItem.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2016 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -86,7 +86,13 @@ rwt.qx.Class.define( "rwt.widgets.ExpandItem", {
}
},
- setText : function( text ) {
+ setText : function( value ) {
+ var text = value;
+ var EncodingUtil = rwt.util.Encoding;
+ if( !this._expandBar.isMarkupEnabled() ) {
+ text = EncodingUtil.escapeText( text, false );
+ text = EncodingUtil.replaceNewLines( text, "<br/>" );
+ }
this._header.setCellContent( 1, text );
},
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
index b9b90f1978..49b84d7df5 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandBar.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2016 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,8 +11,10 @@
******************************************************************************/
package org.eclipse.swt.widgets;
+import static org.eclipse.swt.internal.widgets.MarkupUtil.isMarkupEnabledFor;
+
+import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
-import org.eclipse.rap.rwt.internal.textsize.TextSizeUtil;
import org.eclipse.rap.rwt.theme.BoxDimensions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
@@ -21,7 +23,6 @@ import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ExpandAdapter;
import org.eclipse.swt.events.ExpandEvent;
import org.eclipse.swt.events.ExpandListener;
-import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.widgets.IExpandBarAdapter;
@@ -56,31 +57,9 @@ import org.eclipse.swt.internal.widgets.expandbarkit.ExpandBarLCA;
*/
public class ExpandBar extends Composite {
- private final class ExpandBarAdapter implements IExpandBarAdapter {
-
- @Override
- public Rectangle getBounds( ExpandItem item ) {
- int index = indexOf( item );
- return getItem( index ).getBounds();
- }
-
- @Override
- public Rectangle getBottomSpacingBounds() {
- return ExpandBar.this.getBottomSpacingBounds();
- }
- }
-
- private final class ResizeListener extends ControlAdapter {
- @Override
- public void controlResized( ControlEvent event ) {
- layoutItems( 0 );
- }
- }
-
ExpandItem focusItem;
int spacing;
int allItemsHeight;
- int charHeight;
private transient IExpandBarAdapter expandBarAdapter;
private final ItemHolder<ExpandItem> itemHolder;
private final ResizeListener resizeListener;
@@ -263,10 +242,6 @@ public class ExpandBar extends Composite {
return control;
}
- int getBandHeight() {
- return Math.max( ExpandItem.CHEVRON_SIZE, charHeight );
- }
-
/**
* Returns the item at the given, zero-relative index in the receiver. Throws
* an exception if the index is out of range.
@@ -374,77 +349,56 @@ public class ExpandBar extends Composite {
}
void layoutItems( int index ) {
- int itemCount = getItemCount();
- if( index < itemCount ) {
- int y = spacing;
- for( int i = 0; i < index; i++ ) {
- ExpandItem item = getItem( i );
- if( item.expanded ) {
- y += item.height;
+ if( !isInDispose() ) {
+ int itemCount = getItemCount();
+ if( index < itemCount ) {
+ int y = spacing;
+ for( int i = 0; i < index; i++ ) {
+ ExpandItem item = getItem( i );
+ if( item.expanded ) {
+ y += item.height;
+ }
+ BoxDimensions itemBorder = item.getItemBorder();
+ y += item.getHeaderHeight() + itemBorder.top + itemBorder.bottom + spacing;
}
- BoxDimensions itemBorder = item.getItemBorder();
- y += item.getHeaderHeight() + itemBorder.top + itemBorder.bottom + spacing;
- }
- for( int i = index; i < itemCount; i++ ) {
- ExpandItem item = getItem( i );
- item.setBounds( spacing, y, 0, 0, true, false );
- if( item.expanded ) {
- y += item.height;
+ for( int i = index; i < itemCount; i++ ) {
+ ExpandItem item = getItem( i );
+ item.setBounds( spacing, y, 0, 0, true, false );
+ if( item.expanded ) {
+ y += item.height;
+ }
+ BoxDimensions itemBorder = item.getItemBorder();
+ y += item.getHeaderHeight() + itemBorder.top + itemBorder.bottom + spacing;
}
- BoxDimensions itemBorder = item.getItemBorder();
- y += item.getHeaderHeight() + itemBorder.top + itemBorder.bottom + spacing;
}
- }
- // Calculate all items size
- if( itemCount > 0 ) {
- ExpandItem lastItem = getItem( itemCount - 1 );
- allItemsHeight = lastItem.y + lastItem.getBounds().height;
- }
- updateScrollBars();
- // Set items width based on scrollbar visibility
- Rectangle bounds = getBounds();
- BoxDimensions border = getBorder();
- int scrollBarWidth = getVScrollBarWidth();
- for( int i = 0; i < itemCount; i++ ) {
- ExpandItem item = getItem( i );
- Rectangle itemBounds = item.getBounds();
- if( isVScrollBarVisible() ) {
- if( this.getOrientation() == SWT.RIGHT_TO_LEFT ) {
- itemBounds.x = spacing + scrollBarWidth;
+ // Calculate all items size
+ if( itemCount > 0 ) {
+ ExpandItem lastItem = getItem( itemCount - 1 );
+ allItemsHeight = lastItem.y + lastItem.getBounds().height;
+ }
+ updateScrollBars();
+ // Set items width based on scrollbar visibility
+ Rectangle bounds = getBounds();
+ BoxDimensions border = getBorder();
+ int scrollBarWidth = getVScrollBarWidth();
+ for( int i = 0; i < itemCount; i++ ) {
+ ExpandItem item = getItem( i );
+ Rectangle itemBounds = item.getBounds();
+ if( isVScrollBarVisible() ) {
+ if( this.getOrientation() == SWT.RIGHT_TO_LEFT ) {
+ itemBounds.x = spacing + scrollBarWidth;
+ }
+ int width = bounds.width - scrollBarWidth - ( border.left + border.right ) - 2 * spacing;
+ item.setBounds( itemBounds.x, itemBounds.y, width, item.height, true, true );
+ } else {
+ int width = bounds.width - ( border.left + border.right ) - 2 * spacing;
+ item.setBounds( spacing, itemBounds.y, width, item.height, true, true );
}
- int width = bounds.width - scrollBarWidth - ( border.left + border.right ) - 2 * spacing;
- item.setBounds( itemBounds.x, itemBounds.y, width, item.height, true, true );
- } else {
- int width = bounds.width - ( border.left + border.right ) - 2 * spacing;
- item.setBounds( spacing, itemBounds.y, width, item.height, true, true );
}
}
}
/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</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>
- */
- @Override
- public void setFont( Font font ) {
- if( font != getFont() ) {
- super.setFont( font );
- charHeight = TextSizeUtil.getCharHeight( getFont() ) + 4;
- }
- }
-
- /**
* Sets the receiver's spacing. Spacing specifies the number of pixels
* allocated around each item.
*
@@ -471,6 +425,13 @@ public class ExpandBar extends Composite {
layoutItems( 0 );
}
+ @Override
+ public void setData( String key, Object value ) {
+ if( !RWT.MARKUP_ENABLED.equals( key ) || !isMarkupEnabledFor( this ) ) {
+ super.setData( key, value );
+ }
+ }
+
void showItem( ExpandItem item ) {
Control control = item.control;
if( control != null && !control.isDisposed() ) {
@@ -582,4 +543,28 @@ public class ExpandBar extends Composite {
}
super.reskinChildren( flags );
}
+
+ private final class ExpandBarAdapter implements IExpandBarAdapter {
+
+ @Override
+ public Rectangle getBounds( ExpandItem item ) {
+ return item.getBounds();
+ }
+
+ @Override
+ public Rectangle getBottomSpacingBounds() {
+ return ExpandBar.this.getBottomSpacingBounds();
+ }
+
+ }
+
+ private final class ResizeListener extends ControlAdapter {
+
+ @Override
+ public void controlResized( ControlEvent event ) {
+ layoutItems( 0 );
+ }
+
+ }
+
}
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandItem.java
index af1dd290bb..a9c3b5df0b 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ExpandItem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2016 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,11 @@
******************************************************************************/
package org.eclipse.swt.widgets;
+import static org.eclipse.rap.rwt.internal.textsize.TextSizeUtil.textExtent;
+import static org.eclipse.swt.internal.widgets.MarkupUtil.isMarkupEnabledFor;
+import static org.eclipse.swt.internal.widgets.MarkupValidator.isValidationDisabledFor;
+
import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
-import org.eclipse.rap.rwt.internal.textsize.TextSizeUtil;
import org.eclipse.rap.rwt.internal.theme.ThemeAdapter;
import org.eclipse.rap.rwt.theme.BoxDimensions;
import org.eclipse.swt.SWT;
@@ -21,6 +24,7 @@ import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.internal.widgets.MarkupValidator;
import org.eclipse.swt.internal.widgets.expandbarkit.ExpandBarThemeAdapter;
import org.eclipse.swt.internal.widgets.expanditemkit.ExpandItemLCA;
@@ -197,9 +201,11 @@ public class ExpandItem extends Item {
*/
public int getHeaderHeight() {
checkWidget();
+ Font font = parent.getFont();
BoxDimensions itemHeaderBorder = getItemHeaderBorder();
int borderHeight = itemHeaderBorder.top + itemHeaderBorder.bottom;
- return Math.max( parent.getBandHeight(), imageHeight ) + borderHeight;
+ int textHeight = textExtent( font, text, SWT.DEFAULT, isMarkupEnabledFor( parent ) ).y + 4;
+ return Math.max( Math.max( CHEVRON_SIZE, imageHeight ), textHeight ) + borderHeight;
}
/**
@@ -235,23 +241,17 @@ public class ExpandItem extends Item {
}
int getPreferredWidth() {
- int result = 0;
if( !isDisposed() ) {
Image image = getImage();
- int w = ( image == null )
- ? 0
- : image.getBounds().width;
String text = getText();
- if( text != null ) {
- if( w > 0 ) {
- w += INTERNAL_SPACING;
- }
- Font parentFont = getParent().getFont();
- w += TextSizeUtil.stringExtent( parentFont, text ).x;
+ int width = ( image == null ) ? 0 : image.getBounds().width;
+ if( width > 0 ) {
+ width += INTERNAL_SPACING;
}
- result = w + LEFT_MARGIN + RIGHT_MARGIN;
+ width += textExtent( parent.getFont(), text, SWT.DEFAULT, isMarkupEnabledFor( parent ) ).x;
+ return width + LEFT_MARGIN + RIGHT_MARGIN;
}
- return result;
+ return 0;
}
Rectangle getBounds() {
@@ -407,6 +407,9 @@ public class ExpandItem extends Item {
if( string == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
+ if( isMarkupEnabledFor( parent ) && !isValidationDisabledFor( parent ) ) {
+ MarkupValidator.getInstance().validate( string );
+ }
if( !string.equals( getText() ) ) {
super.setText( string );
updateBounds();
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
index 570fcecd70..9ca61dae55 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/expandbarkit/ExpandBarLCA.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2016 Innoopract Informationssysteme GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,17 +11,18 @@
******************************************************************************/
package org.eclipse.swt.internal.widgets.expandbarkit;
-import static org.eclipse.rap.rwt.internal.protocol.JsonUtil.createJsonArray;
-import static org.eclipse.rap.rwt.internal.protocol.RemoteObjectFactory.createRemoteObject;
import static org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil.getStyles;
import static org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil.preserveProperty;
import static org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil.renderProperty;
import static org.eclipse.rap.rwt.internal.lifecycle.WidgetUtil.getId;
+import static org.eclipse.rap.rwt.internal.protocol.JsonUtil.createJsonArray;
+import static org.eclipse.rap.rwt.internal.protocol.RemoteObjectFactory.createRemoteObject;
+import static org.eclipse.swt.internal.widgets.MarkupUtil.isMarkupEnabledFor;
import java.io.IOException;
-import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
import org.eclipse.rap.rwt.internal.lifecycle.ControlLCAUtil;
+import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil;
import org.eclipse.rap.rwt.remote.RemoteObject;
import org.eclipse.swt.SWT;
@@ -40,6 +41,7 @@ public final class ExpandBarLCA extends WidgetLCA<ExpandBar> {
private static final String PROP_BOTTOM_SPACING_BOUNDS = "bottomSpacingBounds";
private static final String PROP_VSCROLLBAR_MAX = "vScrollBarMax";
+ private static final String PROP_MARKUP_ENABLED = "markupEnabled";
private static final String PROP_EXPAND_LISTENER = "Expand";
private static final String PROP_COLLAPSE_LISTENER = "Collapse";
@@ -55,6 +57,7 @@ public final class ExpandBarLCA extends WidgetLCA<ExpandBar> {
remoteObject.setHandler( new ExpandBarOperationHandler( expandBar ) );
remoteObject.set( "parent", getId( expandBar.getParent() ) );
remoteObject.set( "style", createJsonArray( getStyles( expandBar, ALLOWED_STYLES ) ) );
+ remoteObject.set( PROP_MARKUP_ENABLED, isMarkupEnabledFor( expandBar ) );
// Always listen for Expand and Collapse.
// Currently required for item's control visibility and bounds update.
remoteObject.listen( PROP_EXPAND_LISTENER, true );

Back to the top