Sunday, March 29, 2009
Sampler Eclipse Plug-in
Saturday, March 21, 2009
Reverse Text Selection Eclipse Plug-in
The following screencast shows how you can start with a initial selection and then extend it in both directions using the Reverse Text Selection command (Alt+Shift+/).
Tuesday, March 17, 2009
Google Clips Eclipse Plug-in
Thursday, March 12, 2009
ClickIt a desktop variant of Screen shot Eclipse Plug-in
Saturday, February 21, 2009
Screenshot Plug-in for Eclipse
Thursday, January 01, 2009
Copy paths of selected items in Mac OS X Finder to clipboard
(*
Script: copypaths.app
This script sets the clipboard to the paths of items selected in Finder window.
If there is no selection the clipboard is set to the path of the target
of the Finder window.
Installation:
1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/copypaths.app
3. Drag and drop copypaths.app onto the Finder widow toolbar.
@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
set paths to ""
set selected to selection
if (count of selected) is 0 then
set paths to POSIX path of (target of front window as alias)
else
repeat with aPath in every item in selected
set aPathString to POSIX path of (aPath as alias)
if paths is "" then
set paths to aPathString
else
set paths to paths & "
" & aPathString
end if
end repeat
end if
if paths is not "" then
set the clipboard to paths as text
end if
end tell
Go to parent folder in Mac OS X Finder
(*
Script: up.app
This script sets the target of the Finder window to the
parent of the current target of the Finder window.
Installation:
1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/up.app
3. Drag and drop up.app onto the Finder widow toolbar.
@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
set target of front window to (parent of target of front window)
end tell
Keep Mac OS X Finder and Terminal in sync
(*
Script: findercd.scpt
This script sets the target of the front window of Finder
to the directory path passed as the first argument. If
there is no Finder window, one is created. Optionally
the finder window can be activated by passing in "true"
as second argument. If no argument is passed
the user is prompted to select a directory
to go to.
The following two bash functions can be used to
invoke this script from bash running in Terminal
window:
# Change the directory of front window of
# Finder to pwd of shell
fcd() {
cd "${1}"
osascript ~/scripts/finder/findercd.scpt "`pwd`" ${2}
}
# Change the directory of front window of
# Finder to pwd of shell and activate the
# Finder window
fcda() {
fcd "${1}" true
}
Installation:
1. Paste this script in Script editor
2. Save it as a script - ~/scripts/finder/findercd.scpt
3. Add the fcd() and fcda() functions mentioned above
to your .bashrc or .bashrc_profile
This script complements the terminalcd.scpt script.
@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
on run argv
if (count of argv) is 0 then
try
set directory to POSIX path of (choose folder with prompt "Go to")
on error
return
end try
else
set directory to (item 1 of argv)
end if
set doActivate to false
if (count of argv) is greater than 1 then
set doActivate to (item 2 of argv)
end if
tell application "Finder"
if (count of windows) is 0 then
make new Finder window
end if
set target of front window to (POSIX file directory)
if doActivate = "true" then
activate
end if
end tell
end run
terminalcd.app
(*
Script: terminalcd.app
This script sets the directory of the shell in front window of Terminal to the
target directory of front window of Finder. If there is no Terminal window
is there a new window is created. If the the front window of
Terminal is busy new window is created.
Installation:
1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/temrinalcd.app
3. Drag and drop terminalcd.app onto the Finder widow toolbar.
This script compliments the findercd.scpt script.
@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
if (count of windows) is greater than 0 then
set cdTo to POSIX path of (target of front window as alias)
set terminalWasRunning to false
tell application "System Events"
if exists process "Terminal" then
set terminalWasRunning to true
end if
end tell
tell application "Terminal"
activate
if (count of windows) is 0 then
do script ""
else if window 1 is busy then
do script ""
end if
do script "cd '" & cdTo & "'" in front window
end tell
end if
end tell
Wednesday, December 17, 2008
Automatically Create Working Sets Eclipse plug-in
Tuesday, December 16, 2008
Smart Semicolon Eclipse plug-in
Sunday, December 07, 2008
Hooking into Eclipse command execution
// Add listener to monitor Cut and Copy commands
ICommandService commandService = (ICommandService) PlatformUI
.getWorkbench().getAdapter(ICommandService.class);
if (commandService != null) {
commandService.addExecutionListener(new IExecutionListener() {
public void notHandled(String commandId,
NotHandledException exception) {
}
public void postExecuteFailure(String commandId,
ExecutionException exception) {
}
public void postExecuteSuccess(String commandId,
Object returnValue) {
// Is it a Cut or Copy command
if ("org.eclipse.ui.edit.copy".equals(commandId)
|| "org.eclipse.ui.edit.cut".equals(commandId)) {
Clipboard clipboard = new Clipboard(PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getShell().getDisplay());
Object contents = clipboard
.getContents(TextTransfer.getInstance());
if (contents instanceof String) {
// Now do something with text selection
}
}
}
public void preExecute(String commandId, ExecutionEvent event) {
}
});
}
Cool huh?
Thursday, November 27, 2008
Graphical cd
gcd() {
local CDTO=`zenity --title="cd" --file-selection --directory`
if [ -n "${CDTO}" ] ; then
cd "${CDTO}"
fi
}
Thursday, November 13, 2008
Zero length Java array cache
The output is:
import java.util.Map;
import java.util.WeakHashMap;
/**
* A simple cache using WeakHashMap of zero length arrays of a given class.
*
* @author schitale
*
*/
public class ZeroLength {
private static Mapmap = new WeakHashMap ();
@SuppressWarnings("unchecked")
public staticT[] array(Class c) {
T[] array = (T[]) map.get(c);
if (array == null) {
array = (T[]) java.lang.reflect.Array.newInstance(c, 0);
map.put(c, array);
}
return array;
}
public static void main(String[] args) {
System.out.println(array(String.class).getClass().getCanonicalName()
+ " of length " + array(String.class).length);
System.out.println(array(String[].class).getClass().getCanonicalName()
+ " of length " + array(String.class).length);
}
}
java.lang.String[] of length 0If you want to rely on the identity of the zero length array instance (e.g. == based comparison) then replace the WeakHashMap with HashMap. However, in that case you have to watch out for memory leaks through static fields of array component classes. You may want to add a method to remove the reference to the array from the HashMap.
java.lang.String[][] of length 0
Is there a better way to do this?
IMHO the java.lang.Class class should provide such factory method. This is along the lines of factory method:
public static final T List T java.util.Collections.emptyList();
The implementation in java.lang.Class may look like:
private static T[] zeroLengthArray;
public static synchronized T[] emptyArray() {
if (zeroLengthArray == null) {
zeroLengthArray = (T[]) java.lang.reflect.Array.newInstance(this, 0);
}
return zeroLengthArray;
}
Thursday, October 23, 2008
Bundles, Extension Points, Extensions View for Eclipse 3.4
- Bundles
- Extensions Points
- Extensions
You can start with any one of these at the top level by using the toolbar settings. You can continue to expand the relationships between these objects to any level.
Several actions are supported in the context menu:
- Open plugin.xml
- Copy extension and extension element trees
- Open Java Type specified by attributes which specify implementing Java classes.
For example, the Copy Extension action copied the following xml to the Clipboard:
Export a file containing the names and locations of the shared projects in the workspace.
I plan to make more enhancements to this view.
You can download it here.
DISCLAIMER: This plug-in is experimental. So no guarantees. Use the plug-in at your own risk.
Tuesday, October 14, 2008
Reclaim Ctrl+C and Ctrl+V for familiar Copy and Paste in gnome-terminal
In this entry I describe how to make Ctrl+C and Ctrl+V do Copy and Paste in gnome-terminals. Here is how to do it:
Open a gnome-terminal window and type the following commands:
Add the following to .bashrc
> stty intr ^K # free Ctrl+C for copy
> stty lnext ^- # free Ctrl+V for paste
> stty -g
> stty -g > ~/.stty # store the settings in home directory
case $- inNow using the gconf-editor, edit the gnome-terminal's key bindings (@ /apps/gnome-terminal/keybindings key).
*i*)
stty `cat ~/.stty` # reload the stored stty settings
bind -u quoted-insert # unbind the quoted-insert function of bash - free Ctrl+V for paste
esac
Close and reopen the terminal window. And now Ctrl+C will copy and Ctrl+V will paste.
Sunday, October 12, 2008
Launching the Open Type dialog
OpenTypeSelectionDialog dialog = new OpenTypeSelectionDialog(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
true,
PlatformUI.getWorkbench().getProgressService(),
null,
IJavaSearchConstants.TYPE);
dialog.setTitle(JavaUIMessages.OpenTypeAction_dialogTitle);
dialog.setMessage(JavaUIMessages.OpenTypeAction_dialogMessage);
dialog.setInitialPattern("java.lang.String");
int result= dialog.open();
if (result != IDialogConstants.OK_ID)
{
return;
}
Object[] types= dialog.getResult();
if (types != null && types.length > 0) {
IType type= null;
for (int i= 0; i < types.length; i++) {
type= (IType) types[i];
try {
JavaUI.openInEditor(type, true, true);
} catch (CoreException x) {
// Handle exception
}
}
}
Enhanced Plug-in Registry View
The Plug-in Registry View has a mode (Show Extension Content only) to show:
- extension-points
- extensions
- extension elements
- extension attributes
This plug-in adds some additional actions on the Plug-in Registry View's tool bar. The following screen shot shows the example of the additional actions.
For attributes with values that look like Java Type name - the Open
This works well if you have added all the plug-in classes to your Java search using the tip - Extending the Java search scope.
The other supported action is:
- Open plugin.xml
You can download the plug-in here.
BTW this plug-in makes use of the technique described in the entry - Add pulldown actions to Eclipse View's Toolbars.
DISCLAIMER: This plug-in is experimental. So no guarantees. Use the plug-in at your own risk.
Sunday, September 28, 2008
Template Tools Eclipse plug-in
Template Tools Eclipse plug-in enhances the functionality of code templates:
- ${clipboard} template variable - replaced by the contents of the clipboard.
- ${prompt(input|file|directory|enumeration, value [, value]*|color|font)}
- input - the user is prompted to enter a value
- file - the user is prompted to select a file
- directory - the user is prompted to select a directory
- enumeration - the user is prompted to select a value from the list of values
- color - the user is prompted to select a color using a color dialog. The color value can be formatted using java.util.Formatter strings. The parameters passed to the format are red, green or blue color component values. If no format is specified the value is formatted as the org.eclipse.swt.graphics.RGB.toString() value of the color.
- font - the user is prompted to select a font using a FontDialog. The returned value is the org.eclipse.swt.graphics.FontData.toString() value returned by the font dialog.
This plug-in also supports extension-point promptProviders.
<extension
point="TemplateTools.promptProviders">
<promptProvider
class="templatetools.InputPrompt"
type="input">
</promptProvider>
:
:
</extension>
Here is the implementation:
package templatetools;
import java.util.Formatter;
import java.util.List;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.ui.PlatformUI;
public class ColorPrompt implements IPrompt {
@SuppressWarnings("unchecked")
public String getValue(String name, List params) {
ColorDialog colorDilaog = new ColorDialog(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell());
RGB color = colorDilaog.open();
if (color != null) {
if (params.size() > 0) {
Object format = params.get(0);
if (format instanceof String) {
StringBuffer formatBuffer = new StringBuffer();
new Formatter(formatBuffer).format((String) format,
color.red, color.green, color.blue);
return formatBuffer.toString();
}
} else {
return color.toString();
}
}
return null;
}
}
You can download the plug-in here.
DISCLAIMER: This plug-in is experimental. So no guarantees. Use the plug-in at your own risk.Monday, September 15, 2008
Reorder Eclipse Plug-in : How does it work?
Basically, the Reorder plug-in uses the AST APIs to get parsed structure of the Java source code surrounding the caret in the Java editor.
- It gets the ASTNode at caret position using NodeFinder API and starts traversing the parent ASTNodes until it find a Class Instance Creation, Method Invocation, Method Declaration or an Array initializer node.
- Once found it gets the ASTNode's list of arguments, parameters or array initialization elements and stores the text of each node in a ordered list of items. While doing so, it also records the intervening white spaces as items.
- It also records which item's extent surrounds the caret position. It records it as a current item.
- Then, it swaps the current item with the following or preceding non-whitespace item in the list based on the action that was invoked - forward or backward swap.
- Lastly it builds the string from the list of items and replaces the original text with the new string.