com.nextep.designer.vcs.ui.handlers.VersionCompareHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.nextep.designer.vcs.ui.handlers.VersionCompareHandler.java

Source

/*******************************************************************************
 * Copyright (c) 2011 neXtep Software and contributors.
 * All rights reserved.
 *
 * This file is part of neXtep designer.
 *
 * NeXtep designer 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, either 
 * version 3 of the License, or any later version.
 *
 * NeXtep designer 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     neXtep Softwares - initial API and implementation
 *******************************************************************************/
package com.nextep.designer.vcs.ui.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import com.nextep.datadesigner.vcs.services.VersionHelper;
import com.nextep.designer.vcs.model.IVersionInfo;
import com.nextep.designer.vcs.ui.VCSUIPlugin;

public class VersionCompareHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        ISelection s = HandlerUtil.getCurrentSelection(event);
        if (s == null || s.isEmpty()) {
            return null;
        }
        if (s instanceof IStructuredSelection) {
            IStructuredSelection sel = (IStructuredSelection) s;
            IVersionInfo mainVersion = null;
            IVersionInfo otherVersion = null;
            // Retrieving selected versions from selection
            for (Object o : sel.toArray()) {
                if (mainVersion == null) {
                    mainVersion = VersionHelper.getVersionInfo(o);
                } else {
                    otherVersion = VersionHelper.getVersionInfo(o);
                }
            }
            // Have we got anything selected? If so we compare
            if (mainVersion != null) {
                final IVersionInfo sourceVersion = otherVersion == null ? mainVersion.getPreviousVersion()
                        : otherVersion;
                VCSUIPlugin.getComparisonUIManager().compare(mainVersion.getReference(), mainVersion,
                        sourceVersion);
            }
        }

        return null;
    }
}