Java tutorial
/* Copyright (C) 2007-2011 BlueXML - www.bluexml.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.bluexml.side.Portal.modeler.diagram.dialogs; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; 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.TabFolder; import org.eclipse.swt.widgets.TabItem; import com.bluexml.side.Portal.modeler.PortalPlugin; import com.bluexml.side.portal.isChildPage; public class IsChildPageEditDialog extends Dialog implements IDialogConstants { private isChildPage isChildPage; private Map data; private static final int MIN_DIALOG_WIDTH = 500; private static final int MIN_DIALOG_HEIGHT = 300; public static final String ISCHILDPAGE_Inherit = "isChildPage inherit"; private Button inherit; public IsChildPageEditDialog(isChildPage p_isChildPage, Shell p_parentShell) { super(p_parentShell); setBlockOnOpen(true); setShellStyle(getShellStyle() | SWT.RESIZE); isChildPage = p_isChildPage; } public Map getData() { return data; } protected Control createDialogArea(Composite parent) { Composite dialogComposite = (Composite) super.createDialogArea(parent); GridData dialogLayoutData = new GridData(GridData.FILL_BOTH); dialogLayoutData.widthHint = MIN_DIALOG_WIDTH; dialogLayoutData.heightHint = MIN_DIALOG_HEIGHT; dialogComposite.setLayoutData(dialogLayoutData); createIsChildPageGroup(dialogComposite); loadData(); return dialogComposite; } protected void createIsChildPageGroup(Composite parent) { TabFolder tabFolder = new TabFolder(parent, SWT.TOP); tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH)); createGeneralTab(tabFolder); } private void createGeneralTab(Composite parent) { // Create tab item and add it composite that fills it TabItem generalItem = new TabItem((TabFolder) parent, SWT.NONE); generalItem.setText("General"); Composite composite = new Composite(parent, SWT.NONE); generalItem.setControl(composite); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); Label propertyIdLbl = new Label(composite, SWT.NONE); propertyIdLbl.setText("Inherit : "); inherit = new Button(composite, SWT.CHECK); inherit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } /** * Initialize the content of the widgets */ private void loadData() { inherit.setSelection(isChildPage.isInherit()); } /** * Save the values before the widgets are disposed * * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { data = new HashMap(); try { data.put(ISCHILDPAGE_Inherit, inherit.getSelection()); super.okPressed(); } catch (Exception e) { // TODO change this with a validation listener that disable the ok // button until the widgets are valid PortalPlugin.log("Required fields", IStatus.WARNING); MessageDialog.openWarning(getShell(), "Required parameters", "Some parameters are not set.\nPlease, fill those fields before validating."); } } }