You have implemented your own graphical editor as a new eclipse plugin.
You are looking for a way to add zoom functions into the graphical
editor. It is very easy!
1. Add the action into the toolbar:
...in Class: ActionBarContributor...
...in Method: contributeToToolBar...
toolBarManager.add(getAction(GEFActionConstants.ZOOM_IN));
toolBarManager.add(getAction(GEFActionConstants.ZOOM_OUT));
toolBarManager.add(new ZoomComboContributionItem(getPage()));
2. Connect the Zoom Manager with your edit part:
...in Class: YourEditor...
...in Method: configureGraphicalViewer...
ScalableFreeformRootEditPart rootEditPart= new ScalableFreeformRootEditPart();
getGraphicalViewer().setRootEditPart(rootEditPart);
ZoomManager manager = rootEditPart.getZoomManager();
IAction action = new ZoomInAction(manager);
getActionRegistry().registerAction(action);
action = new ZoomOutAction(manager);
getActionRegistry().registerAction(action);
//define the zoom possibilities
double[] zoomLevels = new double[] {0.25,0.5,0.75,1.0,1.5,2.0,2.5,3.0,4.0};
manager.setZoomLevels(zoomLevels);
...in Method: getAdapter...
if (type == ZoomManager.class)
return ((ScalableFreeformRootEditPart)
getGraphicalViewer().
getRootEditPart()).getZoomManager();
That's all! Now you have two buttons to zoom in and zoom out. And you
can see the zoom level in percent. With the example here
you can change zoom level from 25% to 400%.
There is an example of creating linked resources in code.
IProject project = workspace.getProject("Project");//assume this exists
IFolder link = project.getFolder("Link");
IPath location = new Path("C:\TEMP\folder");
if (workspace.validateLinkLocation(location).isOK()) {
link.createLink(location, IResource.NONE, null);
} else {
//invalid location, throw an exception or warn user
}
This example will create a linked folder called "Link" that is located at "c:\temp\folder".
link.getFullPath() => "/Project/Link"
link.getLocation() => "c:\temp\folder"
link.getRawLocation() => "temp/folder"
link.isLinked() => "true"
IFile child = link.getFile("abc.txt");
child.create(...);
child.getFullPath() => "/Project/Link/abc.txt"
child.getLocation() => "c:\temp\folder\abc.txt"
child.getRawLocation() => "c:\temp\folder\abc.txt"
child.isLinked() => "false"
Recently I had a problem in converting java.io.File to IFile for
external files. The external files sind the files which are not located
in the eclipse workspace. So they are not eclipse "resources" and can
not be converted into IFile instances. With the following code you can
solve this problem:
IEditorInput input= createEditorInput(selectedFile);
String editorId= getEditorId(selectedFile);
IWorkbenchPage page= fWindow.getActivePage();
try {
page.openEditor(input, editorId);
} catch (PartInitException e) {
//EditorsPlugin.log(e.getStatus());
}
This idea comes from
org.eclipse.ui.internal.editors.text.OpenExternalFileAction. In this
class you can also find the implementation for the methods
"createEditorInput" and "getEditorId".
In JDK 1.4 System.getenv() is deprecated. (In JDK 1.5 it is
un-deprected again.) The getProperty method is now the correspoding
method to get the variables. For example:
System.getProperty("java.class.path",""). But it doesn't work for user
defined environment variable. This problem can be solved by using the
following code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Environment class simulates the System.getenv() method which is deprecated
* on java 1.4.2
*
* @author v-josp
*
*/
public class TestRoot
{
//result of all enviornment variables
private static BufferedReader commandResult;
static
{
String cmd = null;
String os = null;
//getting the OS name
os = System.getProperty("os.name").toLowerCase();
// according to OS set the command to execute
if(os.startsWith("windows"))
{
cmd = "cmd /c SET";
}
else
{
cmd="env";
}
try
{
//execute the command and get the result in the form of InputStream
Process p = Runtime.getRuntime().exec(cmd);
//parse the InputStream data
InputStreamReader isr = new InputStreamReader(p.getInputStream());
commandResult= new BufferedReader(isr);
}
catch (Exception e)
{
System.out.println("OSEnvironment.class error: " + cmd + ":" + e);
}
}
/**
* This method is used to get the path of the given enviornment variable. This
* method tries to simulates the System.getenv() which is deprecated on java 1.4.2
*
* @param String - name of the environment variable
* @param String - default value
* @return
*/
public static String getenv(String envName,String defaultValue)
{
String line = null;
try
{
while ((line = commandResult.readLine()) != null)
{
if(line.indexOf(envName)>-1)
{
return line.substring(line.indexOf(envName)+envName.length()+1);
}
}
return defaultValue;
}
catch (Exception e)
{
return defaultValue;
}
}
public static void main(String args[])
{
System.out.println(TestRoot.getenv("CLASSPATH",""));
}
}
Output
_____
F:\software\javaws-1_2-dev\jnlp.jar;
try {
File currDir = new File (".");
System.out.println("Dir: " + currDir.getCanonicalPath());
}
catch (IOException ex){
//
}