Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Blocking all plug-in actions if preference constant is not valid
Blocking all plug-in actions if preference constant is not valid [message #640120] Fri, 19 November 2010 08:29 Go to next message
federico c is currently offline federico cFriend
Messages: 7
Registered: October 2010
Junior Member
Hi everybody!

I have written a plug-in which is 100% coupled with an XML file: if such file cannot be succesfully unmarshalled, none of the actions offered by the plug-in should be executed. The path of file must be set in the eclipse preferences.

My problem is how to prevent plug-in actions to be executed if the unmarshalling is not succesfull. The plug-in offers a View (populated with data from the XML file) but also other extension points (such as popupMenus), so I couldn`t find a single entry point for this control.. Of course I could add everywhere something like:

if (!xmlFileIsValid){
//show alert "please set a valid xml file in the eclipse preferences"
return;
}


but I wonder if there is not a single entry point where I could perform this check..

Thank you very much!
Bye!
Federico
Re: Blocking all plug-in actions if preference constant is not valid [message #640177 is a reply to message #640120] Fri, 19 November 2010 13:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

With commands and handlers, you can add the check to the
org.eclipse.ui.handlers definition (either as a activeWhen or
enabledWhen) that will disable each command if the file is not available.

Then use org.eclipse.ui.menus to add your commands to various popup menus.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Blocking all plug-in actions if preference constant is not valid [message #640925 is a reply to message #640177] Tue, 23 November 2010 15:06 Go to previous messageGo to next message
federico c is currently offline federico cFriend
Messages: 7
Registered: October 2010
Junior Member
Hi Paul!

Thank you for your reply!
Unfortunately I am not really sure I got what you mean...
My plugin.xml looks like this:

<plugin>
   <extension
         point="org.eclipse.ui.views">
      <category
            name="My Category"
            id="my-plugin">
      </category>
      <view
            name="My View"
            icon="icons/sample.gif"
            category="my-plugin"
            class="my.plugin.package.views.MyView"
            id="my.plugin.views.MyView">
      </view>
   </extension>
   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="org.eclipse.jdt.ui.JavaPerspective">
         <view
               ratio="0.5"
               relative="org.eclipse.ui.views.TaskList"
               relationship="right"
               id="my.plugin.views.MyView">
         </view>
      </perspectiveExtension>
   </extension>
   <extension
         point="org.eclipse.ui.popupMenus">
   <objectContribution
            adaptable="false"
            id="my-plugin.PluginManagerObjectContribution"
            nameFilter="*.*"
            objectClass="org.eclipse.ui.IEditorInput">
           <menu
                icon="icons/sample.gif"
                id="my-plugin-pluginManager.popupSubMenu"
                label="My View"
                path="additions">
             <groupMarker
                   name="content">
             </groupMarker>
          </menu>
         <action
               class="my.plugin.package.actions.AnAction"
               enablesFor="1"
               icon="icons/sample.gif"
               id="my-plugin.action1"
               label="Do something with the selected text"
               menubarPath="my-plugin-pluginManager.popupSubMenu/content"
               tooltip="Do something with the selected text">
         </action>
         <action
               class="my.plugin.package.actions.AnotherAction"
               enablesFor="1"
               icon="icons/sample.gif"
               id="my-plugin.action2"
               menubarPath="my-plugin-pluginManager.popupSubMenu/content"
               label="Do something else with the selected text"
               tooltip="Do something else with the selected text">
         </action>
         
      </objectContribution>
   </extension>
   <extension
         point="org.eclipse.ui.preferencePages">
      <page
            class="my.plugin.package.preferences.MyViewPreferencePage"
            id="my.plugin.package.preferences.MyViewPreferencePage"
            name="My View Preferences">
      </page>
   </extension>
   <extension
         point="org.eclipse.core.runtime.preferences">
      <initializer
            class="my.plugin.package.preferences.PreferenceInitializer">
      </initializer>
   </extension>
 
</plugin>


I want to disable both the View and the popupMenus if the xml file is not properly set in the preference page. What were your idea? Can you help me with an example please?

Thank you vey much!
Bye
Federico
Re: Blocking all plug-in actions if preference constant is not valid [message #640963 is a reply to message #640925] Tue, 23 November 2010 17:14 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The view can't really be disabled, except by Activities/Capabilities.

http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench_scalability.htm

popupMenus are targetted at an object, not the general application
state. You would have to look through the org.eclipse.ui.popupMenus
extension point description to see if any of the visibility clauses can
be adapted to check what you want.

There might be an objectContribution/enablement element that can use
core expressions, and then you could create a PropertyTester to check
your preference.

I was suggesting commands and org.eclipse.ui.menus/menuContributions
which use core expressions for activeWhen/enabledWhen/visibleWhen. They
would also use a property tester to test if the preference was set
correctly.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:List of all visible ( package explorer) resources in workspace
Next Topic:Splash handler not running when org.eclipse.osgi run from workbench
Goto Forum:
  


Current Time: Fri Mar 29 07:33:42 GMT 2024

Powered by FUDForum. Page generated in 0.02287 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top