com.bluexml.side.Class.modeler.diagram.dialogs.CommentEditDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.bluexml.side.Class.modeler.diagram.dialogs.CommentEditDialog.java

Source

/*
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/>.
    
*/

/*******************************************************************************
 *    Copyright (C) BlueXML 2005-2008
 *
 * 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 2.
 * 
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Boston, MA 02111.
 ******************************************************************************/
package com.bluexml.side.Class.modeler.diagram.dialogs;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
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.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

import com.bluexml.side.common.Comment;

public class CommentEditDialog extends Dialog implements IDialogConstants {

    /** The ID of the property name */
    public static final String COMMENT_BODY = "comment body";

    private static final int MIN_DIALOG_WIDTH = 400;

    private static final int MIN_DIALOG_HEIGHT = 300;

    /** Current edited property */
    private Comment comment;

    private Map data;

    // SWT Objects
    private Text commentBody;

    /**
     * Create the dialog for a given Attribute
     * 
     * @param prop
     *            the Attribute to edit
     * @param parentShell
     *            the parent shell
     */
    public CommentEditDialog(Comment comm, Shell parentShell) {
        super(parentShell);
        setBlockOnOpen(true);
        setShellStyle(getShellStyle() | SWT.RESIZE);
        comment = comm;
    }

    /**
     * Set the title of the new shell
     * 
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    protected void configureShell(Shell newShell) {
        newShell.setText("Comment");
        newShell.setMinimumSize(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT);

        super.configureShell(newShell);
    }

    /**
     * Create the Dialog area
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    protected Control createDialogArea(Composite parent) {
        // Dialog
        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);

        createCcommentGroup(dialogComposite);

        loadData();

        return dialogComposite;
    }

    /**
     * Creates the group
     * 
     * @param parent
     *            the parent Composite
     */
    private void createCcommentGroup(Composite parent) {
        TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
        tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));

        createBodyTab(tabFolder);
    }

    private void createBodyTab(TabFolder parent) {
        // Create tab item and add it composite that fills it
        TabItem viewItem = new TabItem((TabFolder) parent, SWT.NONE);
        viewItem.setText("Body comment");
        Composite composite = new Composite(parent, SWT.NONE);
        viewItem.setControl(composite);

        composite.setLayout(new GridLayout(2, false));
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));

        commentBody = new Text(composite, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
        commentBody.setLayoutData(new GridData(GridData.FILL_BOTH));
    }

    /**
     * Initialize the content of the widgets
     */
    private void loadData() {
        //Body comment
        if (comment.getValue() != null)
            commentBody.setText(comment.getValue());
    }

    /**
     * Save the values before the widgets are disposed
     * 
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
    protected void okPressed() {
        data = new HashMap();
        data.put(COMMENT_BODY, commentBody.getText());
        super.okPressed();
    }

    /**
     * Return a map containing Attribute data that may changed
     * 
     * @return a Map
     */
    public Map getData() {
        return data;
    }

}