blob: ec04608e6193a16f191a614ca7ccaf6db768927f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.widgets;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jst.ws.internal.consumption.ui.widgets.object.ValidateWSDLJob;
import org.eclipse.wst.command.internal.provisional.env.core.SimpleCommand;
import org.eclipse.wst.command.internal.provisional.env.core.common.Choice;
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus;
import org.eclipse.wst.command.internal.provisional.env.core.common.Status;
import org.eclipse.wst.ws.internal.parser.discovery.WebServicesParserExt;
import org.eclipse.wst.ws.internal.parser.wsil.WebServicesParser;
import org.eclipse.wst.ws.internal.plugin.WSPlugin;
import org.eclipse.wst.ws.internal.ui.plugin.WSUIPlugin;
import org.eclipse.wst.ws.internal.ui.wsi.preferences.PersistentWSIContext;
public class CheckWSDLValidationCommand extends SimpleCommand
{
private String LABEL = "TASK_LABEL_CHECK_WSDL_VALIDATION";
private String DESCRIPTION = "TASK_DESC_CHECK_WSDL_VALIDATION";
private static MessageUtils msgUtils_;
public CheckWSDLValidationCommand () {
String pluginId = "org.eclipse.jst.ws.consumption.ui";
msgUtils_ = new MessageUtils( pluginId + ".plugin", this );
setName (msgUtils_.getMessage(LABEL));
setDescription( msgUtils_.getMessage(DESCRIPTION));
}
public Status execute(Environment env)
{
IJobManager jobManager = Platform.getJobManager();
Job[] jobs = jobManager.find( ValidateWSDLJob.VALIDATE_WSDL_JOB_FAMILY );
ValidateWSDLJob existingValidateWSDLJob = null;
if( jobs.length > 0 )
{
for (int i=0; i<jobs.length; i++) {
existingValidateWSDLJob = (ValidateWSDLJob)jobs[i];
if (existingValidateWSDLJob.getState() != Job.NONE) {
if (ignoreWSDLValidation(env)) {
// if don't want to wait for validation, cancel existing validation job
existingValidateWSDLJob.cancel();
return new SimpleStatus("");
} else {
// wait for WSDL validation
return new SimpleStatus(
"CheckWSDLValidationCommand",
msgUtils_.getMessage("WAIT_FOR_WSDL"),
Status.ERROR);
}
}
}
}
return new SimpleStatus("");
}
private boolean ignoreWSDLValidation(Environment env) {
if (!WSPlugin.getInstance().getWaitForWSDLValidationContext().getPersistentWaitForWSDLValidation())
return true; // do not want to wait for WSDL validation, i.e. Ignore all
// give a warning message with the options to stop, ignore this one, or
// ignore all coming messages
SimpleStatus status_ = new SimpleStatus(WSUIPlugin.ID, msgUtils_
.getMessage("STILL_VALIDATING_WSDL"), Status.WARNING);
// adding all messages from WSI Incompliances
Choice ignoreChoice = new Choice('I', msgUtils_
.getMessage("IGNORE_LABEL"), msgUtils_
.getMessage("IGNORE_DESCRIPTION"));
Choice ignoreAllChoice = new Choice('A', msgUtils_
.getMessage("IGNORE_ALL_LABEL"), msgUtils_
.getMessage("IGNORE_ALL_DESCRIPTION"));
Choice cancelChoice = new Choice('C', msgUtils_
.getMessage("CANCEL_LABEL"), msgUtils_
.getMessage("CANCEL_DESCRIPTION"));
Choice result = env.getStatusHandler().report(status_,
new Choice[] { ignoreChoice, ignoreAllChoice, cancelChoice });
// if the user closes the message box or selects ignore continue
if (result == null
|| (result.getLabel().equals(ignoreChoice.getLabel()))) {
return true;
// if the user selects ignore all, change the preference
} else if (result.getLabel().equals(ignoreAllChoice.getLabel())) {
// update ignore WSDL validation preference
WSPlugin.getInstance().getWaitForWSDLValidationContext().setWaitForWSDLValidation(false);
return true;
}
// if the user selects to cancel , do not continue with the command
else if (result.getLabel().equals(cancelChoice.getLabel())) {
return false;
}
return true;
}
}