Dienstag, 9. November 2010

Confluence: Freemind mindmaps embedded in pages

If you want to embed freemind (*.mm) mindmaps into your confluence page (which is not possible by default) just follow these steps and you're ready to go.


mindmap macro setup
  1. Get the Freemind browser applet from here Freemind at Sourceforge
  2. Create a page in your confluence that can be access by an anonymous user and attach the freemindbrowser.jar to it.
  3. Login as Confluence Administrator and create a new user macro
  4. Put the following code into the template textbox:

#set($width= $param1)
#if (!$width)
  #set ($width=600)
#end
#set($height= $param2)
#if (!$height)
  #set ($height=450)
#end
#set($attachmentUrl="$action.getGlobalSettings().getBaseUrl()$content.getAttachmentNamed($param0).getDownloadPathWithoutEncoding()")
<applet code="freemind.main.FreeMindApplet.class" 
    archive="http://your.company.confluence.server/download/attachments/2687383/freemindbrowser.jar"       width="$width" height="$height">
    <param name="type" value="application/x-java-applet;version=1.4">
    <param name="scriptable" value="false">
    <param name="modes" value="freemind.modes.browsemode.BrowseMode">
    <param name="browsemode_initial_map"
         value="$attachmentUrl">
    <param name="initial_mode" value="Browse">
    <param name="selection_method" value="selection_method_direct">
</applet>
Just replace http://your.company.confluence.server/download/attachments/2687383/freemindbrowser.jar with the url of the attached freemindbrowser.jar

Now you can use the macro with the following syntax to embed freemind mindmaps:
{mindmap:<attachment_filename>[|<width>[|<height>]]}

Example:
{mindmap:my_mindmap.mm|650|500}


Enjoy it! :-)

Montag, 9. August 2010

Dropdown Button for SWT

Ever come to that point you needed a button with an menu that pops up after clicking on it? Same like eclipse has in its toolbars? Yes? So i did. But after doing a bit research, nothing suitable came across. So once again i decided to write it myself.

I wanted the behaviour as shown on the picture. You have an ordinary button (with his whole functionallity) and a menu popup.

The code is finished and ready to use. Just use at your own risk ;-)
http://download.planethost.de/code/DropdownButton.java






Update:
A short snippet for the shell shown above:

public class Snippet {

public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout (new RowLayout ());
    
    SelectionListener sl = new SelectionListener()
        {
        
        @Override
        public void widgetSelected(SelectionEvent e)
            {
            MenuItem mi = (MenuItem)e.getSource();
            System.out.println(mi.getText() + " selected");
            }
        
        @Override
        public void widgetDefaultSelected(SelectionEvent e)
            {
            }
    };
    
    DropdownButton db = new DropdownButton(shell, "myDropButton", SWT.NONE);
    db.addMenuItem("item 1").addSelectionListener(sl);
    db.addMenuItem("item 2").addSelectionListener(sl);
    db.addMenuItem("item 3").addSelectionListener(sl);
    
    shell.pack ();
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
} 

Tooltip enabled CCombo for SWT

After if did a lot of research about a tooltip enabled combo box in SWT I came across several issue reports in the offical issue tracker. There they stated that there will be no tooltip enabled combo box.
So I decied to do it my own because we had a great need for it. 

Et voilá, here it is:
http://download.planethost.de/code/TooltipCCombo.java

Use at your own risk. Tested with Eclipse 3.6 on Windows and Linux.

 Screenshot from TooltipCCombo in action.










A short snippet for the shell shown above:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet {

public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout (new RowLayout ());
    
    TooltipCCombo combo = new TooltipCCombo(shell, SWT.READ_ONLY | SWT.BORDER);
    combo.add("first", "first tooltip");
    combo.add("second", "second tooltip");
    combo.add("fourth", "fourthtooltip");
    combo.add("thrid", 2, "third tooltip");
    
    shell.pack ();
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
}