/*
 * Perfclispe
 * 
 * 
 * Copyright (c) 2013 Jakub Knetl
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.perfclipse.ui.swt.events;

import java.util.List;

import org.eclipse.gef.commands.Command;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.events.SelectionEvent;
import org.perfclipse.ui.Utils;
import org.perfclipse.ui.wizards.AbstractPerfCakeEditWizard;

/**
 * @author Jakub Knetl
 *
 */
public abstract class AbstractEditCommandSelectionAdapter extends
		AbstractCommandSelectionAdapter {

	private AbstractPerfCakeEditWizard wizard;
	
	/**
	 * @param commands
	 * @param viewer
	 */
	public AbstractEditCommandSelectionAdapter(List<Command> commands,
			TableViewer viewer) {
		super(commands, viewer);
	}


	
	@Override
	public void widgetSelected(SelectionEvent e) {
		if (! (getViewer().getSelection() instanceof IStructuredSelection))
			return;
		
		IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();

		wizard = createWizard(selection);
		if (Utils.showWizardDialog(wizard) != Window.OK)
			return;
		
		
		super.widgetSelected(e);
		getViewer().refresh();
	}

	/**
	 * Returns wizard to show for editing.
	 * @param selection
	 * @return Returns wizard to show for editing.
	 */
	protected abstract AbstractPerfCakeEditWizard createWizard(IStructuredSelection selection);



	@Override
	protected Command getCommand() {
		if (wizard.getCommand().isEmpty())
			return null;
		return wizard.getCommand();
	}

}

@@ -1358,16 +1358,234 @@
 %0A%09%7D%0A%0A%0A%09%0A
+%09/**%0A%09 * this method checks if some element is selected if it is, then it calls%0A%09 * createWizard(element) and shows this wizard. If wizard is closed properly%0A%09 * then it creates command and call refresh on viewer%0A%09 */%0A
 %09@Overri
@@ -1806,16 +1806,71 @@
 ion();%0A%0A
+%09%09if (selection.getFirstElement() == null)%0A%09%09%09return;%0A%0A
 %09%09wizard

Fix check if selection is not empty