private VLayout createDisplayLabel() { String message = "Search for value sets. Select the value sets by checking the checkbox and then click Add to add them."; i_label = new Label("<b>" + message + "<b>"); i_label.setWidth100(); i_label.setHeight(30); i_label.setMargin(2); i_label.setValign(VerticalAlignment.CENTER); i_label.setBackgroundColor(BACKGROUND_COLOR); final VLayout vLayoutLayoutSpacers = new VLayout(); vLayoutLayoutSpacers.setWidth100(); vLayoutLayoutSpacers.setHeight(30); vLayoutLayoutSpacers.setBackgroundColor(BACKGROUND_COLOR); vLayoutLayoutSpacers.setLayoutMargin(6); vLayoutLayoutSpacers.setMembersMargin(6); vLayoutLayoutSpacers.addMember(i_label); return vLayoutLayoutSpacers; }
public ListaVentas(final Sgc_capa_web mainWindow) { String PATH_IMG = "/sgc_capa_web/images/"; VLayout layout = new VLayout(10); layout.setBackgroundColor("#006633"); final ListGrid facturaGrid = new ListGrid(); facturaGrid.setWidth(500); facturaGrid.setHeight(224); facturaGrid.setShowAllRecords(true); facturaGrid.setAlternateRecordStyles(true); facturaGrid.setShowEdges(true); facturaGrid.setBorder("0px"); facturaGrid.setBodyStyleName("normal"); facturaGrid.setLeaveScrollbarGap(false); facturaGrid.setBackgroundColor("#99ffcc"); /*-Buscar ------------------------------*/ DynamicForm buscarFields = new DynamicForm(); // buscarFields.setBackgroundColor("#99ffcc"); buscarFields.setItemLayout(FormLayoutType.ABSOLUTE); final TextItem codigoText = new TextItem("codigo"); codigoText.setWrapTitle(false); codigoText.setLeft(10); codigoText.setWidth(43); codigoText.addKeyPressHandler( new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if ("Enter".equals(event.getKeyName())) { /* buscar por el campo correspondiente */ if (codigoText.getValue() != null) { Factura factura = new Factura(); factura.setId(Integer.parseInt(codigoText.getValue().toString())); listar(facturaGrid, factura, "codigo"); } } } }); ButtonItem buscarButton = new ButtonItem("find", ""); buscarButton.setIcon("view.png"); buscarButton.setWidth(50); buscarButton.setLeft(443); buscarButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { /* buscar por el campo correspondiente */ Factura factura = new Factura(); if (codigoText.getValue() != null) factura.setId(Integer.parseInt(codigoText.getValue().toString())); /*if(nombreusuarioText.getValue() != null) cliente.setNombreusuario(nombreusuarioText.getValue().toString());*/ listar(facturaGrid, factura, "nombre"); } }); buscarFields.setFields(codigoText, buscarButton); /*--------------------------------------*/ ListGridField codigoField = new ListGridField("codigo", "Codigo"); ListGridField fechaField = new ListGridField("fecha", "Fecha"); ListGridField numeroField = new ListGridField("numero", "Numero"); ListGridField pendienteField = new ListGridField("pendiente", "Pendiente"); ListGridField saldoField = new ListGridField("saldo", "Saldo"); ListGridField editarField = new ListGridField("edit", "Editar"); ListGridField borrarField = new ListGridField("remove", "Borrar"); codigoField.setAlign(Alignment.CENTER); editarField.setAlign(Alignment.CENTER); borrarField.setAlign(Alignment.CENTER); editarField.setType(ListGridFieldType.IMAGE); borrarField.setType(ListGridFieldType.IMAGE); editarField.setImageURLPrefix(PATH_IMG); borrarField.setImageURLPrefix(PATH_IMG); editarField.setImageURLSuffix(".png"); borrarField.setImageURLSuffix(".png"); facturaGrid.addCellClickHandler( new CellClickHandler() { @Override public void onCellClick(CellClickEvent event) { ListGridRecord record = event.getRecord(); int col = event.getColNum(); if (col > 4) { Factura factura = new Factura(); factura.setId(record.getAttributeAsInt("codigo")); factura.setFecha(record.getAttributeAsDate("fecha")); factura.setNumero(Integer.parseInt(record.getAttribute("numero"))); factura.setPendiente(record.getAttribute("pendiente")); factura.setSaldo(Double.parseDouble(record.getAttribute("saldo"))); if (col == 5) { /* Editar */ new VentaDetalle(factura, mainWindow); } else { /* Borrar */ FacturaServiceAsync service = GWT.create(FacturaService.class); ServiceDefTarget serviceDef = (ServiceDefTarget) service; serviceDef.setServiceEntryPoint(GWT.getModuleBaseURL() + "facturaService"); try { service.eliminar( record.getAttributeAsInt("codigo"), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { Window.alert( "Ocurrio un error y no se puedo eliminar (objeto referenciado)"); // " // + // caught.getClass().getName() + " " + caught.getMessage()) ; } @Override public void onSuccess(Void result) { new ListaVentas(mainWindow); } }); } catch (NumberFormatException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } } }); codigoField.setWidth(50); fechaField.setWidth(180); numeroField.setWidth(50); pendienteField.setWidth(50); saldoField.setWidth(50); facturaGrid.setFields( codigoField, fechaField, numeroField, pendienteField, saldoField, editarField, borrarField); facturaGrid.setCanResizeFields(true); ButtonItem button = new ButtonItem("add", "Agregar"); button.setStartRow(false); button.setWidth(80); button.setIcon("add.png"); button.setAlign(Alignment.CENTER); button.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { new VentaDetalle(mainWindow); } }); listar(facturaGrid, new Factura(), "nombre"); Label label = new Label(); label.setBackgroundColor("#99ffcc"); label.setHeight(30); label.setWidth(500); label.setPadding(10); label.setAlign(Alignment.CENTER); label.setValign(VerticalAlignment.CENTER); label.setWrap(false); label.setShowEdges(true); label.setContents("<div style='color:black;font-size:15'><b>Lista de Ventas</b></div>"); layout.addMember(label); layout.addMember(buscarFields); layout.addMember(facturaGrid); DynamicForm form = new DynamicForm(); // form.setBackgroundColor("#99ffcc"); form.setWidth(300); form.setItems(button); layout.addMember(form); mainWindow.showDialog(layout); }
private void build() { final VLayout layout = new VLayout(); layout.setMargin(5); final VStack infraLayout = new VStack(); infraLayout.setHeight(26); final Label infraLabel = new Label("Updating available Infrastructures and Policies"); infraLabel.setIcon("loading.gif"); infraLabel.setHeight(26); infraLabel.setAlign(Alignment.CENTER); infraLayout.addMember(infraLabel); final DynamicForm infraForm = new DynamicForm(); infraForm.setEncoding(Encoding.MULTIPART); infraForm.setMethod(FormMethod.POST); infraForm.setAction(GWT.getModuleBaseURL() + "createnodesource"); infraForm.setTarget("__hiddenFrame"); infraLayout.addMember(infraForm); final Label label = new Label( "A Node Source is a combination of an Infrastructure, which defines how resources" + " will be acquired, and a Policy, that dictates when resources can be acquired."); label.setHeight(40); final HashMap<String, List<FormItem>> allForms = new HashMap<String, List<FormItem>>(); controller.fetchSupportedInfrastructuresAndPolicies( new Runnable() { public void run() { infraSelect = new SelectItem("infra", "Infrastructure"); infraSelect.setRequired(true); policySelect = new SelectItem("policy", "Policy"); policySelect.setRequired(true); infraSelect.setWidth(300); policySelect.setWidth(300); HiddenItem name = new HiddenItem("nsName"); HiddenItem callback = new HiddenItem("nsCallback"); HiddenItem session = new HiddenItem("sessionId"); ArrayList<FormItem> tmpAll = new ArrayList<FormItem>(); tmpAll.add(name); tmpAll.add(callback); tmpAll.add(session); tmpAll.add(infraSelect); LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); for (PluginDescriptor inf : controller.getModel().getSupportedInfrastructures().values()) { String shortName = inf.getPluginName().substring(inf.getPluginName().lastIndexOf('.') + 1); values.put(inf.getPluginName(), shortName); List<Field> configurableFields = inf.getConfigurableFields(); ArrayList<FormItem> forms = new ArrayList<FormItem>(configurableFields.size()); for (Field f : configurableFields) { FormItem infra = null; if (f.isPassword()) { infra = new PasswordItem(inf.getPluginName() + f.getName(), f.getName()); } else if (f.isFile() || f.isCredential()) { infra = new UploadItem(inf.getPluginName() + f.getName(), f.getName()); if (f.isCredential()) { PickerIcon cred = new PickerIcon( new Picker(Images.instance.key_16().getSafeUri().asString()), new FormItemClickHandler() { @Override public void onFormItemClick(FormItemIconClickEvent event) { CredentialsWindow win = new CredentialsWindow(); win.show(); } }); cred.setPrompt("Create a Credential file"); cred.setWidth(16); cred.setHeight(16); cred.setAttribute("hspace", 6); infra.setIcons(cred); } } else { infra = new TextItem(inf.getPluginName() + f.getName(), f.getName()); } infra.setValue(f.getValue()); infra.setWidth(250); infra.setHint("<nobr>" + f.getDescription() + "</nobr>"); forms.add(infra); tmpAll.add(infra); } allForms.put(inf.getPluginName(), forms); } infraSelect.setValueMap(values); tmpAll.add(new SpacerItem()); values.clear(); tmpAll.add(policySelect); for (PluginDescriptor inf : controller.getModel().getSupportedPolicies().values()) { String shortName = inf.getPluginName().substring(inf.getPluginName().lastIndexOf('.') + 1); values.put(inf.getPluginName(), shortName); List<Field> configurableFields = inf.getConfigurableFields(); ArrayList<FormItem> forms = new ArrayList<FormItem>(configurableFields.size()); for (Field f : configurableFields) { FormItem pol = null; if (f.isPassword()) { pol = new PasswordItem(inf.getPluginName() + f.getName(), f.getName()); } else if (f.isFile() || f.isCredential()) { pol = new UploadItem(inf.getPluginName() + f.getName(), f.getName()); if (f.isCredential()) { PickerIcon cred = new PickerIcon( new Picker(Images.instance.key_16().getSafeUri().asString()), new FormItemClickHandler() { @Override public void onFormItemClick(FormItemIconClickEvent event) { CredentialsWindow win = new CredentialsWindow(); win.show(); } }); cred.setPrompt("Create a Credential file"); cred.setWidth(16); cred.setHeight(16); cred.setAttribute("hspace", 6); pol.setIcons(cred); } } else { pol = new TextItem(inf.getPluginName() + f.getName(), f.getName()); } pol.setValue(f.getValue()); pol.setWidth(250); pol.setHint("<nobr>" + f.getDescription() + "</nobr>"); forms.add(pol); tmpAll.add(pol); } allForms.put(inf.getPluginName(), forms); } policySelect.setValueMap(values); infraSelectChanged = new Runnable() { @Override public void run() { if (policySelect.getValueAsString() == null) { return; } String nsName = infraSelect.getValueAsString(); if (oldInfra != null) { for (FormItem f : allForms.get(oldInfra)) { f.hide(); } } for (FormItem f : allForms.get(nsName)) { f.show(); } if (oldInfra == null) { oldInfra = nsName; policySelectChanged.run(); } else { oldInfra = nsName; } } }; policySelectChanged = new Runnable() { @Override public void run() { if (infraSelect.getValueAsString() == null) { return; } String policy = policySelect.getValueAsString(); if (oldPolicy != null) { for (FormItem f : allForms.get(oldPolicy)) { f.hide(); } } for (FormItem f : allForms.get(policy)) { f.show(); } if (oldPolicy == null) { oldPolicy = policy; infraSelectChanged.run(); } else { oldPolicy = policy; } } }; infraSelect.addChangedHandler( new ChangedHandler() { public void onChanged(ChangedEvent event) { infraSelectChanged.run(); } }); policySelect.addChangedHandler( new ChangedHandler() { public void onChanged(ChangedEvent event) { policySelectChanged.run(); } }); infraForm.setFields(tmpAll.toArray(new FormItem[tmpAll.size()])); infraLabel.hide(); infraForm.show(); for (List<FormItem> li : allForms.values()) { for (FormItem it : li) { it.hide(); } } } }, new Runnable() { @Override public void run() { window.hide(); } }); final TextItem nameItem = new TextItem("nsName", "Name"); DynamicForm nameForm = new DynamicForm(); nameForm.setFields(nameItem); HLayout buttons = new HLayout(); buttons.setWidth100(); buttons.setHeight(22); buttons.setMargin(5); buttons.setAlign(Alignment.RIGHT); buttons.setMembersMargin(5); final IButton okButton = new IButton("Ok"); okButton.setIcon(Images.instance.ok_16().getSafeUri().asString()); okButton.setShowDisabledIcon(false); final IButton cancelButton = new IButton("Cancel"); cancelButton.setIcon(Images.instance.cancel_16().getSafeUri().asString()); cancelButton.setShowDisabledIcon(false); okButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { infraForm.setValue("infra", infraSelect.getValueAsString()); infraForm.setValue("nsName", nameItem.getValueAsString()); infraForm.setValue("policy", policySelect.getValueAsString()); infraForm.setValue("sessionId", LoginModel.getInstance().getSessionId()); infraForm.setCanSubmit(true); /* this smartGWT form looks nice but cannot do callbacks ; * we register a native JS function to the document, send it to * the servlet so that it writes it back when returning * when the browser reads the return value and interprets it as JS, * the callback is called */ infraForm.setValue( "nsCallback", JSUtil.register( new JSUtil.JSCallback() { public void execute(JavaScriptObject obj) { JSONObject js = new JSONObject(obj); if (js.containsKey("result") && js.get("result").isBoolean().booleanValue()) { window.hide(); LogModel.getInstance() .logMessage( "Successfully created nodesource: " + nameItem.getValueAsString()); } else { String msg; if (js.get("errorMessage").isString() != null) { msg = js.get("errorMessage").isString().stringValue(); } else { msg = js.toString(); } label.setContents( "<span style='color:red'>Failed to create Node Source :<br>" + msg + "</span>"); LogModel.getInstance() .logImportantMessage( "Failed to create nodesource " + nameItem.getValueAsString() + ": " + msg); layout.scrollToTop(); } infraLabel.hide(); infraForm.show(); okButton.setDisabled(false); cancelButton.setDisabled(false); } })); infraForm.submitForm(); cancelButton.setDisabled(true); okButton.setDisabled(true); infraLabel.setContents("Node Source creation requested..."); infraLabel.show(); infraForm.hide(); } }); cancelButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { window.hide(); } }); buttons.setMembers(okButton, cancelButton); VLayout scroll = new VLayout(); scroll.setHeight100(); scroll.setWidth100(); scroll.setMembers(infraLayout); scroll.setOverflow(Overflow.AUTO); scroll.setBorder("1px solid #ddd"); scroll.setBackgroundColor("#fafafa"); layout.addMember(label); layout.addMember(nameForm); layout.addMember(scroll); layout.addMember(buttons); int winWidth = com.google.gwt.user.client.Window.getClientWidth() * 80 / 100; int winHeight = com.google.gwt.user.client.Window.getClientHeight() * 80 / 100; winWidth = Math.min(1000, winWidth); winHeight = Math.min(1000, winHeight); this.window = new Window(); this.window.setTitle("Create Node Source"); this.window.setShowMinimizeButton(false); this.window.setIsModal(true); this.window.setShowModalMask(true); this.window.addItem(layout); this.window.setWidth(winWidth); this.window.setHeight(winHeight); this.window.setCanDragResize(true); this.window.setCanDragReposition(true); this.window.centerInPage(); }