Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Thursday, May 5, 2016

Programatically changing the eclipse perspective

try
{
   PlatformUI.getWorkbench().showPerspective("StudioPerspective", PlatformUI.getWorkbench().getActiveWorkbenchWindow());
}
catch (WorkbenchException e)
{
  e.printStackTrace();

}

Monday, March 21, 2016

Updating eclipse features/plugins from terminal


Format:
./eclipse -clean -purgeHistory -application org.eclipse.equinox.p2.director -noSplash -repository <update site url> -installIUs <feature ID> 


Examples:

./eclipse -clean -purgeHistory -application org.eclipse.equinox.p2.director -noSplash -repository http://download.eclipse.org/recommenders/updates/stable/ -installIUs org.eclipse.recommenders.repositories.categories.deps 


./eclipse -clean -purgeHistory -application org.eclipse.equinox.p2.director -noSplash -repository http://download.eclipse.org/mylyn/releases/latest -installIUs org.eclipse.mylyn.commons.sdk.feature.group


./eclipse -clean -purgeHistory -application org.eclipse.equinox.p2.director -noSplash -repository http://download.eclipse.org/mylyn/releases/latest -installIUs org.eclipse.mylyn.commons.notifications.feature.group


./eclipse -clean -purgeHistory -application org.eclipse.equinox.p2.director -noSplash -repository http://download.eclipse.org/modeling/emf/updates/releases/ -installIUs org.eclipse.emf.databinding.edit.feature.group



Resources:

Friday, February 19, 2016

Text setMessage with SWT.MULTI style

Text setMessage with SWT.MULTI style - Yes, this doesn't work!.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=397695

Seems to be that's a native OS behaviour for Windows and GTK platforms.

Example:

Text  releaseNotesTxt = new Text(appPreviewComposite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL );
releaseNotesTxt.setMessage("Enter your release notes for this build (Optional)");


But this works with SWT.Single or SWT.Search


Wednesday, December 9, 2015

Preferences sharing across all workspaces - Handling programatically

To share preferences across all workspaces in eclipse, you need to save preferences via ConfigurationScope.

What is configuration scope ?

Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by that user. On a multi-user installation, these preferences are shared by all users of the configuration.

How to save ?

IEclipsePreferences store = ConfigurationScope.INSTANCE.getNode(MyUIPlugin.PLUGIN_ID);
if (store != null)
{
store.putBoolean(MyFLAG_PREF, true);
try
{
store.flush();
}
catch (BackingStoreException e)
{
//Log exception
}
}


How to retrieve the saved preference value?

boolean isSet = Platform.getPreferencesService().getBoolean(MyUIPlugin.PLUGIN_ID,
MyFLAG_PREF, false, new IScopeContext[] { ConfigurationScope.INSTANCE });


Understand more about preference scopes:


Managing eclipse global preferences / eclipse installation level preferences

Where are the global preferences stored for eclipse? 
 eclipse\configuration\.settings folder

Here some plugins store their global preferences. For example: the recent workspace settings are in org.eclipse.ui.ide.prefs.

MAX_RECENT_WORKSPACES=5
RECENT_WORKSPACES=/Users/kondalkolipaka/development/workspaces/devbranch2\n/Users/kondalkolipaka/development/workspaces/devbranch
RECENT_WORKSPACES_PROTOCOL=3
SHOW_WORKSPACE_SELECTION_DIALOG=true
eclipse.preferences.version=1

Same way you can store your plugin global preferences in your own file.

Take a look at this.
http://mcuoneclipse.com/2012/04/06/eclipse-global-preferences/

Sunday, December 6, 2015

Fragments in OSGI - Eclipse


A Bundle fragment, or simply a fragment, is a bundle whose contents are made available to another bundle (the fragment host). Importantly, fragments share the classloader of their parent bundle. One notable difference is that fragments do not participate in the lifecycle of the bundle, and therefore cannot have an Bundle-Activator.


Example:
These are 2 plugins which does not have any activator classes.
org.eclipse.epp.logging.aeri.ui
org.eclipse.epp.logging.aeri.ide - Host Plugin

And, In org.eclipse.epp.logging.aeri.ide plugin MANIFEST.MF file, you can find below section:
Fragment-Host: org.eclipse.epp.logging.aeri.ui;bundle-version="1.0.0"


At runtime the fragment is merged with its host plug-in and for the runtime both projects are just one. Fragments are always optional for their host plug-in and the host plug-in doesn't even know that it exists.

Thursday, December 3, 2015

"No repository found containing: osgi.bundle" error message during the Eclipse udpate

Below trick helped me to resolve the problem.

Help>Install new software>Uncheck "Contact all update sites during install to find required software"

Tuesday, December 1, 2015

How to identify whether you working in development or debug mode in eclipse RCP

Being a eclipse plugin development programmer, we need to perform certain operations based on the mode you working on.

Eclipse provides a way to identify whether your eclipse is running in debug mode or development mode.

if (Platform.inDevelopmentMode()) //it will look for osgi.dev property
{
  //you are running in development mode.
}

if (Platform.inDebugMode()) //it will look for osgi.debug property
{
  //you are running in debug mode.
}


Thursday, November 19, 2015

How to control eclipse Java formatter on or off

This you can be controlled from Eclipse preferences.

Eclipse preferences: Java > Code Style > Formatter. Click on "Edit" button, "Off/On Tags", check off "Enable Off/On tags".

How to use in the code:
// @formatter:off
...your code here won't be formatted
// @formatter:on




How to listen to Eclipse Log errors

Register a listener in your Core Plugin startup:

Platform.addLogListener(new MyLogListener());

Listen to the log:

import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class MyLogListener implements ILogListener
{

@Override
public void logging(IStatus status, String plugin)
{
if (status.getCode() == IStatus.ERROR)
{
startJob(status);
}
}

private void startJob(final IStatus status)
{
Job job = new Job("Reporting error...")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
System.out.println("===============Studio error reporting starts==============");
String ticketMessage = status.getMessage();
System.out.println(ticketMessage);
Throwable exception = status.getException();
exception.printStackTrace();
 System.out.println("===============Studio error reporting ends==============");
return null;
}
};
job.schedule();
}

}

Wednesday, November 11, 2015

How to change the default console output buffer size in Eclipse

Eclipse User:

In Window > Preferences > Run/Debug > Console there's a checkbox "Limit console output" and a textfield for entering the buffer size of the console. However, you can increase it up to 1000000

Eclipse Plugin Development:

To uncheck the console output limit:
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
store.setDefault(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT, false);
To change only the buffer limit:
store.setDefault(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK, 500000);

Sunday, September 13, 2015

How can I pass arguments to an extension point constructor/ createExecutableExtension with parameters in eclipse

Please also refer to my previous post.
http://exploreeclipse.blogspot.in/2015/09/reading-extension-point-from-eclipse.html


public void readExtensionPoint(String myjsonString) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("com.kk.myplugin", "services");
for (IConfigurationElement iConfigurationElement : elements)
{
iConfigurationElement.getAttribute("service_id");
iConfigurationElement.getAttribute("name");
try
{
try
{
String attribute = iConfigurationElement.getAttribute("class");
String contributorName = iConfigurationElement.getDeclaringExtension().getContributor().getName();
Class<?> javaClass = Platform.getBundle(contributorName).loadClass(attribute);
Constructor<?> ctor = javaClass.getDeclaredConstructor(String.class);
IService service = (IService) ctor.newInstance(myjsonString);
return service;
}
catch (Exception e)
{
}
}
catch (CoreException e)
{
e.printStackTrace();
}
}


}

Reading an extension point from eclipse plugin

public void readExtensionPoint() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("com.kk.core", "platformServices");
for (IConfigurationElement iConfigurationElement : elements)
{
iConfigurationElement.getAttribute("id");
try
{
//This is your class
Object createExecutableExtension = iConfigurationElement.createExecutableExtension("class");
}
catch (CoreException e)
{
e.printStackTrace();
}
}

}


Here is my extension point schema definition:

<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="com.kk.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
      <appinfo>
         <meta.schema plugin="com.kk.core" id="platformServices" name="platformServices"/>
      </appinfo>
      <documentation>
         [Enter description of this extension point.]
      </documentation>
   </annotation>

   <element name="extension">
      <annotation>
         <appinfo>
            <meta.element />
         </appinfo>
      </annotation>
      <complexType>
         <sequence minOccurs="1" maxOccurs="unbounded">
            <element ref="service"/>
         </sequence>
         <attribute name="point" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="id" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="name" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
               <appinfo>
                  <meta.attribute translatable="true"/>
               </appinfo>
            </annotation>
         </attribute>
      </complexType>
   </element>

   <element name="service">
      <complexType>
         <attribute name="id" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="class" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
               <appinfo>
                  <meta.attribute kind="java" basedOn="com.kk.core.services.Service:com.kk.core.services.IService"/>
               </appinfo>
            </annotation>
         </attribute>
      </complexType>
   </element>

   <annotation>
      <appinfo>
         <meta.section type="since"/>
      </appinfo>
      <documentation>
         [Enter the first release in which this extension point appears.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="examples"/>
      </appinfo>
      <documentation>
         [Enter extension point usage example here.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="apiinfo"/>
      </appinfo>
      <documentation>
         [Enter API information here.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="implementation"/>
      </appinfo>
      <documentation>
         [Enter information about supplied implementation of this extension point.]
      </documentation>
   </annotation>


</schema>


Extension:
   <extension
         id="com.kk.core.platform.services"
         name="KK Platform Services"
         point="com.core.platformServices">
      <service
            class="com.kk.core.services.CheckService"
            id="xx34567vvk">
      </service>
     
   </extension>

Sunday, September 6, 2015

Storing in eclipse secure storage with encryption

ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/com/kk/store"); //path

//store
try
{
node.put("myusername", "mysecretpassword", true);
}
catch (StorageException e)
{
e.printStackTrace();

}

Where does Eclipse secure storage file is saved ?

This you can find from Eclipse preferences.
Eclipse -> Preferences -> General -> Security -> Secure Storage -> Contents Tab

Here you can find 'Storage Location'.

Example:
/Users/kkolipaka/.eclipse/org.eclipse.equinox.security/secure_storage



How to get the Eclipse Installation location ?

Eclipse provided a direct API call for this.

Platform.getInstallLocation().getURL();

To get a string path:

Platform.getInstallLocation().getURL().getPath();

Thursday, May 28, 2015

How to specify to load a eclipse plugin only on 32 bit machine but not on 64 bit machine.

It’s simple, specify Eclipse-PlatformFilter flag in MANIFEST.MF file with the required criteria.

For example, I wanted to load my plugin only in 32 bit operating systems.
Eclipse-PlatformFilter: (osgi.os=win32)

for adding multiple conditions.
Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86))

The Framework supports filtering on the following system properties:
* osgi.nl - the platform language setting.
* osgi.os - the platform operating system.
* osgi.arch - the platform architecture.
* osgi.ws - the platform windowing system


Above example specify that, this bundle can only be resolved if the platform properties are osgi.ws=win32 and osgi.os=win32 and osgi.arch=x86. In other words a platform running on an x86 architecture, using a win32 operating system and the win32 windowing system.

We can find this property directly in plugin.xml file "Overview" tab.

Wednesday, May 13, 2015

Eclipse toolbar and menu bar group action id's

ICommonMenuConstants
IWorkbenchActionConstants
IIDEActionConstants


Few examples:
"group.new"
"group.goto"
"group.open"
"group.openWith"
"group.show"
"group.edit"
"group.reorganize"
"group.port"
"group.generate"
"group.search"
"group.build"
"additions"
"group.properties"

These will be used as a insertion points if you are contributing a new action/menu action/toolbar action.


Tuesday, May 5, 2015

Listening to project explorer changes

If you want to control some actions based on the selection of an element from the project explorer, we can register a post selection changes through service registry.

//Register listener
ISelectionService ss = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();

ProjectExplorerSelectionListener selectionListener = new ProjectExplorerSelectionListener();
ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, selectionListener);



//Listener
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;

class ProjectExplorerSelectionListener implements ISelectionListener
{
public void selectionChanged(IWorkbenchPart part, ISelection newSelection)
{
if (newSelection instanceof IStructuredSelection)
{
Object element = ((IStructuredSelection) newSelection).getFirstElement();
if (element instanceof IAdaptable)
{
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
final IProject project = resource.getProject();
//do your action here!!
}
}

}

}

Tuesday, April 14, 2015

Eclipse: Indirectly referenced from required .class files issue

This issue comes when your class is indirectly referring to an other class which is not accessible from your plugin.

For example:











In this scenario, if we get an error some thing like this in Plugin-C.
The type UserAgent cannot be resolved. It is indirectly referenced from required .class files.

The problem is, Plugin-C is unable to locate class from Plugin-A. Because Plugin-C is not added Plugin-A as a dependency.

2 ways we can solve this.
1. Re-export Plugin-A from Plug-in B using "Re-export this dependency" option from Properties in dependencies section.
2. Directly add Plugin-A in Plugin-C dependency list.