XML menu customization

ashukuma
Posts: 10
Joined: Fri Nov 14, 2014 10:04 am

XML menu customization

Post by ashukuma » Fri Nov 14, 2014 12:34 pm

Hi,

I have installed oXygen Eclipse in my system and I am trying to open one DITA sample file as given in the samples. What I have observed is there are two different menu items loaded on opening DITA file. One is XML and other is DITA menu. Since, XML Menu contains menu items related to validation and transformation, I would like to disable/hide XML menu.

I have gone through this post and found out that it can be by writing some java code in some function. If I have to hide XML menu, what can I do, I am not able to understand from the post. Can you please let me know through some code snippet as how can I proceed. It will be really helpful for me.

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Fri Nov 14, 2014 5:23 pm

Hi,

I recommend to start by reading Eclipse IDE Integration. This topic will guide you on how to create a Maven based SDK based project. After you follow the procedure you should focus on project oxygen-sample-eclipse-plugin. In this project there is plugin.xml. You should add in it something like this:

Code: Select all

<extension point="com.oxygenxml.editor.actionBarContributorCustomizer">
<implementation class="my.package.CustomActionBarContributorCustomizer"/>;
</extension>
where CustomActionBarContributorCustomizer is a JAVA class that you must create in this project and extends com.oxygenxml.editor.editors.ActionBarContributorCustomizer. Basically class should be something like this:

Code: Select all

package com.sdk.samples.customizations.eclipse;

import java.util.List;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.CoolBar;
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
import com.oxygenxml.editor.editors.ActionBarContributorCustomizer;

public class CustomActionBarContributorCustomizer extends ActionBarContributorCustomizer {
@Override
public List<IAction> customizeActionsContributedToDocumentMenu(List<IAction> actions) {
// By returning NULL we remove the entire menu.
return null;
}
@Override
public List<IAction> customizeActionsContributedToDocumentToolbar(List<IAction> actions) {
return actions;
}
@Override
public void customizeAuthorPageInternalCoolbar(CoolBar coolBar, WSAuthorEditorPage editorPage) {}
}
Please read README.html from oxygen-sample-eclipse-plugin for information about how to install the plugin.
Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Tue Dec 16, 2014 4:52 pm

HI Alex,

I have used your code to customize the XML menu in oxygen eclipse, but it is having no effect.

Please let me know how I can remove submenus of XML menu using below code. Let me know where to add all these details in the CustomActionBarContributorCustomizer.java file.

( I can see the comment in the code as "// By returning NULL we remove the entire menu." , but please tell me where I need to mention which menu to be customized and which submenu to be removed)

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Wed Dec 17, 2014 9:59 am

Hi Shabeer,

I see that I have an inconsistency in my samples, the implementation given in plugin.xml is not the same with the sample class. Just to clarify it. In oxygen-sample-eclipse-plugin/plugin.xml you add an extension point like this:

Code: Select all

<extension point="com.oxygenxml.editor.actionBarContributorCustomizer">
<implementation class="com.sdk.samples.customizations.eclipse.CustomActionBarContributorCustomizer"/>;
</extension>
Oxygen will now instantiate this class com.sdk.samples.customizations.eclipse.CustomActionBarContributorCustomizer and will call its methods as needed. When you return null on one of these methods the result is that the menu/toolbar will disappear. For the XML menu the called method is customizeActionsContributedToDocumentMenu(List<IAction> actions). This menu has no sub-menus, it's all actions. If you want to selective remove from these actions you can remove them from the list based upon the action text or definition ID:

Code: Select all

public List<IAction> customizeActionsContributedToDocumentMenu(List<IAction> actions) {
// We start with all the actions and we filter some of them.
List<IAction> allowed = new ArrayList<IAction>(actions);
for (Iterator iterator = allowed.iterator(); iterator.hasNext();) {
IAction iAction = (IAction) iterator.next();
if (iAction != null && "com.oxygenxml.editor.validate".equals(iAction.getActionDefinitionId())) {
iterator.remove();
}
}

return allowed;
}

Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Wed Dec 17, 2014 4:57 pm

Hi Alex,

Thank you for the reply!

I have followed all the steps in creating this plugin and placing it in the oxygen eclipse. But still its not working .

Steps followed by me in creating plugin:


1. In eclipse I used the sample packages provided by you for creating the plugin.

I used "oxygen-sample-eclipse-plugin" from the listed samples.

2. First of all, I removed all other packages from the "oxygen-sample-eclipse-plugin"

3. Added com.sdk.samples.customizations.eclipse package with the java file CustomActionBarContributorCustomizer.java.
( The content are same as you shared previously(for removing entire menu))

4. In plugin.xml, added the extension point as you mentioned in the previous mail.

Note:- In README.html, it is mentioned that we need to remove all org.eclipse* dependencies. This step I have not done as it is making compilation errors.
But I could build the project once removing these dependencies also. But still it didn't work. So I don't think this is the issue.

5. Converted the project to plugin project using the option "Configure/Convert to Plug-in Projects "

6. Created jar out of the package by right clicking "oxygen-sample-eclipse-plugin" package and clicking Run as -> maven install option.

This created a jar file in the target directory as mentioned.

7. I placed the jar file inside Eclipse -> dropins folder. ( In dropins folder oxygen XML Author 16 is already there. So I placed the jar with the oxygen (not inside))

8. Opened the eclipse and checked the XML menu.
The menu is still there.

Please let me know whether am wrong in any step. If I have missed anything please let me know.

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Thu Dec 18, 2014 1:03 pm

Hello Shabeer,
2. First of all, I removed all other packages from the "oxygen-sample-eclipse-plugin"
If you take a look inside /oxygen-sample-eclipse-plugin/META-INF/MANIFEST.MF you will see that it is dependent on the structure of your packages. For once I think that you need to keep the class com.oxygenxml.sdksamples.eclipse.SamplePlugin which is the Bundle-Activator. After that here is how I've modified the MANIFEST.MF:

Code: Select all

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Require-Bundle: org.eclipse.ui,
org.eclipse.ui.workbench.texteditor,
org.eclipse.core.runtime.compatibility,
com.oxygenxml.editor,
org.eclipse.ui.views
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Auto-Generated-Export-Package: AutoReplaced
Export-Package: com.sdk.samples.customizations.eclipse
Bundle-Name: oXygen Sample Eclipse Extension
Bundle-SymbolicName: com.sdk.samples.customizations.eclipse.plugin.c;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: com.sdk.samples.customizations.eclipse.SamplePlugin
Bundle-Vendor: Syncro
One strange thing I had to do is modify Bundle-SymbolicName to get an Ecluipse 4.4 to load it. An Eclipse 4.3 had no problem with that (might have been related with some caching issues).

Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Thu Dec 18, 2014 2:50 pm

Hi Alex,

I have taken care of all the points mentioned. But still the result is same

Please tell me whether any of the below points causing me the problem

1. The eclipse version I am doing the plugin creation is 4.4 (eclipse Luna). But the eclipse which contains oxygen is Eclipse Kepler. So I am creating from Eclipse Luna and placing the resulting jar file in dropins folder of eclipse kepler.
2. The java version I am having is 1.7.

3. In plugin.xml, I can see SampleView as one extension. But I am not keeping the SampleView.java in creating the output. Shall I comment out the extension?

4. In README.html, it is mentioned that we need to remove all org.eclipse* dependencies. This step I have not done as it is making compilation errors.

5. I am using the code which you provided in the beginning(for removing entire XML menu). I have not used the code for removing some particular actions from the menu as the code is giving me compilation errors.

Thanks in advance!

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Thu Dec 18, 2014 4:41 pm

Hi Shabber,

If you are using the Author distribution then the extension point ID is a little different (I'm sorry for noticing this aspect sooner):
<extension point="com.oxygenxml.author.actionBarContributorCustomizer">
<implementation class="com.sdk.samples.customizations.eclipse.CustomActionBarContributorCustomizer"/>;
</extension>
1. The eclipse version I am doing the plugin creation is 4.4 (eclipse Luna). But the eclipse which contains oxygen is Eclipse Kepler. So I am creating from Eclipse Luna and placing the resulting jar file in dropins folder of eclipse kepler.
I found Eclipse 4.4 as being a little strange in some situations (like I've said I had to modify the Bundle-SymbolicName to get it to load the plugin). If you could also have an 4.3 for testing it might be better.
3. In plugin.xml, I can see SampleView as one extension. But I am not keeping the SampleView.java in creating the output. Shall I comment out the extension?
Yes, if you are not using it you should remove it.
4. In README.html, it is mentioned that we need to remove all org.eclipse* dependencies. This step I have not done as it is making compilation errors.
Once you convert the project using "Configure/Convert to Plug-in Projects " you should no longer have any errors determined by those missing jars. Eclipse will automatically put those jars in the classpath while compiling the classes.

Other than that all of your steps look correct. Please let me know if after changing the extension point it all worked out.

Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Fri Dec 19, 2014 3:46 pm

Hi Alex,

I have taken care all the comments (except eclipse version)which you have mentioned. But result is still the same.

In the package I have below files,

CustomActionBarContributorCustomizer.java (the code which you have shared)
SamplePlugin.java (existing code)
MANIFEST.MF (contains details which you shared)
pom.xml
plugin.xml

pom.xml contains below details

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>myGroup</groupId>
      <artifactId>mySample</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>
   <name>oXygen Sample Eclipse Extension</name>
   <organization>
      <name>Syncro Soft SRL</name>
   </organization>
   <artifactId>oxygen-sample-eclipse-plugin</artifactId>
   <packaging>jar</packaging>

   <properties>
      <manifest.file>${project.basedir}/target/MANIFEST.MF.TMP</manifest.file>
   </properties>

   <dependencies>
  <!--    <dependency>
         <groupId>org.eclipse</groupId>
         <artifactId>jface</artifactId>
         <version>3.2.1-M20060908-1000</version>
      </dependency>
         <dependency>
         <groupId>org.eclipse.ui.workbench</groupId>
         <artifactId>texteditor</artifactId>
         <version>3.2.0-v20060605-1400</version>
      </dependency>
      <dependency>
         <groupId>org.eclipse.swt.win32.win32</groupId>
         <artifactId>x86</artifactId>
         <version>3.3.0-v3346</version>
      </dependency>      -->
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
      </dependency>


   </dependencies>

   <build>
      <plugins>

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
               <fork>true</fork>
               <executable>${env.JAVA_HOME}/bin/javac</executable>
               <compilerVersion>1.6</compilerVersion>
               <source>1.6</source>
               <target>1.6</target>
               <debug>true</debug>
            </configuration>
         </plugin>

         <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
               <execution>
                  <id>copy-resources</id>
                  <phase>generate-resources</phase>
                  <goals>
                     <goal>copy-resources</goal>
                  </goals>
                  <configuration>
                     <outputDirectory>${project.basedir}/target/classes</outputDirectory>
                     <resources>
                        <resource>
                           <directory>${project.basedir}</directory>
                           <includes>
                              <include>plugin.xml</include>
                           </includes>
                           <filtering>true</filtering>
                        </resource>
                     </resources>
                  </configuration>
               </execution>
            </executions>
         </plugin>

         <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
               <execution>
                  <phase>generate-resources</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <target>
                        <echo>PN: ${project.name}</echo>
                        <copy file="META-INF/MANIFEST.MF" tofile="${manifest.file}" force="true" />

                        <replaceregexp file="${manifest.file}" match="Bundle-Name: (.*)" replace="Bundle-Name: ${project.name}" byline="true" />

                        <replaceregexp file="${manifest.file}" match="Bundle-Version: (.*)" replace="Bundle-Version: ${project.version}" byline="true" />
                        <replaceregexp file="${manifest.file}" match="Bundle-Version: (.*)-SNAPSHOT" replace="Bundle-Version: \1" byline="true" />

                        <replaceregexp file="${manifest.file}" match="Bundle-Vendor: (.*)" replace="Bundle-Vendor: ${project.organization.name}" byline="true" />
                     </target>
                  </configuration>
               </execution>
            </executions>
         </plugin>

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archive>
                  <manifestFile>${manifest.file}</manifestFile>
               </archive>
            </configuration>
         </plugin>
      </plugins>
       
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-antrun-plugin</artifactId>
                                        <versionRange>[1.7,)</versionRange>
                                        <goals>
                                            <goal>run</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
   </build>

</project>
The plugin.xml contains below details

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>

<plugin>
    <extension point="com.oxygenxml.author.outlineDelimiters">
        <delimiters
            name="Oxygen Outline Delimiters Extension"
            start="["
            end="]">
        </delimiters>
    </extension>
   
   <extension point="com.oxygenxml.author.actionBarContributorCustomizer">
       <implementation class="com.sdk.samples.customizations.eclipse.CustomActionBarContributorCustomizer"/>;
   </extension>
   
 <!--   <extension point="com.oxygenxml.author.contextMenuAdditions">
        <group id="Example_group_1">
            <action
                id="Example_action_1"
                label="Replace selection"
                icon="images/ReplaceText16.gif"
                text="NEW_TEXT"
                class="myGroup.mySample.eclipse.action.ReplaceTextAction"/>
        </group>
    </extension>-->

   <!-- TODO This extension point is not working. -->
  <!--  <extension point="com.oxygenxml.author.outlineMenuAdditions">
        <action
            id="Example_action_2"
            label="Select tag"
            icon="images/SelectTag14.gif"
            class="myGroup.mySample.eclipse.action.SelectTagAction"/>
    </extension>

    <extension point="com.oxygenxml.author.toolbarActions">
        <action
            id="Example_action_3"
            label="Locks/Unlocks the XML Tags"
            lockIcon="images/Lock16.gif"
            unlockIcon="images/Unlock16.gif"
            class="myGroup.mySample.eclipse.action.LockUnlockTagsAction"/>
    </extension>-->
   
    <!-- A sample view which accesses functionality from the opened XML Editors.-->
 <!--   <extension point="org.eclipse.ui.views">
           <view class="myGroup.mySample.eclipse.SampleView"
            icon="images/View16.gif"
            id="myGroup.mySample.eclipse.SampleView"
            name="Sample View"/>
    </extension>-->
   <!-- TODO We should add an example using the author API. -->

     
</plugin>
I am creating the jar file by right clicking the "oxygen-sample-eclipse-plugin" foder and using the option Run as -> Maven install. I am placing this directly in eclipse dropins folder.

Please tell me if anything is wrong in any of these?

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Fri Dec 19, 2014 4:31 pm

Hi Shabeer,

I can see nothing wrong with what you've described. Can you send me the oxygen-sample-eclipse-plugin-0.0.1-SNAPSHOT.jar package on support@oxygenxml.com so I can test it myself?

Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Fri Dec 19, 2014 5:25 pm

Hi Alex,

I have sent the jar file to the mentioned mail id.

Please check the same and let me know what's going wrong there and please reply back to this mail chain only.

Many thanks in advance!

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Mon Dec 22, 2014 10:02 am

Hi Shabeer,

The only thing wrong that I saw was that MANIFEST.MF declared dependencies on both of the author (com.oxygenxml.author) and oxygen(com.oxygenxml.editor) distribution. After removing com.oxygenxml.editor from the Require-Bundle entry the plugin was loaded and the XML menu was not presented. I've tested in an Eclipse 4.4 distribution with an Author 16.1 plugin.

Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Wed Dec 24, 2014 9:52 am

Hi Alex,

The solution you have provided has worked now .

Thanks a million for the support provided by you!

With your help, [quote]we could customize XML menu in oxygen eclipse and also we could create our own action in DITA menu.[/quote]

We got the best support at proper time.

Wish you a very happy Christmas!

We expect same support further also.

Regards,
Shabeer

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Mon Jan 05, 2015 10:07 am

Hi,

Can anyone please tell me how to customize the general "contextual menu" of oXygen Author like text, edit profiling attributes,refactoring, review, etc.

Thanks in advance!

Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Mon Jan 05, 2015 10:27 am

Hello Navaneetha,

Which distribution of Oxygen you want to customize? The Eclipse plugin or the Standalone distribution?

Best regards,
Alex

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Mon Jan 05, 2015 10:32 am

Hello,

I want it for Eclipse plug-in

Regards,
navaneetha

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Mon Jan 05, 2015 11:45 am

Eclipse Version

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Mon Jan 05, 2015 4:06 pm

Hello,

Unfortunately the extension point com.oxygenxml.editor.actionBarContributorCustomizer doesn't yet allow you to do this but the good news is that it will, starting with version 17.0. Until version 17.0 is out there is another way to do this. You should start with the sample Eclipse plugin project. Inside plugin.xml add these lines:

Code: Select all

<extension point="org.eclipse.ui.startup">
<startup class="com.oxygenxml.sdksamples.eclipse.SampleStartup"/>
</extension>
Create a the class com.oxygenxml.sdksamples.eclipse.SampleStartup with this content:

Code: Select all

package com.oxygenxml.sdksamples.eclipse;

import java.net.URL;

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.structure.AuthorPopupMenuCustomizer;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.exml.workspace.api.editor.WSEditor;
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
import ro.sync.exml.workspace.api.listeners.WSEditorListener;

public class SampleStartup implements IStartup {

private AuthorPopupMenuCustomizer popUpCustomizer = new AuthorPopupMenuCustomizer() {
@Override
public void customizePopUpMenu(Object popUp, AuthorAccess authorAccess) {
IMenuManager popManager = (IMenuManager) popUp;
iterate(popManager);
}

private void iterate(IMenuManager popManager) {
IContributionItem[] items = popManager.getItems();
for (int i = 0; i < items.length; i++) {
IContributionItem iContributionItem = items[i];
System.out.println(iContributionItem.getId());
// TODO Here you should check for the actions to remove.
if ("some.id".equals(iContributionItem.getId())) {
popManager.remove(iContributionItem);
}

if (iContributionItem instanceof IMenuManager) {
iterate((IMenuManager) iContributionItem);
}
}
}
};

private void customizeContextualMenu(WSEditor editorAccess) {
WSEditorPage currentPage = editorAccess.getCurrentPage();
if (currentPage instanceof WSAuthorEditorPage) {
// Just in case the user switches between the text and author page
// multiple times, we need to remove any previously added listener.
((WSAuthorEditorPage) currentPage).removePopUpMenuCustomizer(popUpCustomizer);
((WSAuthorEditorPage) currentPage).addPopUpMenuCustomizer(popUpCustomizer);
}
}

@Override
public void earlyStartup() {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
URL[] allEditorLocations = pluginWorkspace.getAllEditorLocations(PluginWorkspace.MAIN_EDITING_AREA);
if (allEditorLocations != null) {
for (int i = 0; i < allEditorLocations.length; i++) {
WSEditor editorAccess = pluginWorkspace.getEditorAccess(allEditorLocations[i], PluginWorkspace.MAIN_EDITING_AREA);
customizeContextualMenu(editorAccess);
}
}


window.getPartService().addPartListener(new IPartListener() {
@Override
public void partOpened(IWorkbenchPart part) {
if (part instanceof WSEditor) {
final WSEditor editorAccess = (WSEditor) part;

customizeContextualMenu(editorAccess);

// Just in case the editor is not open in the author page, we need a listener.
editorAccess.addEditorListener(new WSEditorListener() {
@Override
public void editorPageChanged() {
customizeContextualMenu(editorAccess);
}
});
}
}
@Override
public void partDeactivated(IWorkbenchPart part) {}
@Override
public void partClosed(IWorkbenchPart part) {}
@Override
public void partBroughtToTop(IWorkbenchPart part) {}
@Override
public void partActivated(IWorkbenchPart part) {}
});
}
}
});
}
}
The code above adds an ro.sync.ecss.extensions.api.structure.AuthorPopupMenuCustomizer. There is a sample code in it that iterates over the items from the pop-up menu and shows how to remove them.

Best regards,
Alex

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Tue Jan 06, 2015 10:16 am

Hello,

Thanks for your quick response!

I have created the sample oxygen eclipse plug-in and added the extension point in plug-in.xml and tried to remove the 'Generate Ids' using this id "com.oxygenxml.author.extension.generate.ids", the build was successful but that item has not been removed from contextual menu.

Can you please tell what else I need to do?

Thanks & Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Tue Jan 06, 2015 10:31 am

Hello,

The id that will identify the Generate IDs action at this point is Author/generate.ids. Another thing to consider is that this particular action is an author action. That means it can also be removed from the document type/framework configuration dialog. Select tab Author, then Contextual menu, identify and remove the action with the name ${i18n(generate.ids)} on the Current actions section. The next step is to share the altered document typewith your users.

Best regards,
Alex

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Tue Jan 06, 2015 12:22 pm

Hi,

We would like to customize other items which are not available in framework.

We are using "Plug-in Menu Spy" to find the id's of menu items(Is this the correct way of finding the ids??) and we tried to use them in the above code but it doesn't work. we have added this extension in oxygen-eclipse-sample -plugin's plug-in.xml

Code: Select all

    <extension point="com.oxygenxml.author.actionBarContributorCustomizer">
<implementation class="com.sdk.samples.customizations.eclipse.CustomActionBarContributorCustomizer"/>;
</extension>

<extension point="org.eclipse.ui.startup">
<startup class="com.sdk.samples.customizations.eclipse.SampleStartup"/>
</extension>
We have placed the java file in the same path.

Do we need to do any other change in existing enviroment.

Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Tue Jan 06, 2015 1:02 pm

Hello,

Personally I have no experience working with "Plug-in Menu Spy" so I can't really tell you anything about that. You can get get the IDs of the sub-menus and actions added in the contextual menu with a code like the one below (it prints them to the output console). After seeing the ID/Action Definition ID/Text of a menu/action that you must remove you can call the popManager.remove(iContributionItem) method.

Code: Select all

private void iterate(IMenuManager popManager, String level) {
IContributionItem[] items = popManager.getItems();
for (int i = 0; i < items.length; i++) {
IContributionItem iContributionItem = items[i];

if (iContributionItem instanceof MenuManager) {
MenuManager submenu = (MenuManager) iContributionItem;
System.out.println(level + submenu.getId() + " - " + submenu.getMenuText());

iterate((IMenuManager) iContributionItem, level + " ");
} else if (iContributionItem instanceof ActionContributionItem) {
ActionContributionItem action = (ActionContributionItem) iContributionItem;
System.out.println(level + iContributionItem.getId() + " - " + action.getAction().getActionDefinitionId() + " - " + action.getAction().getText());
} else {
System.out.println(level + iContributionItem.getId() + " " + iContributionItem.getClass());
}
}
}
Do you see the output? I'm trying to understand if the com.sdk.samples.customizations.eclipse.SampleStartup was loaded or not. Do you see an warning from Eclipse that might led you to believe that the extension was not loaded? What Eclipse version/distribution are you using?

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Thu Jan 08, 2015 10:24 am

Hi,

I did not get any output. My Eclipse version is: Luna Service Release 1 (4.4.1)

I have pasted your code and then placed a call for that function

Code: Select all

         String level = null;
iterate(popManager,level);
Then I have created the jar file and placed in the dropins folder, Opened oXygen Perspective with on DITA file in Author mode and right clicked on it, but I cannot see any output in console.

Did I miss anything or do we need to follow some other steps?

Thanks & Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Thu Jan 08, 2015 1:22 pm

Hello,

I'm not sure where will those System.out logs end up in this situation. You might want to write to a file instead.

For debugging and faster tests I recommend following the procedure from oxygen-sample-eclipse-plugin/README.html, section How to build the project. After converting the project to an Plug-in Project you can run it as an Eclipse Application (from the contextual menu Run As->Eclipse Application). The Oxygen/Author plugin should also be installed in this Eclipse.

Another aspect worth checking is the dependency in oxygen-sample-eclipse-plugin/META-INF/MANIFEST.MF. If you are testing your plugin with an Oxygen Editor distribution make sure that Require-Bundle specifies com.oxygenxml.editor as dependency. If you are testing your plugin against an Oxygen Author distribution then the id is different: com.oxygenxml.author.

Best regards,
Alex

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Fri Jan 09, 2015 10:01 am

Hi,
I have oXygen author in Eclipse and I have checked com.oxygenxml.author in manifest file it is there

When I try to run this as Eclipse application it is not launching Eclipse rather i am getting below errors:

Code: Select all


org.osgi.framework.BundleException: Could not resolve module: ContextualMenu [3]
Unresolved requirement: Require-Bundle: org.eclipse.ui
Could not resolve module: com.oxygenxml.author [13]
Unresolved requirement: Require-Bundle: org.eclipse.compare
Can you please tell me what I should do check this?

Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Fri Jan 09, 2015 10:56 am

Hello,

The content of META-INF/MANIFEST.MF should look like this:

Code: Select all

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Require-Bundle: org.eclipse.ui,
org.eclipse.ui.workbench.texteditor,
org.eclipse.core.runtime.compatibility,
com.oxygenxml.author,
org.eclipse.ui.views
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Auto-Generated-Export-Package: AutoReplaced
Export-Package: com.oxygenxml.sdksamples.eclipse,
com.oxygenxml.sdksamples.eclipse.action
Bundle-Name: oXygen Sample Eclipse Extension
Bundle-SymbolicName: com.oxygenxml.sdksamples.eclipse.plugin;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: com.oxygenxml.sdksamples.eclipse.SamplePlugin
Bundle-Vendor: Syncro
Plugin-Class: com.oxygenxml.sdksamples.eclipse.SamplePlugin
Bundle-ActivationPolicy: lazy
On the Package Explorer view, contextual menu, select Run as->Run Configurations. Select the Eclipse Application category and select New from the contextual menu. On the new configuration go to tab Plug-ins and in the Launch with combo select "plug-ins selected below only". Check that you are seeing and that are selected the plugins: com.oxygenxml.sdksamples.eclipse.plugin, com.oxygenxml.author. Click Run and it should work correctly.

Best regards,
Alex

nagang
Posts: 32
Joined: Mon Jul 14, 2014 9:48 am

Re: XML menu customization

Post by nagang » Mon Jan 12, 2015 12:18 pm

Hi Alex,

I have followed the steps which you have told.

When I select Run as 'Eclipse Application' I am getting the below error:

Code: Select all

!ENTRY com.oxygenxml.author 4 0 2015-01-12 14:51:01.858
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Could not resolve module: com.oxygenxml.author [12]
Unresolved requirement: Require-Bundle: org.eclipse.compare
Can you please what I should do to resolve this?

Thanks & Regards,
Navaneetha

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Mon Jan 12, 2015 1:06 pm

Hi,

Oxugen requires the Eclipse Platform XML Compare plugin. Depending on which Eclipse distribution you are using this plugin should be already present inside the workbench.
On the Package Explorer view, contextual menu, select Run as->Run Configurations. Select the Eclipse Application you have configured to run the sample. Go to tab Plug-ins and in the Launch with combo select "plug-ins selected below only". Check that you are seeing org.eclipse.compare and that it is selected. If you are not seeing it then you should install and use an Eclipse distribution that has this plugin, for Example the Eclipse EE package.
Best regards,
Alex

mu258770
Posts: 122
Joined: Mon Aug 18, 2014 4:11 pm

Re: XML menu customization

Post by mu258770 » Tue Jan 20, 2015 4:01 pm

Hi Alex,

We have done the setup for context menu customization of oxygen eclipse. Now we are able to run the application as eclipse application, but we are not getting the required result.

Please find the below steps we have followed :

1. In oxygen-sample-eclipse-plugin, added com.oxygenxml.sdksamples.eclipse pakage with "SampleStartup.java" and "SamplePlugin.java".

SamplePlugin.java content is the existing one only. We didn't change anything in that.

SampleStartup.java content is below :

Code: Select all

package com.oxygenxml.sdksamples.eclipse;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.structure.AuthorPopupMenuCustomizer;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.exml.workspace.api.editor.WSEditor;
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
import ro.sync.exml.workspace.api.listeners.WSEditorListener;

public class SampleStartup implements IStartup {
   
   private AuthorPopupMenuCustomizer popUpCustomizer = new AuthorPopupMenuCustomizer() {
      @Override
      public void customizePopUpMenu(Object popUp, AuthorAccess authorAccess) {
         IMenuManager popManager = (IMenuManager) popUp;
         iterate(popManager, null);
      }

      private void iterate(IMenuManager popManager, String level) {
         IContributionItem[] items = popManager.getItems();
         FileOutputStream fos = null;
         try {
              fos = new FileOutputStream("C:\\Users\\shabeer\\Desktop\\out.txt", true);
                for (int i = 0; i < items.length; i++) {
                   IContributionItem iContributionItem = items[i];
           
                   if (iContributionItem instanceof MenuManager) {
                        MenuManager submenu = (MenuManager) iContributionItem;
                  String s="Text '" + submenu.getMenuText() + "' ID='"+ submenu.getId() + "' " + "\n" ;;
                      fos.write(s.getBytes());                
                        iterate((IMenuManager) iContributionItem, level + "  ");
                   } else if (iContributionItem instanceof ActionContributionItem) {
                        ActionContributionItem action = (ActionContributionItem) iContributionItem;
                  String s="level '" + iContributionItem.getId() + "' ID='"+ action.getAction().getActionDefinitionId() + "' " + action.getAction().getText()+ "\n" ;;   
                  fos.write(s.getBytes()); 
                   } else {
                        String s= iContributionItem.getId() + "-" + iContributionItem.getClass();
                  fos.write(s.getBytes()); 
                   }
                }
             }
          catch (Exception e) {
              e.printStackTrace();
          } finally {
              if (fos != null) {
                 try {
                    fos.close();
                 } catch (IOException e) {
                    e.printStackTrace();
                 }
              }
          }
         }
   };
   
   private void customizeContextualMenu(WSEditor editorAccess) {
      WSEditorPage currentPage = editorAccess.getCurrentPage();
      if (currentPage instanceof WSAuthorEditorPage) {
         // Just in case the user switches between the text and author page
         // multiple times, we need to remove any previously added listener.
         ((WSAuthorEditorPage) currentPage).removePopUpMenuCustomizer(popUpCustomizer);
         ((WSAuthorEditorPage) currentPage).addPopUpMenuCustomizer(popUpCustomizer);
      }
   }

  @Override
  public void earlyStartup() {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    workbench.getDisplay().asyncExec(new Runnable() {
      public void run() {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window != null) {
           PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
           URL[] allEditorLocations = pluginWorkspace.getAllEditorLocations(PluginWorkspace.MAIN_EDITING_AREA);
           if (allEditorLocations != null) {
              for (int i = 0; i < allEditorLocations.length; i++) {
               WSEditor editorAccess = pluginWorkspace.getEditorAccess(allEditorLocations[i], PluginWorkspace.MAIN_EDITING_AREA);
               customizeContextualMenu(editorAccess);
            }
           }
           
           
          window.getPartService().addPartListener(new IPartListener() {
            @Override
            public void partOpened(IWorkbenchPart part) {
              if (part instanceof WSEditor) {
                final WSEditor editorAccess = (WSEditor) part;

            customizeContextualMenu(editorAccess);
           
            // Just in case the editor is not open in the author page, we need a listener.
            editorAccess.addEditorListener(new WSEditorListener() {
               @Override
               public void editorPageChanged() {
                  customizeContextualMenu(editorAccess);
               }
            });
              }
            }
            @Override
            public void partDeactivated(IWorkbenchPart part) {}
            @Override
            public void partClosed(IWorkbenchPart part) {}
            @Override
            public void partBroughtToTop(IWorkbenchPart part) {}
            @Override
            public void partActivated(IWorkbenchPart part) {}
          });
        }
      }
    });
  }
}
2. We added extension point in plugin.xml as you mentioned.

Code: Select all

    <extension point="org.eclipse.ui.startup">
        <startup class="com.oxygenxml.sdksamples.eclipse.SampleStartup"/>
    </extension>
3. Manifest content we kept the same which you have shared.

4. We ran the plugin as Eclipse application by following the method which you have suggested(this eclipse contains the oxygen author plugin and the plugin jar file). It is successfully launching, but we are not able to get the menu id s in the output file, neither the output file gets created.

5. We have also tried the same by keeping SampleStartup.java content as the one which you shared (For printing the ids in the console)

Please let us know the way forward.

Regards,
Shabeer

alex_jitianu
Posts: 670
Joined: Wed Nov 16, 2005 11:11 am

Re: XML menu customization

Post by alex_jitianu » Tue Jan 20, 2015 4:25 pm

Hello Shabeer,

I've followed the same procedure as you did and in my case the output was generated. Are you saying that yo've checked the MANIFEST.MF and it has a dependency on the com.oxygenxml.author plugin? When running the Eclipse application you usually get a lot of output in the *Console* view. Can you send me the log? Actually all System.out.println() calls we'll get there too so you could use them now for debugging. Does the plugin gets loaded at all (is the earlyStartup() method called)?

Best regards,
Alex

Post Reply