Java Code Examples for com.smartgwt.client.widgets.form.DynamicForm#setMargin()

The following examples show how to use com.smartgwt.client.widgets.form.DynamicForm#setMargin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceManager.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private DynamicForm createForm() {
    DynamicForm df = new DynamicForm();
    df.setMargin(4);
    df.setNumCols(1);
    df.setTitleOrientation(TitleOrientation.TOP);
    df.setBrowserSpellCheck(false);
    df.setDataSource(DeviceDataSource.getInstance());
    TextItem fieldId = new TextItem(DeviceDataSource.FIELD_ID);
    fieldId.setWidth(280);
    fieldId.setCanEdit(false);
    fieldId.setReadOnlyDisplay(ReadOnlyDisplayAppearance.STATIC);
    TextItem fieldModel = new TextItem(DeviceDataSource.FIELD_MODEL);
    fieldModel.setCanEdit(false);
    fieldModel.setRequired(true);
    TextItem fieldLabel = new TextItem(DeviceDataSource.FIELD_LABEL);
    fieldLabel.setRequired(true);
    fieldLabel.setWidth("*");
    df.setItems(fieldId, fieldModel,  fieldLabel);
    return df;
}
 
Example 2
Source File: NewDigObject.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private DynamicForm createOptionsForm() {
        SelectItem selectModel = new SelectItem(DigitalObjectDataSource.FIELD_MODEL,
                i18n.NewDigObject_OptionModel_Title());
        selectModel.setRequired(true);
        selectModel.setWidth(300);
        // issue 46: always start with empty model
        selectModel.setAllowEmptyValue(true);
        selectModel.setEmptyDisplayValue(ClientUtils.format("<i>&lt;%s&gt;</i>", i18n.NewDigObject_OptionModel_EmptyValue_Title()));
        selectModel.setOptionDataSource(MetaModelDataSource.getInstance());
//        selectModel.setShowOptionsFromDataSource(true);
        selectModel.setValueField(MetaModelDataSource.FIELD_PID);
        selectModel.setDisplayField(MetaModelDataSource.FIELD_DISPLAY_NAME);
        selectModel.setAutoFetchData(true);
        selectModel.setValidators(new CustomValidator() {

            @Override
            protected boolean condition(Object value) {
                boolean valid = getFormItem().getSelectedRecord() != null;
                return valid;
            }
        });

        TextItem newPid = new TextItem(DigitalObjectDataSource.FIELD_PID);
        newPid.setTitle(i18n.NewDigObject_OptionPid_Title());
        newPid.setTooltip(i18n.NewDigObject_OptionPid_Hint());
        newPid.setLength(36 + 5);
        newPid.setWidth((36 + 5) * 8);
        newPid.setValidators(new CustomUUIDValidator(i18n));
        //newPid.setValidators(new RegExpValidator(
        //        "uuid:[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}"));
        DynamicForm form = new DynamicForm();
        form.setWrapItemTitles(false);
        form.setAutoFocus(true);
        form.setNumCols(4);
        form.setBrowserSpellCheck(false);
        form.setFields(selectModel, newPid);
        form.setAutoWidth();
        form.setMargin(4);
        return form;
    }
 
Example 3
Source File: SaveDialog.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public SaveDialog() {
	super();

	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(I18N.message("savesearch"));
	setWidth(350);
	setHeight(100);
	setCanDragResize(true);
	setIsModal(true);
	setShowModalMask(true);
	centerInPage();
	setPadding(5);
	setAutoSize(true);

	final ValuesManager vm = new ValuesManager();
	final DynamicForm form = new DynamicForm();
	form.setValuesManager(vm);
	form.setWidth(350);
	form.setMargin(5);

	TextItem name = ItemFactory.newTextItem("name", "name", null);
	name.setRequired(true);
	name.setValidators(new SimpleTextValidator());
	name.setWidth(100);

	TextItem description = ItemFactory.newTextItem("description", "description", null);
	description.setWidth(300);

	ButtonItem save = new ButtonItem();
	save.setTitle(I18N.message("save"));
	save.setAutoFit(true);
	save.addClickHandler(new ClickHandler() {
		public void onClick(ClickEvent event) {
			vm.validate();
			if (!vm.hasErrors()) {
				final GUISearchOptions options = Search.get().getOptions();
				options.setName(vm.getValueAsString("name"));
				options.setDescription(vm.getValueAsString("description"));
				SearchService.Instance.get().save(Search.get().getOptions(), new AsyncCallback<Boolean>() {

					@Override
					public void onFailure(Throwable caught) {
						Log.serverError(caught);
					}

					@Override
					public void onSuccess(Boolean b) {
						if (!b)
							SC.warn(I18N.message("duplicateelement"));
						else {
							SavedSearchesPanel.get().addEntry(
									vm.getValueAsString("name"),
									vm.getValueAsString("description"),
									options.getType() == GUISearchOptions.TYPE_FULLTEXT ? I18N.message("fulltext")
											: I18N.message("parametric"));
							destroy();
						}
					}
				});
			}
		}
	});

	form.setFields(name, description, save);
	addItem(form);
}
 
Example 4
Source File: ContactDetails.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ContactDetails(final GUIContact contact, final Contacts parent) {
	super();

	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(I18N.message("contact"));
	setWidth(500);
	setAutoHeight();
	setIsModal(true);
	setShowModalMask(true);
	centerInPage();
	setAutoSize(true);

	final ValuesManager vm = new ValuesManager();
	final DynamicForm form = new DynamicForm();
	form.setValuesManager(vm);
	form.setMargin(5);
	form.setNumCols(3);
	form.setTitleOrientation(TitleOrientation.TOP);

	TextItem firstName = ItemFactory.newTextItem("firstname", "firstname", contact.getFirstName());
	TextItem lastName = ItemFactory.newTextItem("lastname", "lastname", contact.getLastName());
	TextItem email = ItemFactory.newEmailItem("email", "email", false);
	email.setRequired(true);
	email.setValue(contact.getEmail());
	TextItem address = ItemFactory.newTextItem("address", "address", contact.getAddress());
	TextItem phone = ItemFactory.newTextItem("phone", "phone", contact.getPhone());
	TextItem cell = ItemFactory.newTextItem("cell", "cell", contact.getMobile());
	TextItem company = ItemFactory.newTextItem("company", "company", contact.getCompany());
	company.setWidth(180);

	ButtonItem save = new ButtonItem();
	save.setTitle(I18N.message("save"));
	save.setAutoFit(true);
	save.addClickHandler(new ClickHandler() {
		public void onClick(ClickEvent event) {
			vm.validate();
			if (!vm.hasErrors()) {

				GUIContact c = new GUIContact();
				c.setId(contact.getId());
				c.setUserId(Session.get().getUser().getId());
				c.setFirstName(vm.getValueAsString("firstname"));
				c.setLastName(vm.getValueAsString("lastname"));
				c.setEmail(vm.getValueAsString("email"));
				c.setAddress(vm.getValueAsString("address"));
				c.setPhone(vm.getValueAsString("phone"));
				c.setMobile(vm.getValueAsString("cell"));
				c.setCompany(vm.getValueAsString("company"));

				ContactService.Instance.get().save(c, new AsyncCallback<Void>() {
					@Override
					public void onFailure(Throwable caught) {
						SC.warn(caught.getMessage());
					}

					@Override
					public void onSuccess(Void ret) {
						ContactDetails.this.destroy();
						if (parent != null)
							parent.refresh();
					}
				});
			}
		}
	});

	form.setFields(email, firstName, lastName, company, address, phone, cell, save);

	addItem(form);
}
 
Example 5
Source File: ChangePassword.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ChangePassword() {
	super();

	GUIUser user = Session.get().getUser();

	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(I18N.message("changepassword"));
	setWidth(300);
	setIsModal(true);
	setShowModalMask(true);
	centerInPage();
	setAutoSize(true);

	final ValuesManager vm = new ValuesManager();
	final DynamicForm form = new DynamicForm();
	form.setValuesManager(vm);
	form.setWidth(350);
	form.setMargin(5);

	PasswordItem password = new PasswordItem();
	password.setName(PASSWORD);
	password.setTitle(I18N.message(PASSWORD));
	password.setRequired(true);

	MatchesFieldValidator equalsValidator = new MatchesFieldValidator();
	equalsValidator.setOtherField(NEWPASSWORDAGAIN);
	equalsValidator.setErrorMessage(I18N.message("passwordnotmatch"));

	LengthRangeValidator sizeValidator = new LengthRangeValidator();
	sizeValidator
			.setErrorMessage(I18N.message("errorfieldminlenght", Integer.toString(user.getPasswordMinLenght())));
	sizeValidator.setMin(user.getPasswordMinLenght());

	PasswordItem newPass = new PasswordItem();
	newPass.setName(NEWPASSWORD);
	newPass.setTitle(I18N.message(NEWPASSWORD));
	newPass.setRequired(true);
	newPass.setValidators(equalsValidator, sizeValidator);

	PasswordItem newPassAgain = new PasswordItem();
	newPassAgain.setName(NEWPASSWORDAGAIN);
	newPassAgain.setTitle(I18N.message(NEWPASSWORDAGAIN));
	newPassAgain.setWrapTitle(false);
	newPassAgain.setRequired(true);

	final ButtonItem apply = new ButtonItem();
	apply.setTitle(I18N.message("apply"));
	apply.setAutoFit(true);
	apply.addClickHandler(new ClickHandler() {
		public void onClick(ClickEvent event) {
			vm.validate();
			if (!vm.hasErrors()) {
				if (vm.getValueAsString(PASSWORD).equals(vm.getValueAsString(NEWPASSWORD))) {
					Map<String, String> errors = new HashMap<String, String>();
					errors.put(NEWPASSWORD, I18N.message("useanotherpassword"));
					vm.setErrors(errors, true);
					return;
				}

				apply.setDisabled(true);

				SecurityService.Instance.get().changePassword(user.getId(), user.getId(),
						vm.getValueAsString(PASSWORD), vm.getValueAsString(NEWPASSWORD), false,
						new AsyncCallback<Integer>() {

							@Override
							public void onFailure(Throwable caught) {
								apply.setDisabled(false);
								SC.warn(caught.getMessage());
							}

							@Override
							public void onSuccess(Integer ret) {
								apply.setDisabled(false);
								if (ret.intValue() > 0) {
									// Alert the user and maintain the popup
									// opened
									if (ret == 1)
										SC.warn(I18N.message("wrongpassword"));
									else if (ret == 2)
										SC.warn(I18N.message("passwdnotnotified"));
									else
										SC.warn(I18N.message("genericerror"));
								} else {
									SC.say(I18N.message("yourpasswordhaschanged"));
									Log.info(I18N.message("event.user.passwordchanged"), null);
								}

								// Close the popup
								ChangePassword.this.destroy();
							}
						});
			}
		}
	});

	form.setFields(password, newPass, newPassAgain, apply);

	addItem(form);
}
 
Example 6
Source File: Registration.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Registration(String[] reg) {
	super();

	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(I18N.message("registration"));
	setWidth(350);
	setHeight(150);
	setIsModal(true);
	setShowModalMask(true);
	centerInPage();
	setAutoSize(true);

	final DynamicForm form = new DynamicForm();
	form.setValuesManager(vm);
	form.setMargin(5);
	form.setNumCols(2);
	form.setTitleOrientation(TitleOrientation.TOP);

	TextItem regName = ItemFactory.newTextItem("reg_name", "name", null);
	regName.setWrapTitle(false);
	regName.setValue(reg[0]);

	TextItem regEmail = ItemFactory.newEmailItem("reg_email", "email", false);
	regEmail.setWrapTitle(false);
	regEmail.setValue(reg[1]);

	TextItem regOrganization = ItemFactory.newTextItem("reg_organization", "organization", null);
	regOrganization.setWrapTitle(false);
	regOrganization.setValue(reg[2]);

	TextItem regWebsite = ItemFactory.newTextItem("reg_website", "website", null);
	regWebsite.setWidth(180);
	regWebsite.setWrapTitle(false);
	regWebsite.setValue(reg[3]);

	ButtonItem apply = new ButtonItem();
	apply.setTitle(I18N.message("apply"));
	apply.setAutoFit(true);
	apply.addClickHandler(new ClickHandler() {
		public void onClick(ClickEvent event) {
			vm.validate();
			if (!vm.hasErrors()) {
				SettingService.Instance.get().saveRegistration(form.getValueAsString("reg_name"),
						form.getValueAsString("reg_email"), form.getValueAsString("reg_organization"),
						form.getValueAsString("reg_website"), new AsyncCallback<Void>() {
							@Override
							public void onFailure(Throwable caught) {
								SC.warn(caught.getMessage());
							}

							@Override
							public void onSuccess(Void ret) {
								afterSave();
								Registration.this.destroy();
							}
						});
			}
		}
	});

	form.setFields(regName, regEmail, regOrganization, regWebsite, apply);

	addItem(form);
}
 
Example 7
Source File: TaskNotificationPanel.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onDraw() {
	VLayout notificationsPane = new VLayout();
	setMembers(notificationsPane);

	final DynamicForm notificationsForm = new DynamicForm();
	notificationsForm.setColWidths(1, "*");
	notificationsForm.setMargin(3);

	List<FormItem> items = new ArrayList<FormItem>();

	// Enable/Disable notifications
	CheckboxItem sendReport = new CheckboxItem();
	sendReport.setName("sendReport");
	sendReport.setTitle(I18N.message("sendactivityreport"));
	sendReport.setRedrawOnChange(true);
	sendReport.setWidth(50);
	sendReport.setValue(task.isSendActivityReport());
	sendReport.addChangedHandler(new ChangedHandler() {

		@Override
		public void onChanged(ChangedEvent event) {
			task.setSendActivityReport("true".equals(notificationsForm.getValue("sendReport").toString()));

			// Notify the external handler
			changedHandler.onChanged(event);
		}
	});

	items.add(sendReport);

	Long[] ids = new Long[task.getReportRecipients().length];
	for (int i = 0; i < ids.length; i++)
		ids[i] = task.getReportRecipients()[i].getId();

	recipients = ItemFactory.newMultiComboBoxItem("recipients", "recipients", new UsersDS(null, false), ids);
	recipients.setValueField("id");
	recipients.setDisplayField("username");
	recipients.addChangedHandler(changedHandler);
	items.add(recipients);

	notificationsForm.setItems(items.toArray(new FormItem[0]));
	notificationsPane.setMembers(notificationsForm);
}
 
Example 8
Source File: ResetPassword.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ResetPassword(String product) {
	this.productName = product;
	setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
	setTitle(I18N.message("passwordreset"));
	setWidth(340);
	setCanDragResize(true);
	setIsModal(true);
	setShowModalMask(true);
	centerInPage();
	setPadding(5);
	setAutoSize(true);
	setMargin(5);

	DynamicForm form = new DynamicForm();
	form.setMargin(5);
	form.setValuesManager(vm);
	TextItem username = ItemFactory.newTextItem("username", "username", "");
	username.setRequired(true);
	TextItem email = ItemFactory.newEmailItem("email", "email", false);
	email.setRequired(true);
	form.setFields(username, email);
	addItem(form);

	Label pwdResetMsg = new Label(I18N.message("passwordresetmessage"));
	pwdResetMsg.setWidth100();
	pwdResetMsg.setMargin(5);
	addItem(pwdResetMsg);

	final DynamicForm buttonForm = new DynamicForm();
	buttonForm.setMargin(5);
	ButtonItem resetButton = new ButtonItem("reset", I18N.message("reset"));
	resetButton.setAutoFit(true);
	resetButton.addClickHandler(new ClickHandler() {
		@SuppressWarnings("unchecked")
		public void onClick(ClickEvent event) {
			Map<String, Object> values = (Map<String, Object>) vm.getValues();

			if (vm.validate()) {
				final String userName = (String) values.get("username");
				final String emailAddress = (String) values.get("email");
				buttonForm.setDisabled(true);
				loginService.resetPassword(userName, emailAddress, productName, new AsyncCallback<Void>() {

					@Override
					public void onFailure(Throwable caught) {
						Log.serverError(caught);
						buttonForm.setDisabled(false);
					}

					@Override
					public void onSuccess(Void result) {
						buttonForm.setDisabled(false);
						SC.say(I18N.message("amessagewassentto", emailAddress));
						destroy();
					}
				});
			}
		}
	});
	buttonForm.setItems(resetButton);
	addItem(buttonForm);
}