How to user custom Drag Appearance in smart gwt - gwt

I am trying to user Custom Drag appearance in smart gwt. how can i implement it.
Current when using DragAppearance.TRACKER its show on 10px square i want a lable with caption Drag to Lineup.
vLayout1.setDragAppearance(DragAppearance.TRACKER);
vLayout1.setCanHover(true);
vLayout1.setCursor(Cursor.HAND);

I hope, the following links will help you
https://github.com/moravianlibrary/MEditor/blob/master/editor-editation/src/main/java/cz/mzk/editor/client/view/ModifyView.java#L1100:L1104
https://github.com/moravianlibrary/MEditor/blob/master/editor-common/editor-common-client/src/main/java/cz/mzk/editor/client/view/other/EditorDragMoveHandler.java

Override BaseWidget.setDragTracker and provide required content using EventHandler.setDragTracker.
VLayout vLayout1 = new VLayout() {
#Override
protected boolean setDragTracker() {
EventHandler.setDragTracker("<pre>Drag to Lineup</pre>");
return false;
}
};
vLayout1.setCanDrop(true);
vLayout1.setCanDrag(true);
vLayout1.setDragAppearance(DragAppearance.TRACKER);
EventHandler.setDragTracker accepts any valid html code and <pre/> tags were used above to avoid word wrap.
Check following sample in SmartGWT showcase:
http://www.smartclient.com/smartgwt/showcase/#effects_dd_tracker

Related

GWT - HTML widget - setEnabled

Is there a way to make com.google.gwt.user.client.ui.HTML widget being enabled or not-enabled? I tried but there seems no setEnabled(boolean) method :S Share your experience please
Thanks
I'm not sure what you mean by enabled but I'll take a stab at it.
I assume that you mean visible or not visible.
HTMLPanel panel = new HTMLPanel();
panel.setVisible(false); // Disabled
panel.setVisible(true); // Enabled
Hopefully that's what you were looking for.
Only a few HTML elements can be enabled or disabled, like inputs. GWT has setEnabled() for elements that can get focus:
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/FocusWidget.html#setEnabled(boolean)
Only some form elements(inputs, options) can be disabled.
To disable:
widget.getElement().setAttribute("disabled","disabled");
To enable again:
widget.getElement().removeAttribute("disabled");
For other widget, you need to set their style to mimic "disabling". (e.g. set the color to grey)
Unfortunately there is no such a method in Widget.
But there is a little room to acheive .I made it work with help of google groups
public void setEnabled (boolean e)
{
Iterator<Widget> itr = grd.iterator (); // grd is a FlexTable which
contains my form controls
while (itr.hasNext ())
{
Widget w = itr.next ();
if (w instanceof TextBox)
{
TextBox t = (TextBox) w;
t.setEnabled (e);
}
if (w instanceof PasswordTextBox)
{
PasswordTextBox t = (PasswordTextBox) w;
t.setEnabled (e);
}
...
}
To Give appearance of enable and disable feature in a widget which does not inherit from FocusWidget.
You would need to override both style and event handling implementation. Keep a enableFl in your MyHTMLPanel extends HTMLPanel.
Step 1 - Provide enable and disable style. Using opacity css turn on/off greying sort of coloring. Based on state of enableFl turn on/off the enable/disable feature.
Step 2 - Disable/Enable event handling on the widget by overriding onBrowserEvent and making its execution conditional on your own enableFl state.
Step 3 - Recursively disable all widgets internal to HTMLPanel.
If your use case is simple you might opt to use com.google.gwt.user.client.ui.HTML instead of com.google.gwt.user.client.ui.HTMLPanel .

Magento: How to add the widget button to the WYSIWYG Products Editor

I want to allow adding the Catalog Product Link widget in the description field of a product (so I can easily link to other products in the description). I've already extended Mage_Catalog_Model_Product by creating a file like:
class mymodule_Catalog_Model_Product extends Mage_Catalog_Model_Product
{
/**
* Add getDescription function that interprets widget or static blocks
* within product descriptions
*/
public function getDescription() {
$processor = Mage::getModel('widget/template_filter');
$html = $processor->filter($this->getData('description'));
return $html;
}
}
Now it works fine if I type something like
{{widget type="catalog/product_widget_link" anchor_text="my text" template="catalog/product/widget/link/link_inline.phtml" id_path="product/1234"}}
into the description field -- it creates a link to the product Id 1234.
But I want to add the actual Catalog Product Link widget button in the WYSIWYG editor for editing a product. The button is already in the CMS editor, but I am missing what I need to modify in order to add this widget to the Admin interface for editing a product. Can someone help me out?
For anybody stumbling across this later on like myself, you can use the cms_wysiwyg_config_prepare event to set this to true.
E.G:
in config.xml
<events>
<cms_wysiwyg_config_prepare>
<observers>
<webtise_widgets>
<class>webtise_widgets/observer</class>
<method>cmsWysiwygConfigPrepare</method>
</webtise_widgets>
</observers>
</cms_wysiwyg_config_prepare>
</events>
In your observer
<?php class Webtise_Widgets_Model_Observer{
public function cmsWysiwygConfigPrepare(Varien_Event_Observer $observer){
$observer->getEvent()->getConfig()->setAddWidgets(true);
}
}
I was able to do this by overriding the core file
app/code/local/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php
and setting
$config['add_widgets'] = true;
Now the widget button shows up in all WYSIWIG editors in the admin interface.

How to style GWT DataGrid dynamically

I am implementing multiple themes in our GWT applications.
The problem is when a DataGrid is constructed, I can't find a way to change the style resource that has been passed to it. Does anybody know how to solve the problem. Or on every theme change, do we have to reconstruct the grid?
Any other new idea to solve the problem (having multiple themes on these widgets) is appreciated.
Thanks.
You could use uibinder.
At this page
https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder#Programmatic_access,
search for the section
Programmatic access to inline Styles
However, you need to be familiar with uibinder.
I was able to do this using -
cellTable.setRowStyles(new RowStyles>() {
#Override
public String getStyleNames(Map<String, String> row, int rowIndex) {
if (rowIndex % 2 == 0) {
return "cellTableEvenRow";
} else {
return "cellTableOddRow";
}
}
});
Since, I had to provide the user 3 color themes, I used 3 style sheets for each color and specified the below style with different colors in each style sheet.
.cellTableEvenRow {
background: #fffff !important;
}
.cellTableOddRow {
background: #E9FDE4 !important;
}
Hope it helps!

Inserting GWT widget into a div element

I'm using a GWT library (gwt-openlayers) which allows me to create a map popup containing arbitrary HTML, similar to Google Maps. I need this HTML to contain a GWT Button widget.
I'm creating some HTML elements on-the-fly like this:
Element outerDiv = DOM.createDiv();
outerDiv.getStyle().setOverflow(Overflow.HIDDEN);
outerDiv.getStyle().setWidth(100, Unit.PCT);
outerDiv.appendChild(new HTML(mapPOI.getHtmlDetails()).getElement());
Button popupButton = new Button("View Property");
popupButton.getElement().getStyle().setFloat(com.google.gwt.dom.client.Style.Float.RIGHT);
outerDiv.appendChild(popupButton.getElement());
Then I'm getting the source HTML for these elements by calling
String src = outerDiv.toString();
and inserting this html into my map marker. Now my map marker displays the content ok, including the button. However, the button won't respond to any events! From what I can gather, this is because the buttons onAttach() method is never being called.
Is there a better way to do this?
Thanks,
Jon
~~~~EDIT~~~~
I'm now trying a new way of doing this, which seems to be the accepted method looking at other similar posts.
First I'm creating my div:
String divId = "popup-" + ref;
String innerHTML = "<div id=\"" +divId + "\"></div>";
Then I'm adding this to my map popup and displaying it (which adds it to the DOM). After the popup has been displayed, I'm getting the Element as follows and trying to wrap a HTMLPanel around it:
Element element = Document.get().getElementById(divId);
HTMLPanel popupHTML = HTMLPanel.wrap(element);
My div element is successfully retrieved. However, HTMLPanel.wrap(element); doesn't complete. The reason for this is that wrap(..) calls RootPanel.detachOnWindowClose(Widget widget), which includes the following assertions:
assert !widgetsToDetach.contains(widget) : "detachOnUnload() called twice "
+ "for the same widget";
assert !isElementChildOfWidget(widget.getElement()) : "A widget that has "
+ "an existing parent widget may not be added to the detach list";
I put some breakpoints in and it seems that the 2nd assertion is failing!
Does anybody have any idea why this might be the case? Should failing this assertion really result in a complete failure of the method (no return)?
Your first approach is good, you just need to register onClick event for your button like this:
DOM.sinkEvents(popupButton.getElement(), Event.ONCLICK);
DOM.setEventListener(popupButton.getElement(), new EventListener() {
#Override
public void onBrowserEvent(Event event) {
//implement the logic after click
}
});
I have checked this, it works 100%!
You might try something like
RootPanel.get("idOfYourMapMarker").add(popupButton);
See RootPanel.get()
Unfortunately, RootPanels are AbsolutePanels which aren't so nice for layout but could work if you just have a simple button to add. You could also try RootLayoutPanel which will give you a LayoutPanel (also not so nice when you just want things to flow). You might end up creating a container widget that does the layout for you, and adding that to the RootPanel.
SimplePanel is a DIV. Perhaps that can be used instead?
You added the element, but you have to keep the hierarchy of the actual GWT Widgets too.
I don't see a clean way to do this, but you could use something like jQuery to grab the button by and ID and add a click handler back to it that would call the original click handler.
private static native void registerEvents(String buttonId, MyClass instance)/*-{
var $ = $wnd.$;
//check click
$('#'+buttonId).live('click', function(e) {
e.preventDefault();
instance.#com.package.MyClass::handleButtonClick(Lcom/google/gwt/event/dom/client/ClickEvent;)(null);
});
}-*/;
Call this registerEvents() either in your onAttach or constructor.
I once had a similar problem. You can use the gwt-openlayer's MapWidget as follows:
private MapWidget createMapWidget() {
final MapOptions defaultMapOptions = new MapOptions();
defaultMapOptions.setDisplayProjection(DEFAULT_PROJECTION);
defaultMapOptions.setNumZoomLevels(TOTAL_ZOOM_LEVELS);
MapWidget mapWidget = new MapWidget(MAP_WIDGET_WIDTH, MAP_WIDGET_HEIGHT, defaultMapOptions);
map = mapWidget.getMap();
return mapWidget;
}
And then add it to any panel be it vertical or horizontal.
MapWidget mapWgt = createMapWidget();
VerticalPanel mainPanel = new VerticalPanel();
mainPanel.add(mapWgt);
...
... add whatever you want
...
You can finally add the created Panel(containing the MapWidget and the gwt widget) to the PopupPanel. Also, you should now be able to add handlers to the gwt button.

TabLayoutPanel disable a Tab GWT

How can i disable a tab (i.e the user cannot open the tab when he clicks on it) in the TabLayoutPanel?I searched online but was not able to find a solution
Thanks
Use a BeforeSelectionHandler:
TabLayoutPanel myPanel = new TabLayoutPanel();
// Add children...
myPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
#Override
public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
// Simple if statement - your test for whether the tab should be disabled
// will probably be more complicated
if (event.getItem() == 1) {
// Canceling the event prevents the tab from being selected.
event.cancel();
}
}
});
If you want to style the disabled tab differently than enabled tabs, you can use TabLayoutPanel#getTabWidget to get the tab widget and add a style name to it.
For anyone who comes across this later:
As of GWT version 1.6, disabling/enabling tabs is built into GWT.
The TabBar class has a method setTabEnabled(int index, boolean enabled) that enables/disables the tab at a given index.
For example, to disable all the tabs in a TabPanel:
TabPanel myTabPanel = new TabPanel();
// Add children
TabBar tabBar = myTabPanel.getTabBar();
for(int i=0; i<tabBar.getTabCount(); i++) {
tabBar.setTabEnabled(i, false);
}
See the GWT javadoc for more info.
To style disabled tabs differently (which GWT does automatically, but if you wanted to change the style): disabled tabBarItem divs are given another CSS class: gwt-TabBarItem-disabled.
You can access tab style by casting class Tab to Widget
TabPanel tabPanel = new TabPanel();
((Widget)tabPanel().getTabBar().getTab(tabsToDisable.iterator().next())).addStyleName("disabled");