use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.
the class OpenPortletResourceAction method selectAndRevealItem.
/**
* @param editor
* TODO: need to work on to fix to reveal the selected node
*/
protected void selectAndRevealItem(IEditorPart editorPart) {
if (this.editorPart instanceof SapphireEditor) {
SapphireEditorForXml editor = (SapphireEditorForXml) editorPart;
PortletNode portletNavigatorNode = (PortletNode) selectedNode;
Element selectedModelElement = portletNavigatorNode.getModel();
if (selectedModelElement != null) {
MasterDetailsEditorPage mdepDetailsEditorPage = (MasterDetailsEditorPage) editor.getActivePageInstance();
if (mdepDetailsEditorPage != null) {
MasterDetailsContentOutline contentOutline = mdepDetailsEditorPage.outline();
MasterDetailsContentNodePart rootNode = contentOutline.getRoot();
if (rootNode != null) {
MasterDetailsContentNodeList nodes = rootNode.nodes();
MasterDetailsContentNodePart portletAppNode = nodes.visible().get(0);
MasterDetailsContentNodePart portletsNode = portletAppNode.findNode(_PORTLETS_NODE_LABEL);
if (portletsNode != null) {
if (selectedModelElement instanceof Portlet) {
Portlet selectedPortlet = (Portlet) selectedModelElement;
for (MasterDetailsContentNodePart childNode : portletsNode.nodes().visible()) {
String selectedPortletName = selectedPortlet.getPortletName().content();
if (childNode.getModelElement() instanceof Portlet) {
Portlet mpContentNodePortlet = (Portlet) childNode.getModelElement();
String mpContentNodePortletName = mpContentNodePortlet.getPortletName().content();
if (selectedPortletName.equals(mpContentNodePortletName)) {
childNode.select();
childNode.setExpanded(true);
break;
}
}
}
}
}
}
}
}
}
}
use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.
the class OpenPortletResourceAction method openPortletJavaClass.
/**
* @param file
*/
protected void openPortletJavaClass(IFile file) {
Element modelElement = ((PortletNode) selectedNode).getModel();
if (modelElement instanceof Portlet) {
Portlet portlet = (Portlet) modelElement;
JavaTypeName portletClassFile = portlet.getPortletClass().content();
Runnable run = new Runnable() {
public void run() {
IJavaProject project = JavaCore.create(file.getProject());
String fullyQualifiedName = portletClassFile.qualified();
try {
IType type = project.findType(fullyQualifiedName);
if ((type != null) && type.exists()) {
IResource resource = type.getResource();
if (resource instanceof IFile) {
IFile javaFile = (IFile) resource;
IEditorDescriptor editorDescriptor = findEditor(javaFile);
IEditorPart editorPart = null;
if (editorDescriptor != null) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
editorPart = page.findEditor(new FileEditorInput(javaFile));
if (editorPart == null) {
editorPart = page.openEditor(new FileEditorInput(javaFile), editorDescriptor.getId());
}
} catch (Exception e) {
MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
}
}
}
}
} catch (JavaModelException jme) {
PortletUIPlugin.logError(jme);
}
}
};
Display.getDefault().asyncExec(run);
}
}
use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.
the class OpenPortletResourceAction method run.
@Override
public void run() {
if (isEnabled()) {
IFile file = initEditorPart();
if ((file != null) && file.exists()) {
editorPart = openEditor(file);
if ((editorPart != null) && selectedNode instanceof PortletNode) {
selectAndRevealItem(editorPart);
openPortletJavaClass(file);
}
}
}
}
use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.
the class OpenPortletResourceAction method initEditorPart.
protected IFile initEditorPart() {
IFile file = null;
if (selectedNode instanceof PortletsNode) {
PortletsNode portletsNode = (PortletsNode) selectedNode;
PortletResourcesRootNode rootNode = portletsNode.getParent();
file = ProjectUtil.getPortletXmlFile(rootNode.getProject());
} else if (selectedNode instanceof PortletNode) {
PortletNode portletNode = (PortletNode) selectedNode;
PortletResourcesRootNode rootNode = portletNode.getParent().getParent();
file = ProjectUtil.getPortletXmlFile(rootNode.getProject());
}
if ((editorPart == null) && (file != null)) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorReferences = page.getEditorReferences();
for (IEditorReference iEditorReference : editorReferences) {
if (file.getName().equals(iEditorReference.getName())) {
editorPart = iEditorReference.getEditor(false);
}
}
}
return file;
}
Aggregations