|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.cocoa; |
| 12 |
|
| 13 |
import org.eclipse.core.commands.AbstractHandler; |
| 14 |
import org.eclipse.core.commands.ExecutionEvent; |
| 15 |
import org.eclipse.core.commands.ExecutionException; |
| 16 |
import org.eclipse.core.commands.IHandler; |
| 17 |
import org.eclipse.jface.dialogs.Dialog; |
| 18 |
import org.eclipse.jface.window.Window; |
| 19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.widgets.Display; |
| 21 |
import org.eclipse.swt.widgets.Shell; |
| 22 |
|
| 23 |
/** |
| 24 |
* |
| 25 |
* @author Prakash G.R. (grprakash@gmail.com) |
| 26 |
* @since 3.6 |
| 27 |
* |
| 28 |
*/ |
| 29 |
public class CloseDialogHandler extends AbstractHandler implements IHandler { |
| 30 |
|
| 31 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
| 32 |
|
| 33 |
Shell activeShell = Display.getDefault().getActiveShell(); |
| 34 |
if((activeShell.getStyle() & SWT.CLOSE) == 0) { |
| 35 |
// if close not enabled, do nothing |
| 36 |
return null; |
| 37 |
} |
| 38 |
|
| 39 |
Object data = activeShell.getData(); |
| 40 |
if(data instanceof Dialog) { |
| 41 |
Dialog dialog = (Dialog) data; |
| 42 |
dialog.setReturnCode(Window.CANCEL); |
| 43 |
dialog.close(); |
| 44 |
} |
| 45 |
|
| 46 |
return null; |
| 47 |
} |
| 48 |
|
| 49 |
} |