blob: 879b8af242f070b6f7c10ab585fd0e80915b6221 [file] [log] [blame]
/**
* Copyright (c) 2011, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.vaaclipse.addons.perspective.dialog;
import java.util.Locale;
import org.eclipse.osbp.runtime.common.i18n.II18nService;
import org.eclipse.osbp.runtime.web.vaadin.common.resource.IResourceProvider;
import org.eclipse.osbp.runtime.web.vaadin.components.dialogs.AbstractInputDialog;
import org.eclipse.osbp.runtime.web.vaadin.components.dialogs.IDialogI18nKeys;
import com.vaadin.data.util.BeanItem;
import com.vaadin.server.Resource;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
/**
* The Class SavePerspectiveDialog.
*/
public class SavePerspectiveDialog extends AbstractInputDialog {
/** The Constant DIALOG_TITLE. */
public static final String DIALOG_TITLE = "org.eclipse.osbp.dialogs.saveperspective.title";
/** The Constant DIALOG_MESSAGE. */
public static final String DIALOG_MESSAGE = "org.eclipse.osbp.dialogs.saveperspective.message";
/** The Constant DIALOG_ICON. */
public static final String DIALOG_ICON = "org.eclipse.osbp.dialogs.saveperspective.image";
/** The Constant DIALOG_DESCRIPTION. */
public static final String DIALOG_DESCRIPTION = "org.eclipse.osbp.dialogs.saveperspective.description";
/** The Constant DIALOG_OPTION__ACCEPT_CAPTION. */
public static final String DIALOG_OPTION__ACCEPT_CAPTION = "org.eclipse.osbp.dialogs.options.saveperspective";
/** The Constant DIALOG_OPTION__ACCEPT_DESCRIPTION. */
public static final String DIALOG_OPTION__ACCEPT_DESCRIPTION = "org.eclipse.osbp.dialogs.options.saveperspective.description";
/** The Constant NAME_FIELD. */
public static final String NAME_FIELD = "org.eclipse.osbp.dialogs.saveperspective.nameField";
/** The Constant SYSTEM_USER_FIELD. */
public static final String SYSTEM_USER_FIELD = "org.eclipse.osbp.dialogs.saveperspective.systemUserField";
/** The i18n service. */
private II18nService i18nService;
/** The name. */
private TextField name;
/** The system user. */
private CheckBox systemUser;
/** The data. */
private Data data;
/** The item. */
private BeanItem<Data> item;
/** The system user capability. */
private boolean systemUserCapability;
/**
* Instantiates a new save perspective dialog.
*
* @param config
* the config
* @param data
* the data
* @param options
* the options
*/
protected SavePerspectiveDialog(DialogConfig config, Data data,
Option... options) {
super(config, options);
this.data = data;
}
/* (non-Javadoc)
* @see org.eclipse.osbp.runtime.web.vaadin.components.dialogs.AbstractInputDialog#fillForm(com.vaadin.ui.FormLayout)
*/
@Override
protected void fillForm(FormLayout customArea) {
Locale locale = UI.getCurrent().getLocale();
name = new TextField(i18nService.getValue(NAME_FIELD, locale));
name.setNullRepresentation("");
systemUser = new CheckBox(i18nService.getValue(SYSTEM_USER_FIELD,
locale));
systemUser.setVisible(systemUserCapability);
customArea.addComponent(name);
customArea.addComponent(systemUser);
item = new BeanItem<Data>(data);
name.setPropertyDataSource(item.getItemProperty("name"));
systemUser.setPropertyDataSource(item.getItemProperty("systemUser"));
name.focus();
}
/**
* Show dialog.
*
* @param service
* the service
* @param systemUserCapability
* the system user capability
* @param resourceProvider
* the resource provider
* @param onAccept
* the on accept
* @param data
* the data
*/
public static void showDialog(II18nService service,
boolean systemUserCapability, IResourceProvider resourceProvider,
Runnable onAccept, Data data) {
if (service == null) {
throw new NullPointerException("Please pass an i18nService");
}
Locale locale = UI.getCurrent().getLocale();
String dialogTitle = service.getValue(DIALOG_TITLE, locale);
String dialogMessage = service.getValue(DIALOG_MESSAGE, locale);
String dialogDescription = service.getValue(DIALOG_DESCRIPTION, locale);
String dialogIcon = service.getValue(DIALOG_ICON, locale);
String optionAcceptCaption = service.getValue(
DIALOG_OPTION__ACCEPT_CAPTION, locale);
String optionAcceptDescription = service.getValue(
DIALOG_OPTION__ACCEPT_DESCRIPTION, locale);
String optionCancelCaption = service.getValue(
IDialogI18nKeys.DIALOG_OPTION__CANCEL_CAPTION, locale);
String optionCancelDescription = service.getValue(
IDialogI18nKeys.DIALOG_OPTION__CANCEL_DESCRIPTION, locale);
String optionCancelIcon = service.getValue(
IDialogI18nKeys.DIALOG_OPTION__CANCEL_ICON, locale);
DialogConfig config = new DialogConfig(dialogTitle, dialogMessage,
dialogDescription, createResource(dialogIcon, resourceProvider)) {
@Override
public void config(Window window) {
super.config(window);
window.setHeight("220px");
window.setWidth("350px");
window.center();
}
};
SavePerspectiveDialog dialog = new SavePerspectiveDialog(config, data,
new Option(optionCancelCaption, optionCancelDescription,
createResource(optionCancelIcon, resourceProvider),
null), new Option(optionAcceptCaption,
optionAcceptDescription, null, onAccept));
dialog.i18nService = service;
dialog.systemUserCapability = systemUserCapability;
dialog.open();
}
/**
* The Class Data.
*/
public static class Data {
/** The name. */
private String name;
/** The system user. */
private boolean systemUser;
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Checks if is system user.
*
* @return the systemUser
*/
public boolean isSystemUser() {
return systemUser;
}
/**
* Sets the system user.
*
* @param systemUser
* the systemUser to set
*/
public void setSystemUser(boolean systemUser) {
this.systemUser = systemUser;
}
}
/**
* The Class AcceptOption.
*/
public static class AcceptOption extends Option {
/**
* Instantiates a new accept option.
*
* @param name
* the name
* @param description
* the description
* @param icon
* the icon
* @param runnable
* the runnable
*/
public AcceptOption(String name, String description, Resource icon,
Runnable runnable) {
super(name, description, icon, runnable);
}
}
}