List of usage examples for com.google.gwt.http.client RequestBuilder setRequestData
public void setRequestData(String requestData)
From source file:org.openmoney.omlets.mobile.client.utils.RestRequest.java
License:Open Source License
/** * Sends a request using the given callback to notify the results. * This method does not uses authentication, to perform authenticated * requests see {@link #sendAuthenticated(AsyncCallback)} *///from w w w .j av a 2s . c o m public Request send(AsyncCallback<T> callback) { // Start loading progress OmletsMobile.get().getMainLayout().startLoading(); String url = ""; // Append parameters as GET if (httpMethod == RequestBuilder.GET) { url = Configuration.get().getServiceUrl(this.path, parameters); } else { url = Configuration.get().getServiceUrl(this.path); } ErrorHandler.debug("RestRequest:" + httpMethod + ",url:" + url); RequestBuilder request = new RequestBuilder(httpMethod, url); request.setTimeoutMillis(40 * 1000); // 40 seconds request.setHeader("Accept", "application/json"); request.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); if (httpMethod == RequestBuilder.POST) { request.setHeader("Content-Type", "application/json"); // Send post body parameters if (parameters != null) { String json = parameters.toJSON(); request.setRequestData(json); } else { // Send post without data request.setRequestData(""); } } // Send a JSON post object if (postObject != null) { request.setHeader("Content-Type", "application/json"); request.setRequestData(new JSONObject(postObject).toString()); } if (username != null && !username.isEmpty()) { request.setHeader("Authorization", "Basic " + Base64.encode(username + ":" + password)); } request.setCallback(new RequestCallbackAdapter(callback)); try { // Send request return request.send(); } catch (RequestException e) { callback.onFailure(e); // Stop loading progress OmletsMobile.get().getMainLayout().stopLoading(); // Returns an emulated request, which does nothing return new Request() { @Override public void cancel() { } @Override public boolean isPending() { return false; } }; } }
From source file:org.opentaps.gwt.common.client.listviews.EntityEditableListView.java
License:Open Source License
/** * Handles the save all batch action, this takes all records that need * to be created, update or deleted and send them in one request. * The posted data is the same format as for a <code>service-multi</code>. *//*from www . j a v a 2 s . c o m*/ protected void doBatchAction() { UtilUi.logInfo("doBatchAction ...", MODULE, "doBatchAction"); String data = makeBatchPostData(); if (data == null) { UtilUi.logInfo("nothing to do", MODULE, "doBatchAction"); return; } RequestBuilder request = new RequestBuilder(RequestBuilder.POST, GWT.getHostPageBaseURL() + saveAllUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(data); request.setTimeoutMillis(UtilLookup.getAjaxDefaultTimeout()); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message markGridNotBusy(); UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // if it is a correct response, reload the grid markGridNotBusy(); UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "doBatchAction"); if (!ServiceErrorReader.showErrorMessageIfAny(response, saveAllUrl)) { // commit store changes getStore().commitChanges(); loadFirstPage(); } } }); try { markGridBusy(); UtilUi.logInfo("posting batch", MODULE, "doBatchAction"); request.send(); } catch (RequestException e) { // display error message UtilUi.errorMessage(e.toString(), MODULE, "doBatchAction"); } }
From source file:org.opentaps.gwt.common.client.services.Service.java
License:Open Source License
/** * Sends the request and get the result asynchronously. * @param cb an <code>AsyncCallback</code> instance for the returned <code>Record</code> */// www .j a v a2s. c o m public void request(final AsyncCallback<Record> cb) { RequestBuilder request = new RequestBuilder(RequestBuilder.POST, GWT.getHostPageBaseURL() + url); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(data); request.setTimeoutMillis(UtilLookup.getAjaxDefaultTimeout()); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message if (autoPopupErrors) { UtilUi.errorMessage(exception.toString()); } else { UtilUi.logError("onError, error = " + exception.toString(), MODULE, "request"); } cb.onFailure(exception); } public void onResponseReceived(Request request, Response response) { UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "request"); String err = ServiceErrorReader.getErrorMessageIfAny(response, url); if (err == null) { if (store != null) { store.loadJsonData(response.getText(), false); Record rec = null; if (store.getTotalCount() > 0) { rec = store.getRecordAt(0); } cb.onSuccess(rec); } } else { if (autoPopupErrors) { UtilUi.errorMessage(err); } else { UtilUi.logError("onResponseReceived, error = " + err, MODULE, "request"); } cb.onFailure(new RequestException(err)); } } }); try { UtilUi.logInfo("posting request", MODULE, "request"); request.send(); } catch (RequestException e) { if (autoPopupErrors) { UtilUi.errorMessage(e.toString()); } else { UtilUi.logError("Caught RequestException, error = " + e.toString(), MODULE, "request"); } cb.onFailure(e); } }
From source file:org.opentaps.gwt.crmsfa.client.accounts.form.AccountsSublistView.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w.j a v a 2 s .co m public void init() { String entityViewUrl = "/crmsfa/control/viewAccount?partyId={0}"; StringFieldDef idDefinition = new StringFieldDef(PartyLookupConfiguration.INOUT_PARTY_ID); makeLinkColumn(UtilUi.MSG.crmContactId(), idDefinition, entityViewUrl, true); makeLinkColumn(UtilUi.MSG.crmAccountName(), idDefinition, new StringFieldDef(PartyLookupConfiguration.INOUT_FRIENDLY_PARTY_NAME), entityViewUrl, true); makeColumn(UtilUi.MSG.partyCity(), new StringFieldDef(PartyLookupConfiguration.INOUT_CITY)); makeColumn(UtilUi.MSG.crmPrimaryEmail(), new StringFieldDef(PartyLookupConfiguration.INOUT_EMAIL)); makeColumn(UtilUi.MSG.crmPrimaryPhone(), new StringFieldDef(PartyLookupConfiguration.INOUT_FORMATED_PHONE_NUMBER)); makeColumn(UtilUi.MSG.partyToName(), new StringFieldDef(PartyLookupConfiguration.INOUT_TO_NAME)); makeColumn(UtilUi.MSG.partyAttentionName(), new StringFieldDef(PartyLookupConfiguration.INOUT_ATTENTION_NAME)); makeColumn(UtilUi.MSG.partyAddressLine1(), new StringFieldDef(PartyLookupConfiguration.INOUT_ADDRESS)); makeColumn(UtilUi.MSG.partyAddressLine2(), new StringFieldDef(PartyLookupConfiguration.OUT_ADDRESS_2)); makeColumn(UtilUi.MSG.partyState(), new StringFieldDef(PartyLookupConfiguration.INOUT_STATE)); makeColumn(UtilUi.MSG.partyCountry(), new StringFieldDef(PartyLookupConfiguration.INOUT_COUNTRY)); makeColumn(UtilUi.MSG.partyPostalCode(), new StringFieldDef(PartyLookupConfiguration.INOUT_POSTAL_CODE)); makeColumn(UtilUi.MSG.crmPostalCodeExt(), new StringFieldDef(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT)); // add last column if logged in user has required permission deleteColumnIndex = getCurrentColumnIndex(); if (hasAccountsRemoveAbility()) { ColumnConfig config = makeColumn("", new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { return Format.format("<img width=\"15\" height=\"15\" class=\"checkbox\" src=\"{0}\"/>", UtilUi.ICON_DELETE); } }); config.setWidth(26); config.setResizable(false); config.setFixed(true); config.setSortable(false); addGridCellListener(new GridCellListenerAdapter() { private final String actionUrl = "/crmsfa/control/removeContactFromAccountAJX"; /** {@inheritDoc} */ @Override public void onCellClick(GridPanel grid, int rowIndex, int colindex, EventObject e) { if (colindex == AccountsSublistView.this.deleteColumnIndex) { String accountPartyId = getStore().getRecordAt(rowIndex).getAsString("partyId"); RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(Format.format("partyId={0}&contactPartyId={0}&accountPartyId={1}", AccountsSublistView.this.contactPartyId, accountPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message markGridNotBusy(); UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // if it is a correct response, reload the grid markGridNotBusy(); UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "ContactListView.init()"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { getStore().reload(); loadFirstPage(); } } }); try { markGridBusy(); UtilUi.logInfo("posting batch", MODULE, "ContactListView.init()"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(e.toString(), MODULE, "ContactListView.init()"); } } } }); } configure(PartyLookupConfiguration.URL_FIND_ACCOUNTS, PartyLookupConfiguration.INOUT_PARTY_ID, SortDir.ASC); // by default, hide non essential columns setColumnHidden(PartyLookupConfiguration.INOUT_PARTY_ID, true); setColumnHidden(PartyLookupConfiguration.INOUT_STATE, true); setColumnHidden(PartyLookupConfiguration.INOUT_COUNTRY, true); setColumnHidden(PartyLookupConfiguration.INOUT_TO_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ATTENTION_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ADDRESS, true); setColumnHidden(PartyLookupConfiguration.OUT_ADDRESS_2, true); setColumnHidden(PartyLookupConfiguration.INOUT_POSTAL_CODE, true); setColumnHidden(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT, true); }
From source file:org.opentaps.gwt.crmsfa.client.contacts.form.ContactsSublistView.java
License:Open Source License
/** {@inheritDoc} */ @Override/*w w w.j ava 2 s. c om*/ public void init() { String entityViewUrl = "/crmsfa/control/viewContact?partyId={0}"; StringFieldDef idDefinition = new StringFieldDef(PartyLookupConfiguration.INOUT_PARTY_ID); makeLinkColumn(UtilUi.MSG.crmContactId(), idDefinition, entityViewUrl, true); makeLinkColumn(UtilUi.MSG.crmContactName(), idDefinition, new StringFieldDef(PartyLookupConfiguration.INOUT_FRIENDLY_PARTY_NAME), entityViewUrl, true); makeColumn(UtilUi.MSG.partyCity(), new StringFieldDef(PartyLookupConfiguration.INOUT_CITY)); makeColumn(UtilUi.MSG.crmPrimaryEmail(), new StringFieldDef(PartyLookupConfiguration.INOUT_EMAIL)); makeColumn(UtilUi.MSG.crmPrimaryPhone(), new StringFieldDef(PartyLookupConfiguration.INOUT_FORMATED_PHONE_NUMBER)); makeColumn(UtilUi.MSG.partyToName(), new StringFieldDef(PartyLookupConfiguration.INOUT_TO_NAME)); makeColumn(UtilUi.MSG.partyAttentionName(), new StringFieldDef(PartyLookupConfiguration.INOUT_ATTENTION_NAME)); makeColumn(UtilUi.MSG.partyAddressLine1(), new StringFieldDef(PartyLookupConfiguration.INOUT_ADDRESS)); makeColumn(UtilUi.MSG.partyAddressLine2(), new StringFieldDef(PartyLookupConfiguration.OUT_ADDRESS_2)); makeColumn(UtilUi.MSG.partyState(), new StringFieldDef(PartyLookupConfiguration.INOUT_STATE)); makeColumn(UtilUi.MSG.partyCountry(), new StringFieldDef(PartyLookupConfiguration.INOUT_COUNTRY)); makeColumn(UtilUi.MSG.partyPostalCode(), new StringFieldDef(PartyLookupConfiguration.INOUT_POSTAL_CODE)); makeColumn(UtilUi.MSG.crmPostalCodeExt(), new StringFieldDef(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT)); // add Remove button if user has required permission if (hasRemovePermission(isOpportunity)) { deleteColumnIndex = getCurrentColumnIndex(); ColumnConfig config = makeColumn("", new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { return Format.format("<img width=\"15\" height=\"15\" class=\"checkbox\" src=\"{0}\"/>", UtilUi.ICON_DELETE); } }); config.setWidth(26); config.setResizable(false); config.setFixed(true); config.setSortable(false); addGridCellListener(new GridCellListenerAdapter() { private final String actionUrl = isOpportunity ? "/crmsfa/control/removeContactFromOpportunityAJX" : "/crmsfa/control/removeContactFromAccountAJX"; /** {@inheritDoc} */ @Override public void onCellClick(GridPanel grid, int rowIndex, int colindex, EventObject e) { if (colindex == ContactsSublistView.this.deleteColumnIndex) { String contactPartyId = getStore().getRecordAt(rowIndex).getAsString("partyId"); RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); if (isOpportunity) { request.setRequestData(Format.format("salesOpportunityId={0}&contactPartyId={1}", ContactsSublistView.this.entityId, contactPartyId)); } else { request.setRequestData( Format.format("partyId={0}&accountPartyId={0}&contactPartyId={1}", ContactsSublistView.this.entityId, contactPartyId)); } request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message markGridNotBusy(); UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // if it is a correct response, reload the grid markGridNotBusy(); UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "ContactListView.init()"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { // commit store changes getStore().reload(); loadFirstPage(); } } }); try { markGridBusy(); UtilUi.logInfo("posting batch", MODULE, "ContactListView.init()"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(e.toString(), MODULE, "ContactListView.init()"); } } } }); } configure(PartyLookupConfiguration.URL_FIND_CONTACTS, PartyLookupConfiguration.INOUT_PARTY_ID, SortDir.ASC); // by default, hide non essential columns setColumnHidden(PartyLookupConfiguration.INOUT_PARTY_ID, true); setColumnHidden(PartyLookupConfiguration.INOUT_STATE, true); setColumnHidden(PartyLookupConfiguration.INOUT_COUNTRY, true); setColumnHidden(PartyLookupConfiguration.INOUT_TO_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ATTENTION_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ADDRESS, true); setColumnHidden(PartyLookupConfiguration.OUT_ADDRESS_2, true); setColumnHidden(PartyLookupConfiguration.INOUT_POSTAL_CODE, true); setColumnHidden(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT, true); }
From source file:org.opentaps.gwt.crmsfa.client.Entry.java
License:Open Source License
/** * This method setup a button into subsection title at right-hand position * and allow to assign a new account using lookup accounts window. * @param container <code>RootPanel</code> that is root container for button * @param contactAccounts parent accounts list view. *//* ww w .j ava 2 s . c om*/ private void loadAssignAccountToContactWidget(RootPanel container, final AccountsSublistView contactAccounts) { // create lookup window final LookupAccountsWindow window = new LookupAccountsWindow(true, true); window.create(); // register listener to be notified when user selects an account window.register(new FormNotificationInterface<String>() { /** {@inheritDoc} */ public void notifySuccess(String obj) { if (obj == null) { return; } final String actionUrl = "/crmsfa/control/assignAccountToContactAJX"; // keep user's selection String accountPartyId = obj; // nothing special, just send HTTP POST request // and run crmsfa.assignContactToAccount service RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(Format.format("partyId={0}&contactPartyId={0}&accountPartyId={1}", getPartyId(), accountPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // we don't expect anything from server, just reload the list of contacts UtilUi.logInfo("onResponseReceived, response = " + response, "", "loadAssignContactToAccountWidget"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { contactAccounts.getStore().reload(); contactAccounts.loadFirstPage(); } contactAccounts.markGridNotBusy(); } }); try { contactAccounts.markGridBusy(); UtilUi.logInfo("Run service crmsfa.assignContactToAccount", MODULE, "loadAssignContactToAccountWidget"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(re.toString(), MODULE, "loadAssignContactToAccountWidget"); } } }); // create hyperlink as submenu button Button embedLink = new Button(UtilUi.MSG.crmAssignAccount(), new ClickHandler() { public void onClick(ClickEvent event) { window.show(); } }); embedLink.setStyleName("subMenuButton"); // place [Assign Contact] button on page container.add(embedLink); }
From source file:org.opentaps.gwt.crmsfa.client.Entry.java
License:Open Source License
/** * This method setup a button into subsection title at right-hand position * and allow to assign a new contact using lookup contacts window. * @param container <code>RootPanel</code> that is root container for button * @param opportunityContacts parent contacts list view. *//*from w w w . jav a 2 s .c o m*/ private void loadAssignContactToOpportunityWidget(RootPanel container, final ContactsSublistView opportunityContacts) { // create lookup window final LookupContactsWindow window = new LookupContactsWindow(true, true); window.create(); // register listener to be notified when user selects a contact window.register(new FormNotificationInterface<String>() { /** {@inheritDoc} */ public void notifySuccess(String obj) { if (obj == null) { return; } final String actionUrl = "/crmsfa/control/addContactToOpportunityAJX"; // keep user's selection String contactPartyId = obj; // nothing special, just send HTTP POST request // and run crmsfa.assignContactToAccount service RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(Format.format("salesOpportunityId={0}&contactPartyId={1}", getSalesOpportunityId(), contactPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // we don't expect anything from server, just reload the list of contacts UtilUi.logInfo("onResponseReceived, response = " + response, "", "loadAssignContactToAccountWidget"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { opportunityContacts.getStore().reload(); opportunityContacts.loadFirstPage(); } opportunityContacts.markGridNotBusy(); } }); try { opportunityContacts.markGridBusy(); UtilUi.logInfo("Run service crmsfa.assignContactToAccount", MODULE, "loadAssignContactToAccountWidget"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(re.toString(), MODULE, "loadAssignContactToAccountWidget"); } } }); // create hyperlink as submenu button Button embedLink = new Button(UtilUi.MSG.crmAssignContact(), new ClickHandler() { public void onClick(ClickEvent event) { window.show(); } }); embedLink.setStyleName("subMenuButton"); // place [Assign Contact] button on page container.add(embedLink); }
From source file:org.opentaps.gwt.crmsfa.client.Entry.java
License:Open Source License
/** * This method setup a button into subsection title at right-hand position * and allow to assign a new contact using lookup contacts window. * @param container <code>RootPanel</code> that is root container for button * @param accountContacts parent contacts list view. *///from w ww . j a v a 2 s . com private void loadAssignContactToAccountWidget(RootPanel container, final ContactsSublistView accountContacts) { // create lookup window final LookupContactsWindow window = new LookupContactsWindow(true, true); window.create(); // register listener to be notified when user selects a contact window.register(new FormNotificationInterface<String>() { /** {@inheritDoc} */ public void notifySuccess(String obj) { if (obj == null) { return; } final String actionUrl = "/crmsfa/control/assignContactToAccountAJX"; // keep user's selection String contactPartyId = obj; // nothing special, just send HTTP POST request // and run crmsfa.assignContactToAccount service RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(Format.format("partyId={0}&accountPartyId={0}&contactPartyId={1}", getPartyId(), contactPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // we don't expect anything from server, just reload the list of contacts UtilUi.logInfo("onResponseReceived, response = " + response, "", "loadAssignContactToAccountWidget"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { accountContacts.getStore().reload(); accountContacts.loadFirstPage(); } accountContacts.markGridNotBusy(); } }); try { accountContacts.markGridBusy(); UtilUi.logInfo("Run service crmsfa.assignContactToAccount", MODULE, "loadAssignContactToAccountWidget"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(re.toString(), MODULE, "loadAssignContactToAccountWidget"); } } }); // create hyperlink as submenu button Button embedLink = new Button(UtilUi.MSG.crmAssignContact(), new ClickHandler() { public void onClick(ClickEvent event) { window.show(); } }); embedLink.setStyleName("subMenuButton"); // place [Assign Contact] button on page container.add(embedLink); }
From source file:org.opentaps.gwt.crmsfa.client.opportunities.form.OpportunityContactsSubview.java
License:Open Source License
/** * Constructor with autoLoad parameter, use this constructor if some filters need to be set prior to loading the grid data. * @param autoLoad sets the grid autoLoad parameter, set to <code>false</code> if some filters need to be set prior to loading the grid data *//*from w w w . j a v a 2 s. co m*/ public OpportunityContactsSubview(String accountPartyId, boolean autoLoad) { super(UtilUi.MSG.crmContactId(), UtilUi.MSG.crmFindContacts()); this.accountPartyId = accountPartyId; contactListView = new ContactListView() { /** {@inheritDoc} */ @Override public void init() { String entityViewUrl = "/crmsfa/control/viewContact?partyId={0}"; StringFieldDef idDefinition = new StringFieldDef(PartyLookupConfiguration.INOUT_PARTY_ID); makeLinkColumn(UtilUi.MSG.crmContactId(), idDefinition, entityViewUrl, true); makeLinkColumn(UtilUi.MSG.crmContactName(), idDefinition, new StringFieldDef(PartyLookupConfiguration.INOUT_FRIENDLY_PARTY_NAME), entityViewUrl, true); makeColumn(UtilUi.MSG.partyCity(), new StringFieldDef(PartyLookupConfiguration.INOUT_CITY)); makeColumn(UtilUi.MSG.crmPrimaryEmail(), new StringFieldDef(PartyLookupConfiguration.INOUT_EMAIL)); makeColumn(UtilUi.MSG.crmPrimaryPhone(), new StringFieldDef(PartyLookupConfiguration.INOUT_FORMATED_PHONE_NUMBER)); makeColumn(UtilUi.MSG.partyToName(), new StringFieldDef(PartyLookupConfiguration.INOUT_TO_NAME)); makeColumn(UtilUi.MSG.partyAttentionName(), new StringFieldDef(PartyLookupConfiguration.INOUT_ATTENTION_NAME)); makeColumn(UtilUi.MSG.partyAddressLine1(), new StringFieldDef(PartyLookupConfiguration.INOUT_ADDRESS)); makeColumn(UtilUi.MSG.partyAddressLine2(), new StringFieldDef(PartyLookupConfiguration.OUT_ADDRESS_2)); makeColumn(UtilUi.MSG.partyState(), new StringFieldDef(PartyLookupConfiguration.INOUT_STATE)); makeColumn(UtilUi.MSG.partyCountry(), new StringFieldDef(PartyLookupConfiguration.INOUT_COUNTRY)); makeColumn(UtilUi.MSG.partyPostalCode(), new StringFieldDef(PartyLookupConfiguration.INOUT_POSTAL_CODE)); makeColumn(UtilUi.MSG.crmPostalCodeExt(), new StringFieldDef(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT)); deleteColumnIndex = getCurrentColumnIndex(); ColumnConfig config = makeColumn("", new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { return Format.format("<img width=\"15\" height=\"15\" class=\"checkbox\" src=\"{0}\"/>", UtilUi.ICON_DELETE); } }); config.setWidth(26); config.setResizable(false); config.setFixed(true); config.setSortable(false); addGridCellListener(new GridCellListenerAdapter() { private final String actionUrl = "/crmsfa/control/removeContactFromAccount"; /** {@inheritDoc} */ @Override public void onCellClick(GridPanel grid, int rowIndex, int colindex, EventObject e) { if (colindex == OpportunityContactsSubview.this.deleteColumnIndex) { String contactPartyId = getStore().getRecordAt(rowIndex).getAsString("partyId"); RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData( Format.format("partyId={0}&accountPartyId={0}&contactPartyId={1}", OpportunityContactsSubview.this.accountPartyId, contactPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message markGridNotBusy(); UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // if it is a correct response, reload the grid markGridNotBusy(); UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "ContactListView.init()"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { // commit store changes getStore().reload(); loadFirstPage(); } } }); try { markGridBusy(); UtilUi.logInfo("posting batch", MODULE, "ContactListView.init()"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(e.toString(), MODULE, "ContactListView.init()"); } } } }); configure(PartyLookupConfiguration.URL_FIND_CONTACTS, PartyLookupConfiguration.INOUT_PARTY_ID, SortDir.ASC); // by default, hide non essential columns setColumnHidden(PartyLookupConfiguration.INOUT_PARTY_ID, true); setColumnHidden(PartyLookupConfiguration.INOUT_STATE, true); setColumnHidden(PartyLookupConfiguration.INOUT_COUNTRY, true); setColumnHidden(PartyLookupConfiguration.INOUT_TO_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ATTENTION_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ADDRESS, true); setColumnHidden(PartyLookupConfiguration.OUT_ADDRESS_2, true); setColumnHidden(PartyLookupConfiguration.INOUT_POSTAL_CODE, true); setColumnHidden(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT, true); } }; contactListView.setHeader(false); contactListView.setAutoLoad(autoLoad); contactListView.init(); addListView(contactListView); }
From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.GeneralPanel.java
License:Open Source License
@Override public List<RequestBuilder> prepareRequests() { ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>(); String moduleBaseURL = GWT.getModuleBaseURL(); String moduleName = GWT.getModuleName(); String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName)); String setMetadataUrl = contextURL + "api/repo/files/" //$NON-NLS-1$ + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/metadata?cb=" //$NON-NLS-1$ + System.currentTimeMillis(); RequestBuilder setMetadataBuilder = new RequestBuilder(RequestBuilder.PUT, setMetadataUrl); setMetadataBuilder.setHeader("Content-Type", "application/json"); setMetadataBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); // prepare request data JSONArray arr = new JSONArray(); JSONObject metadata = new JSONObject(); metadata.put("stringKeyStringValueDto", arr); for (int i = 0; i < metadataPerms.size(); i++) { Set<String> keys = metadataPerms.get(i).keySet(); for (String key : keys) { if (key != null && SolutionBrowserPanel.getInstance().isAdministrator()) { if (key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.SCHEDULABLE_KEY) && !fileSummary.isFolder() || key.equals(org.pentaho.platform.api.repository2.unified.RepositoryFile.HIDDEN_KEY)) { JSONObject obj = new JSONObject(); obj.put("key", new JSONString(key)); obj.put("value", metadataPerms.get(i).get(key).isString()); arr.set(i, obj);//from w ww. ja va 2 s . c om } } } } // setMetadataBuilder.sendRequest(metadata.toString(), setMetadataCallback); if (arr.size() > 0) { setMetadataBuilder.setRequestData(metadata.toString()); requestBuilders.add(setMetadataBuilder); } return requestBuilders; }