org.locationtech.udig.project.ui.internal.handlers.LayerPropertiesCommandHandler.java Source code

Java tutorial

Introduction

Here is the source code for org.locationtech.udig.project.ui.internal.handlers.LayerPropertiesCommandHandler.java

Source

/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net
 * (C) 2004, Refractions Research Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD
 * License v1.0 (http://udig.refractions.net/files/bsd3-v10.html).
 */
package org.locationtech.udig.project.ui.internal.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PropertyDialogAction;
import org.eclipse.ui.handlers.HandlerUtil;

/**
 * A command hander for the LayerProperties command.
 * 
 * @author jesse
 * @since 1.1.0
 */
public class LayerPropertiesCommandHandler extends AbstractHandler implements IHandler {

    public Object execute(final ExecutionEvent event) throws ExecutionException {

        final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);

        IShellProvider shellProvider = new IShellProvider() {

            public Shell getShell() {
                return new Shell(activeWorkbenchWindow.getShell());
            }

        };

        IWorkbenchPart activePart = activeWorkbenchWindow.getActivePage().getActivePart();
        ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
        PropertyDialogAction action = new org.eclipse.ui.dialogs.PropertyDialogAction(shellProvider,
                selectionProvider);
        PreferenceDialog dialog = action.createDialog();
        dialog.open();

        return null;
    }

}