com.clustercontrol.maintenance.dialog.HinemosPropertyTypeDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.maintenance.dialog.HinemosPropertyTypeDialog.java

Source

/*
    
Copyright (C) 2006 NTT DATA Corporation
    
 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, 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.
    
 */

package com.clustercontrol.maintenance.dialog;

import java.util.Map;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.clustercontrol.bean.PropertyDefineConstant;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.dialog.ValidateResult;
import com.clustercontrol.maintenance.HinemosPropertyTypeMessage;
import com.clustercontrol.maintenance.composite.HinemosPropertyTypeListComposite;
import com.clustercontrol.maintenance.view.HinemosPropertyView;
import com.clustercontrol.util.Messages;
import com.clustercontrol.util.WidgetTestUtil;

/**
 * ?<BR>
 *
 * @version 5.0.0
 * @since 5.0.0
 */
public class HinemosPropertyTypeDialog extends CommonDialog {

    // ----- instance  ----- //
    // ?pack???sizeX??
    private static final int sizeX = 300;
    private static final int sizeY = 300;

    // ?
    private HinemosPropertyTypeListComposite listComposite = null;

    // (listComposite?)
    private ListViewer HinemosPropertyTypeList = null;

    // ??
    private HinemosPropertyView view = null;

    /** ??? */
    private String managerName = null;

    // -----  ----- //

    /**
     * ????
     *
     * @param parent ??
     */
    public HinemosPropertyTypeDialog(Shell parent, HinemosPropertyView view, String managerName) {
        super(parent);
        this.view = view;
        this.managerName = managerName;
    }

    // ----- instance  ----- //

    @Override
    protected Point getInitialSize() {
        return new Point(sizeX, sizeY);
    }

    /**
     * ???
     */
    @Override
    protected void customizeDialog(Composite parent) {
        Shell shell = this.getShell();

        // 
        parent.getShell().setText(Messages.getString("hinemos.property.type"));

        GridLayout layout = new GridLayout(5, true);
        parent.setLayout(layout);
        layout.marginHeight = 0;
        layout.marginWidth = 0;

        listComposite = new HinemosPropertyTypeListComposite(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, listComposite);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 5;
        listComposite.setLayoutData(gridData);

        HinemosPropertyTypeList = listComposite.getHinemosPropertyTypeList();

        HinemosPropertyTypeList.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                return element.toString();
            }
        });
        // ??
        for (Map.Entry<Integer, String> entry : HinemosPropertyTypeMessage.getList().entrySet()) {
            HinemosPropertyTypeList.add(entry.getValue());
        }

        // ?????????????
        HinemosPropertyTypeList.addDoubleClickListener(new IDoubleClickListener() {
            @Override
            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }
        });

        // ?pack:resize to be its preferred size
        shell.pack();
        shell.setSize(new Point(shell.getSize().x, shell.getSize().y));

        // ??
        Display display = shell.getDisplay();
        shell.setLocation((display.getBounds().width - shell.getSize().x) / 2,
                (display.getBounds().height - shell.getSize().y) / 2);
    }

    /**
     * ???(?)??
     *
     * @return
     */
    public String getSelectItem() {
        return this.listComposite.getSelectItem();
    }

    /**
     * OK ?
     */
    @Override
    protected String getOkButtonText() {
        return Messages.getString("next");
    }

    /**
     * OK <BR>
     * ???????
     */
    @Override
    protected void okPressed() {
        // ??null?
        if (this.getSelectItem() == null) {
            ValidateResult result = null;
            result = new ValidateResult();
            result.setValid(false);
            result.setID(Messages.getString("message.hinemos.1"));
            result.setMessage(Messages.getString("message.hinemos.property.1"));
            displayError(result);

            return;
        }

        // ?????
        int valueType = HinemosPropertyTypeMessage.stringToType(this.getSelectItem());
        // ??
        HinemosPropertyDialog dialog = new HinemosPropertyDialog(getParentShell(), managerName, valueType,
                PropertyDefineConstant.MODE_ADD, null);

        dialog.open();

        // ??????
        // super.okPressed();

        // ?
        this.view.update();
    }

    @Override
    protected void cancelPressed() {
        super.cancelPressed();
    }

    /**
     * ?
     */
    @Override
    protected String getCancelButtonText() {
        return Messages.getString("cancel");
    }
}