/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.dialogs;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import de.innovationgate.eclipse.editors.models.WGAPortletModesModel;
import de.innovationgate.eclipse.utils.ui.ValidatedDialog;
public class AddPortletModeDialog extends ValidatedDialog {
private Text _text;
private String _mode;
private WGAPortletModesModel _model;
public AddPortletModeDialog(Shell parent, WGAPortletModesModel model) {
super(parent);
setHelpAvailable(false);
_model = model;
}
public void computeResponse() {
_mode = _text.getText();
}
protected Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.None);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
new Label(composite, SWT.NONE).setText("Mode name:");
_text = new Text(composite, SWT.BORDER);
GridData txtStyle = new GridData(GridData.FILL_HORIZONTAL);
_text.setLayoutData(txtStyle);
_text.addModifyListener(this);
return composite;
}
@Override
public List<String> validate() {
List<String> messages = new ArrayList<String>();
if (_text.getText().equals("")) {
messages.add("Please type a Modename.");
} else {
if (_model.getBeans().contains(_text.getText())) {
messages.add("Mode \"" + _text.getText() + "\" already exists.");
}
}
return messages;
}
public String getMode() {
return _mode;
}
}