blob: 4658522b92d5d9f1797d0a822555935e00df388d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 SAP AG.
* 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:
* Georgi Konstantinov - initial API and implementation.
*******************************************************************************/
package org.eclipse.wst.sse.sieditor.search.provider.wsdl;
import java.util.Collection;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.platform.discovery.runtime.api.ISearchParameters;
import org.eclipse.wst.sse.sieditor.model.api.IWsdlModelRoot;
import org.eclipse.wst.sse.sieditor.model.wsdl.api.IServiceInterface;
import org.eclipse.wst.sse.sieditor.search.provider.AbstractSearchQueryOperation;
import org.eclipse.wst.sse.sieditor.search.provider.WildcardStringMatcher;
import org.eclipse.wst.sse.sieditor.search.ui.tree.FileNode;
import org.eclipse.wst.sse.sieditor.search.ui.tree.ITreeNodeWithCustomizableChildren;
import org.eclipse.wst.sse.sieditor.search.ui.tree.NamespaceNode;
import org.eclipse.wst.sse.sieditor.search.ui.tree.RootTreeNode;
import org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode;
import org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController;
import org.eclipse.wst.sse.sieditor.ui.v2.wsdltree.nodes.ServiceInterfaceNode;
public class WsdlSearchQueryOperation extends AbstractSearchQueryOperation {
public WsdlSearchQueryOperation(ISearchParameters searchParams) {
super(searchParams);
}
@Override
protected boolean isFileThatMayHaveTheSearchedContenet(IFile file) {
String fileExtension = file.getFileExtension();
if (isWsdlFileExtension(fileExtension) || isXmlFileExtension(fileExtension)) {
return true;
}
return false;
}
@Override
protected ITreeNode getRootTreeNode(Set<IFile> files) {
RootTreeNode rootTreeNode = new RootTreeNode();
final ResourceSetImpl resourceSet = new ResourceSetImpl();
for (IFile file : files) {
FileNode fileNode = new FileNode(file, rootTreeNode, false);
IWsdlModelRoot wsdlModelRoot = getWsdlModelRootForFile(file, resourceSet);
if (isByNamespaceHierarchy() || isByFilesHierarchy()) {
NamespaceNode namespaceNode = new NamespaceNode(wsdlModelRoot.getDescription(), fileNode);
addInterfacesToNamespaceNode(wsdlModelRoot, namespaceNode);
chooseParentForNamespaceNode(rootTreeNode, fileNode, namespaceNode);
} else {
addInterfacesToNamespaceNode(wsdlModelRoot, rootTreeNode);
}
if (fileNode.hasChildren() && isByFilesHierarchy()) {
rootTreeNode.addChild(fileNode);
}
}
return rootTreeNode;
}
private void addInterfacesToNamespaceNode(IWsdlModelRoot wsdlModelRoot, ITreeNodeWithCustomizableChildren parent) {
Collection<IServiceInterface> allInterfaces = wsdlModelRoot.getDescription().getAllInterfaces();
for (IServiceInterface serviceInterface : allInterfaces) {
if (!WildcardStringMatcher.matches(searchParams.getKeywordString(), serviceInterface.getName())) {
continue;
}
parent.addChild(new ServiceInterfaceNode(parent, serviceInterface, new SIFormPageController(wsdlModelRoot, false,
false)));
}
}
}