I'm new at GWT-P, but there is very little material on this topic. I'm trying to make simple pie chart widget, for testing purpose. I've made Widget presenter, view, and UiBinder.
package com.rs.gwtp.gametestingyou.client;
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;
import com.google.inject.Inject;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.HTMLPanel;
public class PieChartPresenter extends
PresenterWidget<PieChartPresenter.MyView> {
public interface MyView extends View {
public HTMLPanel getChartPanel();
public void drawPieChart();
}
#Inject
public PieChartPresenter(final EventBus eventBus, final MyView view) {
super(eventBus, view);
}
#Override
protected void onBind() {
super.onBind();
}
/*Ovde prmeniti method*/
#Override
protected void onReset() {
super.onReset();
/*MyView v = getView();
v.drawPieChart();*/
getView().drawPieChart();
}
}
Then View.
package com.rs.gwtp.gametestingyou.client;
import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.google.gwt.visualization.client.visualizations.corechart.PieChart;
import com.google.inject.Inject;
public class PieChartView extends ViewImpl implements PieChartPresenter.MyView {
private final Widget widget;
#UiField HTMLPanel chartPanel;
#UiField (provided=true) PieChart pieChart;
public interface Binder extends UiBinder<Widget, PieChartView> {
}
#Inject
public #UiConstructor PieChartView(final Binder binder) {
widget = binder.createAndBindUi(this);
pieChart = new PieChart(createTable(), createOptions());
chartPanel.add(pieChart);
}
#Override
public Widget asWidget() {
return widget;
}
public HTMLPanel getChartPanel(){
return chartPanel;
}
#Override
public void drawPieChart() {
// OVAJ POKUSAJ
pieChart.draw(createTable(),createOptions());
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
}
And last UiBinder
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default'
xmlns:c="urn:import:com.google.gwt.visualization.client.visualizations.corechart" xmlns:v="urn:import:com.google.gwt.visualization.client.visualizations">
<g:HTMLPanel ui:field="chartPanel">
<c:PieChart ui:field="pieChart" ></c:PieChart>
</g:HTMLPanel>
</ui:UiBinder>
When I load this code I get Error:
[ERROR] [gametestingyou] - Unable to load module entry point class com.rs.gwtp.gametestingyou.client.GameTestingYou (see associated exception for details) and Umbrella exception.
Help please :) !
This is full Exception:
19:14:34.890 [ERROR] [gametestingyou] Unable to load module entry point class com.rs.gwtp.gametestingyou.client.GameTestingYou (see associated exception for details)
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.google.gwt.user.client.impl.HistoryImpl.fireEvent(HistoryImpl.java:75)
at com.google.gwt.event.logical.shared.ValueChangeEvent.fire(ValueChangeEvent.java:43)
at com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl(HistoryImpl.java:82)
at com.google.gwt.user.client.History.fireCurrentHistoryState(History.java:121)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace(PlaceManagerImpl.java:310)
at com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad(GameTestingYou.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.EventBus.castFireEventFromSource(EventBus.java:77)
at com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource(SimpleEventBus.java:67)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.fireEvent(PlaceManagerImpl.java:146)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.doRevealPlace(PlaceManagerImpl.java:121)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealPlace(PlaceManagerImpl.java:339)
at com.rs.gwtp.gametestingyou.client.place.ClientPlaceManager.revealDefaultPlace(ClientPlaceManager.java:24)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.onValueChange(PlaceManagerImpl.java:264)
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:128)
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.google.gwt.user.client.impl.HistoryImpl.fireEvent(HistoryImpl.java:75)
at com.google.gwt.event.logical.shared.ValueChangeEvent.fire(ValueChangeEvent.java:43)
at com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl(HistoryImpl.java:82)
at com.google.gwt.user.client.History.fireCurrentHistoryState(History.java:121)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace(PlaceManagerImpl.java:310)
at com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad(GameTestingYou.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: null
at com.google.gwt.user.client.ui.HTMLPanel.addAndReplaceElement(HTMLPanel.java:197)
at com.rs.gwtp.gametestingyou.client.PieChartView_BinderImpl.createAndBindUi(PieChartView_BinderImpl.java:33)
at com.rs.gwtp.gametestingyou.client.PieChartView_BinderImpl.createAndBindUi(PieChartView_BinderImpl.java:1)
at com.rs.gwtp.gametestingyou.client.PieChartView.(PieChartView.java:27)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.com$rs$gwtp$gametestingyou$client$PieChartView_PieChartView_methodInjection(ClientGinjectorImpl.java:555)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key$type$com$rs$gwtp$gametestingyou$client$PieChartView$_annotation$$none$$(ClientGinjectorImpl.java:559)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key$type$com$rs$gwtp$gametestingyou$client$PieChartView$_annotation$$none$$(ClientGinjectorImpl.java:570)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key$type$com$rs$gwtp$gametestingyou$client$PieChartPresenter$MyView$_annotation$$none$$(ClientGinjectorImpl.java:1726)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key$type$com$rs$gwtp$gametestingyou$client$PieChartPresenter$MyView$_annotation$$none$$(ClientGinjectorImpl.java:1735)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key$type$com$rs$gwtp$gametestingyou$client$PieChartPresenter$_annotation$$none$$(ClientGinjectorImpl.java:1522)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key$type$com$rs$gwtp$gametestingyou$client$PieChartPresenter$_annotation$$none$$(ClientGinjectorImpl.java:1533)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.memberInject_Key$type$com$rs$gwtp$gametestingyou$client$ShowTestResultsPresenter$_annotation$$none$$(ClientGinjectorImpl.java:2069)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key$type$com$rs$gwtp$gametestingyou$client$ShowTestResultsPresenter$_annotation$$none$$(ClientGinjectorImpl.java:2079)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key$type$com$rs$gwtp$gametestingyou$client$ShowTestResultsPresenter$_annotation$$none$$(ClientGinjectorImpl.java:2092)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.memberInject_Key$type$com$rs$gwtp$gametestingyou$client$HomePagePresenter$_annotation$$none$$(ClientGinjectorImpl.java:1341)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key$type$com$rs$gwtp$gametestingyou$client$HomePagePresenter$_annotation$$none$$(ClientGinjectorImpl.java:1352)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key$type$com$rs$gwtp$gametestingyou$client$HomePagePresenter$_annotation$$none$$(ClientGinjectorImpl.java:1365)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.access$4(ClientGinjectorImpl.java:1363)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl$5$1.onSuccess(ClientGinjectorImpl.java:1413)
at com.google.gwt.core.client.GWT.runAsync(GWT.java:255)
at com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl$5.get(ClientGinjectorImpl.java:1411)
at com.gwtplatform.common.client.CodeSplitProvider.get(CodeSplitProvider.java:48)
at com.gwtplatform.mvp.client.proxy.ProxyImpl.getPresenter(ProxyImpl.java:46)
at com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract.handleRequest(ProxyPlaceAbstract.java:193)
at com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract.access$0(ProxyPlaceAbstract.java:192)
at com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract$1.onPlaceRequest(ProxyPlaceAbstract.java:143)
at com.gwtplatform.mvp.client.proxy.PlaceRequestInternalEvent.dispatch(PlaceRequestInternalEvent.java:134)
at com.gwtplatform.mvp.client.proxy.PlaceRequestInternalEvent.dispatch(PlaceRequestInternalEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEventFromSource(SimpleEventBus.java:96)
at com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource(SimpleEventBus.java:62)
at com.google.gwt.event.shared.EventBus.castFireEventFromSource(EventBus.java:75)
at com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource(SimpleEventBus.java:67)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.fireEvent(PlaceManagerImpl.java:146)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.doRevealPlace(PlaceManagerImpl.java:121)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealPlace(PlaceManagerImpl.java:339)
at com.rs.gwtp.gametestingyou.client.place.ClientPlaceManager.revealDefaultPlace(ClientPlaceManager.java:24)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.onValueChange(PlaceManagerImpl.java:264)
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:128)
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.google.gwt.user.client.impl.HistoryImpl.fireEvent(HistoryImpl.java:75)
at com.google.gwt.event.logical.shared.ValueChangeEvent.fire(ValueChangeEvent.java:43)
at com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl(HistoryImpl.java:82)
at com.google.gwt.user.client.History.fireCurrentHistoryState(History.java:121)
at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace(PlaceManagerImpl.java:310)
at com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad(GameTestingYou.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
package com.rs.gwtp.gametestingyou.client;
import com.google.gwt.core.client.EntryPoint;
import com.rs.gwtp.gametestingyou.client.gin.ClientGinjector;
import com.google.gwt.core.client.GWT;
import com.gwtplatform.mvp.client.DelayedBindRegistry;
public class GameTestingYou implements EntryPoint {
private final ClientGinjector ginjector = GWT.create(ClientGinjector.class);
#Override
public void onModuleLoad() {
// This is required for Gwt-Platform proxy's generator
DelayedBindRegistry.bind(ginjector);
ginjector.getPlaceManager().revealCurrentPlace();
}
}
In your constructor try to initialize pieChart before calling createAndBindUi
#Inject
public #UiConstructor PieChartView(final Binder binder) {
pieChart = new PieChart(createTable(), createOptions());
widget = binder.createAndBindUi(this);
chartPanel.add(pieChart);
}
Ok I found out that this issue is specific for GWT-P because EntryPoint class doesn't load needed PACKAGE. It need to be loaded with this method
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
and add Runnable interface to class which implements EntryPoint class, like this sample:
Runnable onLoadCallback = new Runnable() {
#Override
public void run() {
PieChart pieChart = new PieChart(createTable(), createOptions());
Panel panel = RootPanel.get();
panel.add(pieChart);
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
};
but this will add, in this example pieChart, to RootPanel, just now to figure out how to add this object pieChart to specific PresenterWidget. When I do this I will made a tutorial :)
Success!!! This is how I FINALLY done what I intended: To add some chart to existing GWT-P project. When I was sure API set up was fine I figure out that this is solution:
UiBinder just need to have HTML table:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default' xmlns:c="urn:import:com.google.gwt.visualization.client.visualizations.corechart"
xmlns:v="urn:import:com.google.gwt.visualization.client.visualizations">
<g:HTMLPanel ui:field="chartPanel">
</g:HTMLPanel>
</ui:UiBinder>
Then View should be simple as this:
public class PieChartView extends ViewImpl implements PieChartPresenter.MyView {
private final Widget widget;
#UiField HTMLPanel chartPanel;
public interface Binder extends UiBinder<Widget, PieChartView> {
}
#Inject
public #UiConstructor PieChartView(final Binder binder) {
widget = binder.createAndBindUi(this);
}
#Override
public Widget asWidget() {
return widget;
}
public HTMLPanel getChartPanel(){
return chartPanel;
}
}
And Then PresenterWidget, need to load appropriate PACKAGE via VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE); like this:
public class PieChartPresenter extends
PresenterWidget<PieChartPresenter.MyView> {
public interface MyView extends View {
public HTMLPanel getChartPanel();
}
#Inject
public PieChartPresenter(final EventBus eventBus, final MyView view) {
super(eventBus, view);
}
#Override
protected void onBind() {
super.onBind();
Runnable onLoadCallback = new Runnable() {
#Override
public void run() {
PieChart pieChart = new PieChart(createTable(), createOptions());
/*Panel panel = RootPanel.get();*/
/*panel.add(pieChart);*/
Panel panel = getView().getChartPanel();
panel.add(pieChart);
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
/*Ovde prmeniti method*/
#Override
protected void onReset() {
super.onReset();
}
}
Now this is for testing purpose only, and it was a result which I intended: To place PieChart in PresenterWidget and present it on call.
Related
I am trying to develop an eclipse plug-in. I am aware about the basics of this thing.
In a sample plugin template when we click the menu entry (or button with eclipse icon in below image in this case) in testing instance of eclipse, execute method of sampleHandler.java is executed and a pop-up shown in image below appears.
I want to invoke 'execute' method whenever I press some key (lets say backspace) in code editor instead of clicking any menu entry (or button).
SampleHandler.java
public class SampleHandler extends AbstractHandler {
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(
window.getShell(),
"Sdfsdfsadf",
"Hello, Eclipse world");
return null;
}
}
I tried suggestions given in other posts but I am unable to achieve the desired functionality.
As per my understanding from referenced post in above line, I tried below code -
package eventlisten.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
* #see org.eclipse.core.commands.IHandler
* #see org.eclipse.core.commands.AbstractHandler
*/
public class SampleHandler extends AbstractHandler {
/**
* The constructor.
*/
public SampleHandler() {
}
/**
* the command has been executed, so extract extract the needed information
* from the application context.
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
MessageDialog.openInformation(window.getShell(),"EventListen","Trying event listen");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();
IDocument document=(((ITextEditor)editor).getDocumentProvider()).getDocument(IDocument.class);
document.addDocumentListener(new IDocumentListener() //**this is line 45**
{
#Override
public void documentAboutToBeChanged(DocumentEvent event) {
// TODO Auto-generated method stub
System.out.println("Hello");
}
#Override
public void documentChanged(DocumentEvent event) {
// TODO Auto-generated method stub
System.out.println("Hello second");
}
});
return null;
}
}
But after showing the pop-up , it throws the exception -
java.lang.NullPointerException
at eventlisten.handlers.SampleHandler.execute(SampleHandler.java:45)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
at org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Can someone guide me through the process? Let me know in case more information is required.
Your first problem seems to be that you only interact with the documents when the user presses the button. There are better ways to set this up.
As far as I can tell, you want to either detect when a user modifies a document (probably by typing), any key is typed anywhere, or when the AST of the code is modified. You will probably only find one of the solutions below useful or relevant.
Listening to Document Changes
The solution you attempted is closest to the first one, so I'll start there. I did something like this (in the post you linked, as it turns out). Start by making your plugin extend the org.eclipse.ui.startup extension point, and define a class to override IStartup
That earlyStartup() will look something like:
#Override
public void earlyStartup() {
IWorkbench wb = PlatformUI.getWorkbench();
wb.addWindowListener(generateWindowListener());
}
We'll listen for windows to open, and when they do,
private IWindowListener generateWindowListener()
{
return new IWindowListener() {
#Override
public void windowOpened(IWorkbenchWindow window) {
IWorkbenchPage activePage = window.getActivePage();
activePage.addPartListener(generateIPartListener2());
}
#Override
public void windowDeactivated(IWorkbenchWindow window) {}
#Override
public void windowClosed(IWorkbenchWindow window) {}
#Override
public void windowActivated(IWorkbenchWindow window) {}
};
}
This part listener is where you should get the EditorPart, which means you can add the document listener:
private IPartListener2 generateIPartListener2()
{
return new IPartListener2() {
private void checkPart(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part instanceof IEditorPart)
{
IEditorPart editor = (IEditorPart) part;
IEditorInput input = editor.getEditorInput();
if (editor instanceof ITextEditor && input instanceof FileEditorInput) //double check. Error Editors can also bring up this call
{
IDocument document=(((ITextEditor)editor).getDocumentProvider()).getDocument(input);
document.addDocumentListener(/* your listener from above*/);
}
}
}
#Override
public void partOpened(IWorkbenchPartReference partRef) {
checkPart(partRef);
}
#Override
public void partInputChanged(IWorkbenchPartReference partRef)
{
checkPart(partRef);
}
#Override
public void partVisible(IWorkbenchPartReference partRef){}
#Override
public void partHidden(IWorkbenchPartReference partRef) {}
#Override
public void partDeactivated(IWorkbenchPartReference partRef) {}
#Override
public void partClosed(IWorkbenchPartReference partRef) {}
#Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {}
#Override
public void partActivated(IWorkbenchPartReference partRef) {}
};
}
Listening to just the keypressess
This ends up being simpler to implement, but may be very noisy. We'll be looking at the Display and the Listener, which gets right into the SWT event loop.
You'll want to do the earlyStartup() extension again, and have something like:
#Override
public void earlyStartup() {
Display display = Display.getDefault();
display.setFilter(SWT.KeyUp, new Listener() {
#Override
public void handleEvent(Event event) {
//do stuff here. Be careful, this may cause lag
}
});
}
Listening to Java AST changes
The final one has the simplicity of the raw keyup approach, but will probably be as semantically useful as the first one I suggested. We will be listening to the JavaCore directly.
Again, in the earlyStartup method()
JavaCore.addElementChangedListener(new IElementChangedListener() {
#Override
public void elementChanged(ElementChangedEvent event)
{
//do stuff with the event
}
});
Conclusion: With luck, one of these three methods is useful to you. I've had reason to use each in my Eclipse development career -- each is useful in its own way.
I hope this helps.
I’m trying to use gwt-graphics in a gwt-plattform project.
When I try to register a ClickHandler of a circle I got an exception:
I can add a ClickHandler to the circle in the view, but how can a add in the presenter?
view:
import org.vaadin.gwtgraphics.client.DrawingArea;
import org.vaadin.gwtgraphics.client.shape.Circle;
import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
public class MainPageView extends ViewImpl implements MainPagePresenter.MyView {
private static String html = "<h1>Web Application Starter Project</h1>\n"
+ "<table align=\"center\">\n"
+ " <tr>\n"
+ " <td colspan=\"2\" style=\"font-weight:bold;\">Please enter your name:</td>\n"
+ " </tr>\n"
+ " <tr>\n"
+ " <td id=\"nameFieldContainer\"></td>\n"
+ " <td id=\"sendButtonContainer\"></td>\n"
+ " </tr>\n"
+ " <tr>\n"
+ " <td colspan=\"2\" style=\"color:red;\" id=\"errorLabelContainer\"></td>\n"
+ " </tr>\n" + "</table>\n";
private final HTMLPanel panel = new HTMLPanel(html);
private final Label errorLabel;
private final TextBox nameField;
private final Button sendButton;
private AbsolutePanel absolutePanel = new AbsolutePanel();
Image image_1;
Image image;
DrawingArea d;
Circle circle;
#Inject
public MainPageView() {
sendButton = new Button("Send");
nameField = new TextBox();
nameField.setText("GWT User");
errorLabel = new Label();
// We can add style names to widgets
sendButton.addStyleName("sendButton");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
panel.add(nameField, "nameFieldContainer");
panel.add(sendButton, "sendButtonContainer");
d = new DrawingArea(500, 500);
panel.add(absolutePanel);
absolutePanel.setHeight("500px");
// circle.addClickHandler(new ClickHandler() {
//
// #Override
// public void onClick(ClickEvent event) {
// Window.alert("image2");
//
// }
// });
image = new Image("ball1.png");
absolutePanel.add(image, 59, 10);
image.setSize("100px", "100px");
image_1 = new Image("Hexagon.svg");
absolutePanel.add(image_1, 115, 10);
image_1.setSize("100px", "100px");
absolutePanel.add(d, 100, 100);
//
Circle circle = new Circle(100, 100, 150);
circle.setStrokeColor("red");
d.add(circle);
panel.add(errorLabel, "errorLabelContainer");
}
#Override
public Widget asWidget() {
return panel;
}
#Override
public HasValue<String> getNameValue() {
return nameField;
}
#Override
public HasClickHandlers getSendClickHandlers() {
return sendButton;
}
#Override
public void resetAndFocus() {
// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();
}
#Override
public void setError(String errorText) {
errorLabel.setText(errorText);
}
// #Override
// public HasClickHandlers getImage1() {
// return image;
// }
//
// #Override
// public HasClickHandlers getImage2() {
// return image_1;
//
// }
#Override
public HasClickHandlers getCircle() {
return circle;
}
}
Presenter:
package mybla.client.core;
import org.vaadin.gwtgraphics.client.shape.Circle;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.annotations.NameToken;
import mybla.client.place.NameTokens;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.google.inject.Inject;
import com.google.gwt.event.shared.EventBus;
import com.gwtplatform.mvp.client.proxy.RevealRootContentEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasValue;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import mybla.shared.FieldVerifier;
public class MainPagePresenter extends
Presenter<MainPagePresenter.MyView, MainPagePresenter.MyProxy> {
public interface MyView extends View {
HasValue<String> getNameValue();
HasClickHandlers getSendClickHandlers();
void resetAndFocus();
void setError(String errorText);
HasClickHandlers getCircle();
// HasClickHandlers getImage2();
//
// HasClickHandlers getImage1();
}
#ProxyStandard
#NameToken(NameTokens.main)
public interface MyProxy extends ProxyPlace<MainPagePresenter> {
}
private final PlaceManager placeManager;
#Inject
public MainPagePresenter(final EventBus eventBus, final MyView view,
final MyProxy proxy, final PlaceManager placeManager) {
super(eventBus, view, proxy);
this.placeManager = placeManager;
}
#Override
protected void revealInParent() {
RevealRootContentEvent.fire(this, this);
}
#Override
protected void onBind() {
super.onBind();
registerHandler(getView().getSendClickHandlers().addClickHandler(
new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
sendNameToServer();
}
}));
// registerHandler(getView().getImage1().addClickHandler(new ClickHandler() {
//
// #Override
// public void onClick(ClickEvent event) {
// Window.alert("image1");
//
// }
// }));
registerHandler(getView().getCircle().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("image2");
}
}));
}
#Override
protected void onReset() {
super.onReset();
getView().resetAndFocus();
}
/**
* Send the name from the nameField to the server and wait for a response.
*/
private void sendNameToServer() {
// First, we validate the input.
getView().setError("");
String textToServer = getView().getNameValue().getValue();
if (!FieldVerifier.isValidName(textToServer)) {
getView().setError("Please enter at least four characters");
return;
}
// Then, we transmit it to the ResponsePresenter, which will do the server call
placeManager.revealPlace(new PlaceRequest(NameTokens.response).with(
ResponsePresenter.textToServerParam, textToServer));
}
}
In your presenter:
getView().getCircle().addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event)
{
Window.alert("image2");
}
});
This will use the getter method set in the presenter.view, to access the circle in the View itself.
Looks like the circle you instantiate in your View's constructor is a local variable, not the class-scope variable your getCircle() method returns. Additionally, the commented out code for adding the onclick handler is before the code that instantiates the local variable.
You have:
...
// circle.addClickHandler(new ClickHandler() {
//
// #Override
// public void onClick(ClickEvent event) {
// Window.alert("image2");
// }
// });
...
Circle circle = new Circle(100, 100, 150);
circle.setStrokeColor("red");
d.add(circle);
Change it to:
...
circle = new Circle(100, 100, 150); // This now references the class-scope variable, rather than creating a new local variable.
circle.setStrokeColor("red");
d.add(circle);
circle.addClickHandler(new ClickHandler() { // This will no longer throw a null-pointer exception.
#Override
public void onClick(ClickEvent event) {
Window.alert("image2");
}
});
I am using SmartGWT 3.0 and GWTP 0.7.
I am trying to do a simple PresenterWidget showing a SmartGWT Window. This is the code for the widget presenter:
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.PopupView;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
public class DemoWidgetPresenter extends
PresenterWidget<DemoWidgetPresenter.MyView> {
public interface MyView extends PopupView {
}
#Inject
public DemoWidgetPresenter(final EventBus eventBus, final MyView view) {
super(eventBus, view);
}
#Override
protected void onBind() {
super.onBind();
}
#Override
protected void onReveal() {
super.onReveal();
System.out.println(">>>> onReveal()");
}
}
And the view code:
import com.gwtplatform.mvp.client.PopupViewImpl;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;
public class DemoWidgetView extends PopupViewImpl implements
DemoWidgetPresenter.MyView {
private Window winModal;
#Inject
public DemoWidgetView(final EventBus eventBus) {
super(eventBus);
winModal = new Window();
winModal.setWidth(300);
winModal.setHeight(500);
winModal.setTitle("Export file");
winModal.setShowMinimizeButton(false);
winModal.setIsModal(true);
winModal.setShowModalMask(true);
winModal.centerInPage();
winModal.setCanDragResize(true);
winModal.addCloseClickHandler(new CloseClickHandler() {
#Override
public void onCloseClick(CloseClickEvent event) {
winModal.hide();
}
});
}
#Override
public void center() {
winModal.centerInPage();
}
#Override
public void hide() {
winModal.hide();
}
#Override
public void setPosition(int left, int top) {
winModal.setLeft(left);
winModal.setTop(top);
}
#Override
public void show() {
winModal.show();
}
public Widget asWidget() {
return winModal;
}
}
In another part of the program I show this presenter with:
addToPopupSlot(dp, true);
Where dp is an injected instance of DemoWidgetPresenter.
When DemoWidgetPresenter is show the folowing Exception is raised:
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: com.smartgwt.client.widgets.Window cannot be cast to com.google.gwt.user.client.ui.PopupPanel
at com.gwtplatform.mvp.client.PopupViewImpl.asPopupPanel(PopupViewImpl.java:130)
at com.gwtplatform.mvp.client.PopupViewImpl.setCloseHandler(PopupViewImpl.java:104)
at com.gwtplatform.mvp.client.PresenterWidget.monitorCloseEvent(PresenterWidget.java:574)
at com.gwtplatform.mvp.client.PresenterWidget.addToPopupSlot(PresenterWidget.java:205)
at com.demo.client.core.mvp.DiffPresenter$9.onClick(DiffPresenter.java:397)
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:96)
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
I see the problem is due to a casting between
com.smartgwt.client.widgets.Window and
com.google.gwt.user.client.ui.PopupPanel but I don't know how to solve it!
Despite the Exception, the window is shown, but function onReveal() is never call, so the presenter live cycle is broken..
Any idea/workaround :-)?
Thank you in advance!
In my case we are using UIBinder XML to define layout and I had an issue with GWTBootstrap3's Modal compenent.
I have rolled out a custom ModalPopupAdapter using the mentioned solution, but needed the following additions to the different parts:
Java Code in View
#UiField(provided = true)
Modal modal = new Modal();
#UiField(provided = true)
ModalPopupAdapter modalPopupAdapter = new ModalPopupAdapter(modal);
UIBinder XML
<afr:ModalPopupAdapter ui:field="modalPopupAdapter">
<bs:Modal ui:field="modal" other-attributes...>
I found a solution doing an adapter class:
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtplatform.mvp.client.PopupView;
import com.gwtplatform.mvp.client.PopupViewImpl;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;
/**
* Adapter class for {#link Window}. This class it is necessary when a
* {#link PopupView} uses as widget a {#link Window}. GWTP library does an
* explicit cast to {#link PopupPanel} in {#link PopupViewImpl} and a cast
* exception is raised. This class adapts only these functions which are call in
* {#link PopupViewImpl}.
*
*
*/
public class PopupPanelAdapter extends PopupPanel {
private Window delegate;
public PopupPanelAdapter(Window delegate) {
this.delegate = delegate;
// adapting window close event
delegate.addCloseClickHandler(new CloseClickHandler() {
#Override
public void onCloseClick(CloseClickEvent event) {
CloseEvent.fire(PopupPanelAdapter.this, null);
}
});
}
public void hide() {
delegate.hide();
}
public void show() {
delegate.show();
}
#Override
public HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler) {
return super.addCloseHandler(handler);
}
#Override
public boolean isShowing() {
return isVisible();
}
#Override
public void center() {
delegate.centerInPage();
}
#Override
public void setPopupPosition(int left, int top) {
if (delegate == null)// call in constructor, delegate is null
return;
delegate.setLeft(left);
delegate.setTop(top);
}
}
It works fine!
I have a problem with Eclipse when I use an RPC..
If I use a single method call it's all in the right direction but if I add a new method to handle the server I get the following error:
com.google.gwt.core.client.JavaScriptException: (null): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:184)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
at com.google.gwt.user.client.rpc.impl.RpcStatsContext.isStatsAvailable(RpcStatsContext.java)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:221)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Thread.java:619)
Can I have more services in an asynchronous call right? Where am I wrong?
This is my implementation MyService:
package de.vogella.gwt.helloworld.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface MyService extends RemoteService {
//chiamo i metodi presenti sul server
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann);
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url);
}
MyServiceAsync
package de.vogella.gwt.helloworld.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MyServiceAsync {
void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback<Void> callback);
void setWeb(String userCorrect,String query, String titolo,String snippet,String url, AsyncCallback<Void> callback);
}
RPCService:
package de.vogella.gwt.helloworld.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlexTable;
public class RPCService implements MyServiceAsync {
MyServiceAsync service = (MyServiceAsync) GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
public RPCService()
{
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc");
}
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback callback)
{
service.creaXML(nickname, pass, email2, gio, mes, ann, callback);
}
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url,AsyncCallback callback) {
service.setWeb(userCorrect,query, titolo,snippet,url,callback);
}
}
MyServiceImpl
package de.vogella.gwt.helloworld.server;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import de.vogella.gwt.helloworld.client.MyService;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;
public class MyServiceImpl extends RemoteServiceServlet implements MyService {
//metodo che inserisce il nuovo iscritto
public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann){
.......
}
public void setWeb(String userCorrect,String query, String titolo,String snippet,String url) {
.....
}
In the app in client-side I do
RPCService rpc2 = New RPCService()
rpc2.setWeb(..,...,...,...,callback);
and
RPCService rpc = New RPCService()
rpc.creaXML(..,...,...,...,callback); (in other posizions in the code...)
and..
AsyncCallback callback = new AsyncCallback()
{
public void onFailure(Throwable caught)
{
Window.alert("Failure!");
}
public void onSuccess(Object result)
{
Window.alert("Successoooooo");
}
};
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>De_vogella_gwt_helloworld.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>rPCImpl</servlet-name>
<servlet-class>de.vogella.gwt.helloworld.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>rPCImpl</servlet-name>
<url-pattern>/de_vogella_gwt_helloworld/rpc</url-pattern>
</servlet-mapping>
</web-app>
Thank you all for your attention
Sebe
You seem to be invoking your RPC services in a strange way.
There is a tutorial in GWT web page showing how this should be done.
EDIT:
This bug reported in GWT bugs database may be related to your problem (the stack trace is very similar). Some information about the bug can be also found here.
I lost my pass and I recreate the account... I see your board..it's a problem with my browser web... If I use Internet Explorer it work fine, but If I use Firefox (my predefinite browser) throw the exception (but It compile fine). I have not found anything that I can fix it...
I'm working on a project with GWT 2.1 and mvp4g. In a view, I'm using
a CellList backed with a ListDataProvider. If I pass a List with data to the constructor
when instantiating the ListDataProvider, the CellList shows this data.
The problem is that afterthat, the CellList never gets redrawn
whenever I change the list within the ListDataProvider. I don't know what I am
doing wrong or if I missing something.
Here is the code:
The UIBinder xml file:
<g:DockLayoutPanel unit="PX">
<g:west size="300">
<g:VerticalPanel styleName='{style.leftPanel}' spacing="8">
<g:Label>Expositores</g:Label>
<g:ScrollPanel addStyleNames='{style.exhibitorList}' width="250px" height="600px">
<c:CellList ui:field="exhibitorList" />
</g:ScrollPanel>
<g:Button ui:field="editExhibitorButton" addStyleNames='{style.button}'>Editar</g:Button>
</g:VerticalPanel>
</g:west>
...
The View class:
public class ExhibitorsAdminView extends Composite implements
ExhibitorsAdminPresenter.IExhibitorsAdminView {
interface Binder extends UiBinder<Widget, ExhibitorsAdminView> {}
private static final Binder binder = GWT.create( Binder.class );
private static class ExhibitorCell extends AbstractCell<Exhibitor> {
#Override
public void render(Cell.Context context, Exhibitor exhibitor,
SafeHtmlBuilder sb) {
if (exhibitor != null) {
sb.appendEscaped(exhibitor.getName());
}
}
}
private ListDataProvider<Exhibitor> exhibitorsDataProvider;
private SingleSelectionModel<Exhibitor> exhibitorsSelectionModel;
#UiField( provided = true )
CellList<Exhibitor> exhibitorList;
#UiField
Button editExhibitorButton;
// #UiField(provided = true)
// CellTable<Object> moduleList = new CellTable<Object>();
public ExhibitorsAdminView() {
exhibitorsSelectionModel = new
SingleSelectionModel<Exhibitor>(Exhibitor.KEY_PROVIDER);
exhibitorList = new CellList<Exhibitor>(new ExhibitorCell(),
Exhibitor.KEY_PROVIDER);
exhibitorList.setSelectionModel(exhibitorsSelectionModel);
exhibitorsDataProvider = new
ListDataProvider<Exhibitor>(getExhibitors());
exhibitorsDataProvider.addDataDisplay(exhibitorList);
exhibitorList.setPageSize(exhibitorsDataProvider.getList().size());
initWidget( binder.createAndBindUi( this ) );
}
public SingleSelectionModel<Exhibitor> getExhibitorsSelectionModel()
{
return exhibitorsSelectionModel;
}
public ListDataProvider<Exhibitor> getExhibitorsDataProvider() {
return exhibitorsDataProvider;
}
private List<Exhibitor> getExhibitors() {
List<Exhibitor> exhibitors = new ArrayList<Exhibitor>();
for (int i = 0; i < 10; i++) {
exhibitors.add(new Exhibitor(i, "aaaaaaaaaaaaaaa"));
}
return exhibitors;
}
public HasClickHandlers getEditExhibitorButton() {
return editExhibitorButton;
}
}
The presenter class:
#Presenter(view = ExhibitorsAdminView.class)
public class ExhibitorsAdminPresenter extends
BasePresenter<ExhibitorsAdminPresenter.IExhibitorsAdminView,
ExhibitorsEventBus> {
public interface IExhibitorsAdminView {
SingleSelectionModel<Exhibitor> getExhibitorsSelectionModel();
ListDataProvider<Exhibitor> getExhibitorsDataProvider();
HasClickHandlers getEditExhibitorButton();
}
private DispatchAsync dispatch = null;
#Inject
public ExhibitorsAdminPresenter(final DispatchAsync dispatch) {
this.dispatch = dispatch;
}
#Override
public void bind() {
getView().getExhibitorsSelectionModel().addSelectionChangeHandler(
new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Exhibitor selected =
getView().getExhibitorsSelectionModel().getSelectedObject();
if (selected != null) {
Window.alert("You selected: " + selected.getName());
}
}
});
getView().getEditExhibitorButton().addClickHandler(
new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
}
public void onGoToExhibitorsAdmin() {
}
public void onLoadExhibitors() {
dispatch.execute(new GetExhibitors(), new
AsyncCallback<GetExhibitorsResult>() {
public void onSuccess(GetExhibitorsResult result) {
getView().getExhibitorsDataProvider().setList(
result.getExhibitors());
getView().getExhibitorsDataProvider().refresh();
}
public void onFailure(Throwable caught) {
GWT.log("error executing command ", caught);
}
});
}
}
Thanks.
I solved it. I'm sorry, it was an issue related with mvp4g. I was doing something wrong that was causing to have to different instances of the view where the CellList was placed. The update operations I was doing on the list of the ListDataProvider were being done on the view instance that wasn't being shown.
You have to manipulate the list by getting it first of your provider like provider.getList().add(...). See How to add or remove a single element from/to CellList? for a minimal example.
Just call exhibitorsDataProvider.refresh() after all operations with underlying list.