/*******************************************************************************
 * Copyright (c) 2017 Red Hat, Inc and others.
 * 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:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.reddeer.eclipse.wst.server.ui.wizard;

import static org.eclipse.reddeer.common.wait.WaitProvider.waitUntil;

import org.hamcrest.core.StringContains;
import org.eclipse.reddeer.common.wait.GroupWait;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.core.condition.NamedThreadHasStatus;
import org.eclipse.reddeer.core.handler.WidgetHandler;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.jface.wizard.WizardDialog;
import org.eclipse.reddeer.jface.wizard.WizardPage;
import org.eclipse.reddeer.swt.condition.TreeContainsItem;
import org.eclipse.reddeer.swt.condition.ControlIsEnabled;
import org.eclipse.reddeer.swt.impl.button.NextButton;
import org.eclipse.reddeer.swt.impl.text.LabeledText;
import org.eclipse.reddeer.swt.impl.tree.DefaultTree;
import org.eclipse.reddeer.swt.impl.tree.DefaultTreeItem;

/**
 * Represents the first page displayed when invoked
 * {@link NewServerWizard}
 * 
 * @author Lucia Jelinkova
 *
 */
public class NewServerWizardPage extends WizardPage {
	
	public NewServerWizardPage(ReferencedComposite referencedComposite) {
		super(referencedComposite);
	}

	/**
	 * Select type.
	 *
	 * @param type
	 *            the type
	 */
	public void selectType(String... type) {
		new GroupWait(waitUntil(new NamedThreadHasStatus(new StringContains("Initializing Servers view"), Thread.State.TERMINATED, true)),
				waitUntil(new TreeContainsItem(new DefaultTree(referencedComposite), type)));
		new DefaultTreeItem(new DefaultTree(referencedComposite), type).select();
		new WaitUntil(new ControlIsEnabled(new NextButton(referencedComposite)));
	}

	/**
	 * Sets the name.
	 *
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		log.info("Set server name to "+name);
		log.info("parent is "+referencedComposite.getClass());
		log.info("null? "+(referencedComposite.getControl() == null));
		if(referencedComposite.getControl() != null){
			log.info("disposed? "+WidgetHandler.getInstance().isDisposed(referencedComposite.getControl()));
			log.info("class "+referencedComposite.getControl().getClass());
		}
		new LabeledText(referencedComposite, "Server name:").setText(name);
	}

	/**
	 * Sets the host name.
	 *
	 * @param name
	 *            the new host name
	 */
	public void setHostName(String name) {
		new LabeledText(referencedComposite, "Server's host name:").setText(name);
	}
}

@@ -893,146 +893,37 @@
 ore.
-handler.WidgetHandler;%0Aimport org.eclipse.reddeer.core.reference.ReferencedComposite;%0Aimport org.eclipse.reddeer.jface.wizard.WizardDialog
+reference.ReferencedComposite
 ;%0Aim
@@ -2195,389 +2195,8 @@
 ) %7B%0A
-%09%09log.info(%22Set server name to %22+name);%0A%09%09log.info(%22parent is %22+referencedComposite.getClass());%0A%09%09log.info(%22null? %22+(referencedComposite.getControl() == null));%0A%09%09if(referencedComposite.getControl() != null)%7B%0A%09%09%09log.info(%22disposed? %22+WidgetHandler.getInstance().isDisposed(referencedComposite.getControl()));%0A%09%09%09log.info(%22class %22+referencedComposite.getControl().getClass());%0A%09%09%7D%0A
 %09%09ne

Remove redundant server page log