sobota, 4 grudnia 2010

SQLite 3 - cheat sheet

  1. Create new database initialised with given sql script

    sqlite3 -init /path/to/script/centrum2.sql crtest.db
    

    alternativly load script in interactive mode
    sqlite3 crtest.db
    sqlite3> .read /path/to/script/centrum2.sql 
    
  2. Rename particular table
    alter table TBL_PRODUCTS rename to PRODUCTS_OLD;
    
  3. Rename particular column name without loosing data

    Actually it is not possible directly. The workaround can be to create an empty table with new set of columns and populate it with data comes from original table.

    create table PRODUCTS_NEW (..);
    insert into PRODUCTS_NEW select * from PRODUCTS;
    drop table PRODUCTS;
    alter table PRODUCTS_NEW rename to PRODUCTS;
    

    Another workaround can be to use CREATE TABLE .. AS SELECT statement.

    create table PRODUCTS_NEW as select id, name, code as pcode, description from PRODUCTS;
    alter table PRODUCTS_NEW rename to PRODUCTS;
    

piątek, 19 listopada 2010

Eclipse Marketplace and Subclipse (no SVNkit bundled)

Today's morning I had a need to configure brand-new PDT environment (Helios SR1). As I am using SVN for versioning the Subclipse plugin is what I usually use. Couple times before I successfully employed Eclipse Marketplace to do the job. Same was this time, but to my surprise this time I was not able to switch SVN interface to SVNKit. The only available was JavaHL implementation. I hope this will be fixed in future, but for now one need to do additional steps to install SVNKit - traditional way of installing plugins.
Help -> Install New Software -> select Subclipse repository and 
check all the available options

The version I worked with were: PDT (Helios SR1) and Subclipse 1.6.15

niedziela, 7 listopada 2010

ActionScript 3.0 - How to limit frames per second of flash animation

The simples way seems to be use SWF meta tag.
Example:

package myPackage {

import required.imports.*;

[SWF(backgroundColor=0xEEEADB,frameRate="5")]

public class MyClass {
..
}

}

sobota, 30 października 2010

How to set human readable address for your facebook profile

It may be not very obvious how to make your profile has human readable address, but actually it is quite easy.
Account -> Account Settings -> Settings -> Username

Note: After setting chosen username you can not change it again!!

HTML site layout with DIV tag and CSS - 1st attempt



ITEM1 | ITEM2 | ITEM3 | ITEM4

How to build simple site layout with DIV tags


In order to see implementation details please look at source of this site ;>.

wtorek, 17 sierpnia 2010

Menu based on commands (org.eclipse.ui.menus - menuContribution)

Extension point: org.eclipse.ui.menus

In order to add new menu menuContribution entry is used.

locationURI property determines where menu will be added.

Examplary locationURI:
→ popup:org.eclipse.ui.popup.any?after=additions
→ toolbar:org.eclipse.ui.views.ContentOutline?after=additions
→ popup:org.eclipse.jdt.ui.PackageExplorer?before=additions

→ menu:sourceMenuId?before=sourceBegin
→ popup:sourcePopupMenuId?before=sourceBegin
→ menu:sourceMenuId?after=sourceBegin
→ popup:sourcePopupMenuId?after=sourceBegin
→ menu:org.eclipse.ui.main.menu?after=sourceMenuId


Where in that cases sourceMenuId and sourcePopupMenuId are menus registered with org.eclipse.ui.actionSets extension point.

Typically menuContribution entries contain command entries.

Command entries can define visibleWhen and properties.
Example:
<menucontribution locationURI="menu:sourceMenuId?before=sourceBegin">
 <command commandId="org.eclipse.php.ui.edit.text.add.description"
  id="AddDescription" mnemonic="%command.mnemonic" style="push">
 <visiblewhen checkEnabled="false">
 <reference definitionId="org.eclipse.php.ui.phpContentType.definition" />
 </visibleWhen>
 </command>
 </menuContribution>
VisibleWhen among others allow to specify reference property which references to definition regristered with org.eclipse.core.expressions.definitions extension point.

Example:
<extension point="org.eclipse.core.expressions.definitions">
<definition id="org.eclipse.php.ui.phpContentType.definition">
<with variable="activeContexts">
<iterate operator="or">
<equals value="org.eclipse.php.core.phpsource" />
</iterate>
</with>
</definition>
</extension>
Other option can be specifying with property.

Example:
<visiblewhen>
<with variable="selection">
<iterate>
<or>
<instanceof value="o.e.editors.OutlineContentProvider$Sources">
</instanceof>
<instanceof value="o.e.editors.OutlineContentProvider$Targets">
</instanceof>
</or>
</iterate>
</with>
</visibleWhen>
or:
<with variable="selection">
<iterate>
<instanceof
             value="c.c.model.VisualizableBlock">
</instanceof>
</iterate>
</with>

poniedziałek, 19 lipca 2010

Build SWT application with maven

There are couple of issues when trying to use SWT with application using Maven for building and deploying. The most fundamental is that you have to deliver separate application per architecture and windowing system. Another one is the fact there are no up-to-date releases of SWT in common Maven repositories. And finally when trying one platform independent binary all handles platforms must be include particular SWT implementations, but here another issue appears: how to put appropriate SWT on class path.

First lets populate our local maven repository with SWT libraries. The first step is to obtain desirable swt implementation for os/ws/arch triples. Lets assume that for needs of this example we limit supported triples to linux/gtk/x86_64, win32/win32/x86, win32/win32/x86_64.

Best can be use p2 director to grab libraries. There is not easy way for importing all swt implementations into one location therefore here you are somewhat weird workaround - each impl needs to be grabbed into separate location.

director/director -consolelog -r http://download.eclipse.org/releases/helios 
-d SWT_GTK -i org.eclipse.swt.gtk.linux.x86
director/director -consolelog -r http://download.eclipse.org/releases/helios 
-d SWT_GTK64 -i org.eclipse.swt.gtk.linux.x86_64
director/director -consolelog -r http://download.eclipse.org/releases/helios 
-d SWT_WIN -i org.eclipse.swt.win32.win32.x86 -p2.os win32 -p2.ws win32 -p2.arch x86
director/director -consolelog -r http://download.eclipse.org/releases/helios 
-d SWT_WIN64 -i org.eclipse.swt.win32.win32.x86_64 -p2.os win32 -p2.ws win32 -p2.arch x86_64

Note that specifying profile details is needed for non-native implementations.

In order to use eclipse:to-maven target we need to mimic eclipse installation with plugin folder. For Linux users:

/tmp/SWTLIBS$ find SWT* -name "org.eclipse.swt.*.jar" | xargs -I{} cp {} SWTLIBS/plugins/
/tmp/SWTLIBS$ ls SWTLIBS/plugins
org.eclipse.swt.gtk.linux.x86_3.6.0.v3650b.jar     org.eclipse.swt.win32.win32.x86_3.6.0.v3650b.jar
org.eclipse.swt.gtk.linux.x86_64_3.6.0.v3650b.jar  org.eclipse.swt.win32.win32.x86_64_3.6.0.v3650b.jar

Once done install jars to the maven repository:
mvn eclipse:to-maven -DdeployTo=eclipse.org::default::file:///home/krma/.m2/repository 
-DeclipseDir=. -DstripQualifier=true

After that we can receive following dependency entries:

 <groupid>org.eclipse.swt.gtk.linux</groupId>
 <artifactid>x86_64</artifactId>
 <version>3.6.0</version>
</dependency>
<dependency>
 <groupid>org.eclipse.swt.win32.win32</groupId>
 <artifactid>x86_64</artifactId>
 <version>3.6.0</version>
</dependency>
<dependency>
 <groupid>org.eclipse.swt.win32.win32</groupId>
 <artifactid>x86</artifactId>
 <version>3.6.0</version>
</dependency>
<dependency>
 <groupid>org.eclipse.swt.win32.win32</groupId>
 <artifactid>x86_64</artifactId>
 <version>3.6.0</version>
</dependency>

But with such configuration there will be one problem. First of all all the SWT implementation will be included to our build. But this is actually not really true as our artifact names are duplicated.

The solution is to force other naming for artifactID by manual installing each jar into local maven repository
mvn install:install-file -Dfile=org.eclipse.swt.gtk.linux.x86_3.6.0.v3650b.jar -DgroupId=org.eclipse -DartifactId=swt.gtk.linux.x86 -Dversion=3.6.0 -Dpackaging=jar -DgeneratePom=true -Dmaven.repo.local=/path/to/mvnrepo

Now the following can be used:
<dependency>
 <groupid>org.eclipse</groupId>
 <artifactid>swt.gtk.linux.x86</artifactId>
 <version>3.6.0</version>
</dependency>
<dependency>
 <groupid>org.eclipse</groupId>
 <artifactid>swt.gtk.win32.win32</artifactId>
 <version>3.6.0</version>
</dependency>

piątek, 28 maja 2010

How to setup Trac for LDAP authentication

First all of I'd like mentioned i'm not Apache master thus do not take responsibility for potential damages whilst following this tutor. But don't be afraid nothing wrong should happen ;).

But to the point. When we decide to install Trac as Apache/httpd application it comes with some basic authentication based on unix password. The following is typical configuration:

<virtualHost *:80>

  ServerName trac.example.com

  <location />
    SetHandler mod_python
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnv /var/www/trac
    PythonOption TracUriRoot /
  </location>
  <location "/login">
    AuthType Basic
    AuthName "trac"
    AuthUserFile /var/www/trac/auth-file
    Require valid-user
  </location>

</virtualHost>

For switching to LDAP authentication use following:

<virtualhost *:80 >

 ServerName trac.example.com

 <location />
  SetHandler mod_python
  PythonHandler trac.web.modpython_frontend
  PythonOption TracEnv /var/www/trac
  PythonOption TracUriRoot /
 </location>

 <location "/login" >
   AuthType Basic
   AuthBasicProvider ldap
   AuthzLDAPAuthoritative off
   AuthLDAPBindDN "DOMAIN\\BINDUSER"
   AuthLDAPBindPassword PASSWORD
   AuthLDAPUrl LDAPUTL
   AuthName "Authorization required"
   Require valid-user
 </location>

</VirtualHost>


BindDN - the Distinguished Name binddn to bind to the LDAP directory

DOMAIN - name of the domain
BINDUSER - special bind user for accessing non-public data
PASSWORD - password for BINDUSER
LDAPURL - ldap://HOST:389/SEARCHBASE?sAMAccountName?sub

SEARCHBASE - the starting point for the search

The following command can be used to test your LDAP connection:

ldapsearch -h HOST -b "SEARCHBASE" -D "DOMAIN\\BINDUSER" -s sub -x -w PASSWORD "(givenName=K*)"

piątek, 9 kwietnia 2010

IHandler - How to obtain current selection based on ExecutionEvent object

The most common method of implementing custom handler is to subclass AbstractHandler. This very handy class reduce our work to fill just one method: execute(ExecutionEvent event). The entire stub looks as following:

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

public class MyCustomHandler extends AbstractHandler {

 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
  // TODO Auto-generated method stub
  return null;
 }
}

The question is how to obtain selection? Actually it is fairly simple and needs employ HandlerUtil class. This class is particularity interesting as delivers couple of utility method for working with ExecutionEvent object.

Two exemplary methods for obtaining current selection looks as below:

// the most straightforward ;>
ISelection selection = HandlerUtil.getCurrentSelection(event);

// and another more elaborate
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();

ExecutionEvent javadoc:

The data object to pass to the command (and its handler) as it executes. This
carries information about the current state of the application, and the
application context in which the command was executed.

An execution event carries three blocks of data: the parameters, the trigger,
and the application context. How these blocks are used is application
dependent. In the Eclipse workbench, the trigger is an SWT event, and the
application context contains information about the selection and active part.

more..

And someshing more about handlers: org.eclipse.ui.handlers

piątek, 2 kwietnia 2010

How to force line numbering when opening a file with TextEditor?

Generally Eclipse workbench use global setting for line-numbering feature. Thus one need to perform following code to on the numbering.


IPreferenceStore store = EditorsUI.getPreferenceStore();
store.setValue(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, true);

But remember: DO not happing others by force ;). Thus if for some reason you decide your editor absolutely needs the numbering, take care to reset the setting then close the editor.

static private String NUMBERING = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER;
private boolean numbering;

...

IPreferenceStore store = EditorsUI.getPreferenceStore();
numbering = store.getBoolean(NUMBERING);
store.setValue(NUMBERING, true);

...

// when dispose
IPreferenceStore store= EditorsUI.getPreferenceStore();
store.setValue(NUMBERING, numbering);
  
super.dispose();


Eclipse - Workspace Cannot Be Locked (former: Workspace in use or cannot be created)

Full error message:
Could not launch the application because the associated workspace is currently use by another Eclipse application.

Basically the following should do the job:
rm $WORKSPACE_DIR/.metadata/.lock

Quick explanation:
Each time you run Eclipse with particular workspace it is locked. Mechanism of that is quite simple. It is just a .lock file in .metadata directory. Thus the only one need to do in order to unlock workspace is to delete .lock file. Usually such happens when Eclipse hangs and you need restart your machine.

środa, 31 marca 2010

How to work with Selection Service and make your WorkbenchPart more cooperative

The whole power of Eclipse platform comes from its cooperation features among of all it part. We used to see all views and editors work together seamlessly. But when comes to develop our own view or editor we found our part not so eager cooperate with environment. Many of the users found this as big disadvantage of your contribution and will not feel comfortable using it. To avoid you part an alien please let me share some common issues I faced during my advantage with Eclipse plug-in development.


1). Make your view open to cooperate with other parts and share own selection events.

Assuming your XXViewer implements ISelectionProvider interface (common to all objects that provide a selection).

public interface ISelectionProvider {
    public void addSelectionChangedListener(ISelectionChangedListener listener);
    public ISelection getSelection();
    public void removeSelectionChangedListener(ISelectionChangedListener listener);
    public void setSelection(ISelection selection);
}

You should set your view (more precisely your XXViewer) as a Selection Provider. Thus any other part listening on selection service can hear your selection events.

public void createPartControl(Composite parent) {
  viewer = new XXViewer(..);
  getSite().setSelectionProvider(viewer);
}

2). Make your view be aware of the others selection events. Don't let your contribution to be ignorant - listen others.

To do so you need to register your workbench part with the selection service.

private ISelectionListener listener = new ISelectionListener() {
  public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
   doSomeActionHere(IWorkbenchPart sourcepart, ISelection selection);
  }
 };

Also please remember about removing listener when part's dispose. It's really important!!

public void dispose() {
 getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(listener);
 super.dispose();
}

Ok, now you can be absolutely sure that your contribution will be full-rights member of Eclipse community.