This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
/
OpenBeanDefinitionAction.java
65 lines (58 loc) · 2.05 KB
/
OpenBeanDefinitionAction.java
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) 2012, 2017 Pivotal, Inc.
* 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:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.beans.ui.live.actions;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean;
import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup;
/**
* @author Leo Dos Santos
* @author Alex Boyko
*/
public class OpenBeanDefinitionAction extends AbstractOpenResourceAction {
public OpenBeanDefinitionAction() {
super("Open Bean Definition File");
}
@Override
public void run() {
IStructuredSelection selection = getStructuredSelection();
List<?> elements = selection.toList();
for (Object obj : elements) {
if (obj instanceof LiveBean) {
LiveBean bean = (LiveBean) obj;
TypeLookup session = bean.getTypeLookup();
String resource = bean.getResource();
if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) {
String resourcePath = extractResourcePath(resource);
if (resourcePath.endsWith(".class")) {
openInEditor(session, extractClassName(resourcePath));
}
}
}
}
}
@Override
protected boolean updateSelection(IStructuredSelection selection) {
if (!selection.isEmpty()) {
List<?> elements = selection.toList();
for (Object obj : elements) {
if (obj instanceof LiveBean) {
LiveBean bean = (LiveBean) obj;
String resource = bean.getResource();
if (resource != null && resource.trim().length() > 0 && !resource.equalsIgnoreCase("null")) {
return true;
}
}
}
}
return false;
}
}