Skip to main content
summaryrefslogtreecommitdiffstats
blob: ba87f03ae5f163068cc438efdc8daea2032c1dc1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2001, 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.wst.wsdl.tests.ui;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.tests.util.DefinitionLoader;
import org.eclipse.wst.wsdl.tests.util.WSDLConverter;



public class ConvertWSDL20ActionDelegate implements IActionDelegate
{
  private ISelection selection = null;

  public void run(IAction action)
  {
    IFile ifile = null;
    if (!selection.isEmpty() && selection instanceof IStructuredSelection)
    {
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
      Object element = structuredSelection.getFirstElement();

      if (element instanceof IFile)
      {
      	ifile = (IFile) element;
        IPath path = ifile.getLocation();
        IPath path2 = path.removeLastSegments(1);
        String output = path2.toString() + "/" + getNewName(ifile);
        
        try
		    {  
            Definition def = DefinitionLoader.load("file:/" + path.toString());
            WSDLConverter converter = new WSDLConverter(def);
            converter.generate20(output);
            IContainer folder = ifile.getParent();
            folder.refreshLocal(IResource.DEPTH_ONE,null);
		    }
        catch (Throwable e)
		    {
          e.printStackTrace();
		    }
      }
      else
        return;
    }
        
  }
  
  private String getNewName(IFile ifile)
  {
    // Assert currentName has a file extension, e.g. foo.wsdl.
    // This will return fooV20.wsdl.
    String currentName = ifile.getName();
    String name = currentName.substring(0,currentName.indexOf("."));
    String extension = currentName.substring(currentName.indexOf("."));
    String newName = name + "V20" + extension;
    return newName;
  }
  
  public void selectionChanged(IAction action, ISelection selection)
  {
    this.selection = selection;
  }

}

Back to the top