com.clustercontrol.notify.dialog.NotifyTypeDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.notify.dialog.NotifyTypeDialog.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.notify.dialog;

import org.eclipse.jface.dialogs.IDialogConstants;
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.Shell;

import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.dialog.CommonDialog;
import com.clustercontrol.dialog.ValidateResult;
import com.clustercontrol.notify.bean.NotifyTypeConstant;
import com.clustercontrol.notify.composite.NotifyTypeListComposite;
import com.clustercontrol.notify.util.NotifyTypeUtil;
import com.clustercontrol.notify.view.action.NotifyModifyAction;
import com.clustercontrol.util.Messages;

/**
 * ????<BR>
 *
 * @version 3.0.0
 * @since 3.0.0
 */
public class NotifyTypeDialog extends CommonDialog {

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

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

    /** ??? */
    private NotifyTypeListComposite listComposite = null;
    private ListViewer notifyTypeList = null;

    private String managerName = null;

    Composite composite = null;

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

    /**
     * ????
     *
     * @param parent
     *            ??
     */
    public NotifyTypeDialog(Shell parent, Composite composite, String managerName) {
        super(parent);
        this.composite = composite;
        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("notify.type.list"));

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

        listComposite = new NotifyTypeListComposite(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);

        notifyTypeList = listComposite.getNotifyTypeList();

        notifyTypeList.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                Integer notifyType = (Integer) element;
                return NotifyTypeUtil.typeToString(notifyType);
            }
        });

        // ??
        for (Integer type : NotifyTypeConstant.getList()) {
            notifyTypeList.add(type);
        }

        // ?????????????
        notifyTypeList.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));
    }

    public Integer getSelectItem() {
        return this.listComposite.getSelectItem();
    }

    /**
     * Show create dialog and do not close after OK pressed
     */
    @Override
    protected void okPressed() {
        ValidateResult result = null;

        // ??null?
        if (this.getSelectItem() == null) {
            result = new ValidateResult();
            result.setValid(false);
            result.setID(Messages.getString("message.hinemos.1"));
            result.setMessage(Messages.getString("message.notify.28"));
            displayError(result);
        }

        // DB?????????
        Integer notifyType = this.getSelectItem();
        NotifyModifyAction action = new NotifyModifyAction();
        if (action.openDialog(getParentShell(), this.managerName, null, notifyType) == IDialogConstants.OK_ID) {
            composite.update();
        }
    }

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

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