/tools/plugins/com.liferay.ide.portlet.ui/src/com/liferay/ide/portlet/ui/navigator/PortletResourcesActionProvider.java

https://gitlab.com/4615833/liferay-ide · Java · 91 lines · 50 code · 12 blank · 29 comment · 8 complexity · 58bda654ac2f217d772112996b8a4033 MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. *
  14. *******************************************************************************/
  15. package com.liferay.ide.portlet.ui.navigator;
  16. import com.liferay.ide.portlet.ui.navigator.actions.OpenPortletResourceAction;
  17. import org.eclipse.jface.action.IMenuManager;
  18. import org.eclipse.jface.viewers.IStructuredSelection;
  19. import org.eclipse.ui.IActionBars;
  20. import org.eclipse.ui.actions.ActionContext;
  21. import org.eclipse.ui.navigator.CommonActionProvider;
  22. import org.eclipse.ui.navigator.ICommonActionConstants;
  23. import org.eclipse.ui.navigator.ICommonActionExtensionSite;
  24. import org.eclipse.ui.navigator.ICommonMenuConstants;
  25. /**
  26. * @author <a href="mailto:kamesh.sampath@hotmail.com">Kamesh Sampath</a>
  27. */
  28. public class PortletResourcesActionProvider extends CommonActionProvider
  29. {
  30. private OpenPortletResourceAction openAction;
  31. /*
  32. * (non-Javadoc)
  33. * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
  34. */
  35. @Override
  36. public void init( ICommonActionExtensionSite aSite )
  37. {
  38. openAction = new OpenPortletResourceAction();
  39. }
  40. /*
  41. * (non-Javadoc)
  42. * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
  43. */
  44. @Override
  45. public void setContext( ActionContext context )
  46. {
  47. if( ( context != null ) && ( context.getSelection() instanceof IStructuredSelection ) )
  48. {
  49. IStructuredSelection selection = (IStructuredSelection) context.getSelection();
  50. this.openAction.selectionChanged( selection );
  51. }
  52. super.setContext( context );
  53. }
  54. @Override
  55. public void fillContextMenu( IMenuManager menuManager )
  56. {
  57. ActionContext context = this.getContext();
  58. if( ( context == null ) || context.getSelection().isEmpty() )
  59. {
  60. return;
  61. }
  62. if( this.openAction.isEnabled() )
  63. {
  64. menuManager.insertAfter( ICommonMenuConstants.GROUP_OPEN, this.openAction );
  65. }
  66. }
  67. /*
  68. * (non-Javadoc)
  69. * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
  70. */
  71. @Override
  72. public void fillActionBars( IActionBars actionBars )
  73. {
  74. if( this.openAction.isEnabled() )
  75. {
  76. actionBars.setGlobalActionHandler( ICommonActionConstants.OPEN, this.openAction );
  77. }
  78. }
  79. }