1 package autotest.tko; 2 3 import autotest.common.JsonRpcCallback; 4 import autotest.common.ui.TabView; 5 import autotest.tko.PreconfigSelector.PreconfigHandler; 6 import autotest.tko.TableView.TableSwitchListener; 7 8 import com.google.gwt.event.dom.client.ClickEvent; 9 import com.google.gwt.event.dom.client.ClickHandler; 10 import com.google.gwt.json.client.JSONObject; 11 import com.google.gwt.json.client.JSONValue; 12 import com.google.gwt.user.client.ui.Button; 13 import com.google.gwt.user.client.ui.HasHorizontalAlignment; 14 15 import java.util.Map; 16 17 public abstract class DynamicGraphingFrontend extends GraphingFrontend 18 implements ClickHandler, PreconfigHandler { 19 protected PreconfigSelector preconfig; 20 protected Button graphButton = new Button("Graph"); 21 protected Plot plot; 22 private TabView parent; 23 24 public DynamicGraphingFrontend(final TabView parent, Plot plot, String preconfigType) { 25 this.parent = parent; 26 this.plot = plot; 27 plot.setDrilldownTrigger(); 28 preconfig = new PreconfigSelector(preconfigType, this); 29 graphButton.addClickHandler(this); 30 } 31 32 @Override 33 public void onClick(ClickEvent event) { 34 if (event.getSource() != graphButton) { 35 super.onClick(event); 36 return; 37 } 38 39 parent.updateHistory(); 40 plot.setVisible(false); 41 embeddingLink.setVisible(false); 42 graphButton.setEnabled(false); 43 44 JSONObject params = buildParams(); 45 if (params == null) { 46 graphButton.setEnabled(true); 47 return; 48 } 49 50 plot.refresh(params, new JsonRpcCallback() { 51 @Override 52 public void onSuccess(JSONValue result) { 53 plot.setVisible(true); 54 embeddingLink.setVisible(true); 55 graphButton.setEnabled(true); 56 } 57 58 @Override 59 public void onError(JSONObject errorObject) { 60 super.onError(errorObject); 61 graphButton.setEnabled(true); 62 } 63 }); 64 } 65 66 protected abstract JSONObject buildParams(); 67 68 @Override 69 public void refresh() { 70 // Nothing to refresh 71 } 72 73 protected void commonInitialization() { 74 table.setWidget(table.getRowCount(), 1, graphButton); 75 table.setWidget(table.getRowCount(), 0, plot); 76 table.getFlexCellFormatter().setColSpan(table.getRowCount() - 1, 0, 3); 77 78 table.setWidget(table.getRowCount(), 2, embeddingLink); 79 table.getFlexCellFormatter().setHorizontalAlignment( 80 table.getRowCount() - 1, 2, HasHorizontalAlignment.ALIGN_RIGHT); 81 82 plot.setVisible(false); 83 embeddingLink.setVisible(false); 84 85 initWidget(table); 86 } 87 88 public void handlePreconfig(Map<String, String> preconfigParameters) { 89 handleHistoryArguments(preconfigParameters); 90 } 91 92 @Override 93 protected void setListener(TableSwitchListener listener) { 94 super.setListener(listener); 95 plot.setListener(listener); 96 } 97 } 98