org.eclipse.osee.framework.ui.plugin.util.ModelessDialog.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.osee.framework.ui.plugin.util.ModelessDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.plugin.util;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;

public class ModelessDialog extends MessageDialog {
    private final List<IShellCloseEvent> closeEventListeners = new ArrayList<IShellCloseEvent>();

    public ModelessDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
            int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
        super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels,
                defaultIndex);
    }

    /**
     * Calling will enable dialog to loose focus
     */
    public void setModeless() {
        setShellStyle(SWT.DIALOG_TRIM | SWT.MODELESS);
        setBlockOnOpen(false);
    }

    public void setSelectionListener(SelectionListener listener) {
        for (int i = 0; i < getButtonLabels().length; i++) {
            Button button = getButton(i);
            button.addSelectionListener(listener);
        }
    }

    @Override
    protected void handleShellCloseEvent() {
        super.handleShellCloseEvent();
        for (IShellCloseEvent event : closeEventListeners) {
            event.onClose();
        }
    }

    public void addShellCloseEventListeners(IShellCloseEvent event) {
        closeEventListeners.add(event);
    }

}