Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6306fbb70859631c627213b6fca3350c25e251cf (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20070116   159618 makandre@ca.ibm.com - Andrew Mak, Project and EAR not defaulted properly when wizard launched from JSR-109 Web services branch in J2EE Project Explorer
 *******************************************************************************/

package org.eclipse.jst.ws.internal.consumption.ui.widgets.object;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jst.j2ee.ejb.EnterpriseBean;
import org.eclipse.jst.j2ee.webservice.wsdd.EJBLink;
import org.eclipse.jst.j2ee.webservice.wsdd.PortComponent;
import org.eclipse.jst.j2ee.webservice.wsdd.ServiceImplBean;
import org.eclipse.wst.command.internal.env.core.data.Transformer;

public class EJBSelectionTransformer implements Transformer
{

  public Object transform(Object value)
  {
    if (value instanceof IStructuredSelection)
    {
      Object sel = ((IStructuredSelection)value).getFirstElement();
      if (sel instanceof EnterpriseBean)
      {
        return new StructuredSelection(((EnterpriseBean)sel).getName());
      }
      else if (sel instanceof ServiceImplBean)
      {
        return new StructuredSelection(getBeanName((ServiceImplBean) sel));
      }
      else if (sel instanceof EJBLink)
      {
        return new StructuredSelection(getBeanName((EJBLink) sel));
      }
    }
    return value;
  }
  
  private String getBeanName(ServiceImplBean bean) {
	  EObject eObject = bean.eContainer();
	  if (eObject instanceof PortComponent) {
		  PortComponent pc = (PortComponent) eObject;
		  return pc.getPortComponentName();	      	
	  }
	  return "";
  }
  
  private String getBeanName(EJBLink link) {
	  EObject eObject = link.eContainer();
	  if (eObject instanceof ServiceImplBean)
		  return getBeanName((ServiceImplBean) eObject);
	  return "";
  }
}

Back to the top