ComputingStuff

all about ruby, python, perl, java, computing, network, hacking, security, encryption. and other interesting stuff

Mittwoch, 11. November 2009

cools news

Google new language Go link

coole eclipse code highstyling plugin: link

Dienstag, 10. November 2009

JFace snippets and Images

some information about Eclipse (3.3) images can be found here: shinkarenko.

JFaceSnippets is a collection of code snippets for JFace.

Donnerstag, 5. November 2009

Eclipse RCP Forms part one

Eclipse Forms allow you to achieve the Web look. Eclipse Editors for Manifest files (f.e) are coded in Forms.

tutorials links:
vogella tutorial about forms
forms tutorial 2
forms tutorial 3

Forms use Views:


public class FormView extends ViewPart {
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createForm(parent);
form.setText("Hello, Eclipse Forms");


it create the form where you can set other widgets.

Therefore forms use GridLayot, GridData, Buttons and other similar as SWT.


GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);

layout.numColumns = 2;
GridData gd = new GridData();
gd.horizontalSpan = 2;
link.setLayoutData(gd);
Label label = new Label(form.getBody(), SWT.NULL);
label.setText("Text field label:");
Text text = new Text(form.getBody(), SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button button = new Button(form.getBody(), SWT.CHECK);
button.setText("An example of a checkbox in a form");
gd = new GridData();
gd.horizontalSpan = 2;
button.setLayoutData(gd);



Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.", SWT.WRAP);
link.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
System.out.println("Link activated!");
}
});

create a hyperlink as a HTML hyperlink.


for more information look tutorials

Montag, 2. November 2009

RCP Tree Viewer part 2

here is the continuation of part one.

tutorial to JFace TreeViewer very good details.


At first we change our staticaly views and root objects.
change in ViewPart1 (thus was it called my TreeViewer ViewPart)

private TreeViewer viewer;
private RootNames root;

public RootNames getTreeRoot() {
return root;
}

public TreeViewer getTreeViewer() {
return viewer;
}


now change the create the Command Add and Del and add them to menu. (see Vogella )


public class CommandAdd extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

System.out.println("start");
ViewPart1 view = (ViewPart1) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().findView(ViewPart1.ID);

RootNames root = view.getTreeRoot();

HostsNames hn = new HostsNames("212.40.32.55", "212.40.32.55");
root.addChild(hn);
hn.addChild(new Commandos("syslog", "syslog"));
hn.addChild(new Commandos("top", "top -d 1"));
hn.addChild(new Commandos("network", "network"));

view.getTreeViewer().refresh();
return null;
}
}

public class CommandDel extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

ViewPart1 view = (ViewPart1) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().findView(ViewPart1.ID);

RootNames root = view.getTreeRoot();

HostsNames hn = root.getChildren()[0];

Commandos c = hn.children.get(0);

hn.removeChild(c);

view.getTreeViewer().refresh();
return null;
}

}


Now we create a second View where we simple put some text.

The commands simple add and del some item of tree.

public class OutputView extends ViewPart {
public static final String ID = "zzz.zmytest.Tree.Views.OutputView";
public Text text;

@Override
public void createPartControl(Composite parent) {
text = new Text(parent, SWT.BORDER);
text.setText("Imagine a fantastic user interface here");
}

@Override
public void setFocus() {
}
}

we will simple alter the text.

selection Listener
selection Listener

we implement ISelectionListener:

public class OutputView extends ViewPart implements ISelectionListener{

@Override
public void createPartControl(Composite parent) {
...

getSite().getPage().addSelectionListener((ISelectionListener) this);
}

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
text.setText(selection.toString());
}
}


add the view in the perspective:


public class Perspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);

layout.addStandaloneView(ViewPart1.ID, false, IPageLayout.LEFT, 0.25f, editorArea);
IFolderLayout folder = layout.createFolder("outputs", IPageLayout.TOP, 0.5f, editorArea);
folder.addPlaceholder(OutputView.ID + ":*");
folder.addView(OutputView.ID);

layout.getViewLayout(ViewPart1.ID).setCloseable(false);
}
}


set the tree view to selection provider:

public class ViewPart1 extends ViewPart {
...

public void createPartControl(Composite parent) {
...

// add to selection provider
getSite().setSelectionProvider(viewer);

}


improve the listener:

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj != null) {
if (obj instanceof HostsNames) {
HostsNames hn = (HostsNames)obj;
text.setText("hostname: "+hn.name);
} else if (obj instanceof Commandos) {
Commandos co = (Commandos)obj;
HostsNames hn = co.parent;
text.setText("commando: "+co.name+ " von host: "+hn.name);
}
}
}
}


the listener look for IStructuredSelection, get the object and test the object for our class instances.


Now we can add further views provider and listener without to handle the wired code.s

RCP Tree Viewer

here is some info about JFace TreeViewer.

The Model is worked with MVC


  • Viewer: TreeViewer, LabelProvider

  • Model: Your own model, ContentProvider. The Objects should be Singleton

  • Control: create the Model, change the Model, refresh Viewer



Create a RCP Application (for tutorials see: Vogella).

Add a view: Manifest -> Extensions -> All Extensions -> Add ( views)
give an ID, name and create a class.

At first create the Model. The Model is a tree with root and nodes.

root
\
node
\node
\
node
\node
\node


This example create a tree of hosts an commands for each host.

The root class. This object should be a singleton and have access to hostnames objects.
The hostnames object should have access to commands objects.


RootNames
/ | \
/ | \
host1 host2 host3
/ | \ | \ |
c1 c2 c3 c1 c2 command1


create package: xxx.model

The model package will be have: RootNames, HostsNames and Commands class models.


public class RootNames {
private static RootNames root=null;
public String name;
public ArrayList children;

private RootNames(String name) {
this.name=name;
children = new ArrayList();

}

public static RootNames getRootNames(String name) {
if(root!=null)
return root;
RootNames r = new RootNames(name);
root=r;
return root;
}

public String toString() {
return name;
}
}

RootNames is a singleton, has only a name and children of HostsNames. For simplicity we do the access public. Thus we don't need implement setter or getter.

Then we implement following help methods in RootNames:

public void addChild(HostsNames child) {
children.add(child);
child.parent = this;
}

public void removeChild(HostsNames child) {
children.remove(child);
child.parent = null;
}

public HostsNames[] getChildren() {
return (HostsNames[]) children.toArray(new HostsNames[children.size()]);
}

public boolean hasChildren() {
return children.size()>0;
}

- add/removeChild() add/remove a child in a list and set/unset the parent of child.
- getChildren() return an array of objects of children. Here a HostsNames array.

HostsNames:

public class HostsNames {
public String name;
public String host;
public RootNames parent;
public ArrayList children;

public HostsNames(String name, String host) {
this.name = name;
this.host = host;
children = new ArrayList();
}

public void addChild(Commandos child) {
children.add(child);
child.parent = this;
}

public void removeChild(Commandos child) {
children.remove(child);
child.parent = null;
}

public Commandos[] getChildren() {
return (Commandos[]) children.toArray(new Commandos[children.size()]);
}

public boolean hasChildren() {
return children.size()>0;
}

public String toString() {
return name;
}
}


HostsNames: have a name, hostname, parent to root and children of Commandos. And helpers for Children.

Commandos:

public class Commandos {
public String name;
public String commando;
public HostsNames parent;

public Commandos(String name, String commando) {
this.name = name;
this.commando = commando;
}

public String toString() {
return name;
}
}

Commandos have name, commando and reference to HostsNames via parent.


Implement Provider:

create package xxx.provider


public class ViewLabelProvider extends LabelProvider {

public String getText(Object obj) {
return obj.toString();
}

public Image getImage(Object obj) {
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
if (obj instanceof HostsNames)
imageKey = ISharedImages.IMG_OBJ_FOLDER;
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}
}

The Label Provider is a View in MVC. it give the name and the image of the Tree back, based on model.

Create a View Content Provider with implemented Interfaces: IStructuredContentProvider and ITreeContentProvider.


public class ViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {

@Override
public Object[] getElements(Object inputElement) {
return null;
}

@Override
public void dispose() {
}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}

@Override
public Object[] getChildren(Object parentElement) {
return null;
}

@Override
public Object getParent(Object element) {
return null;
}

@Override
public boolean hasChildren(Object element) {
return false;
}
}


The Content Provider is the model part of MVC. It provide how the TreeViewer can access the model.
following methods must be implemented: getElements(), getParent(), getChildren(), hasChildren().

Implementation:

@Override
public Object[] getElements(Object parent) {
return getChildren(parent);
}
@Override
public Object[] getChildren(Object parent) {
if (parent instanceof RootNames) {
return ((RootNames)parent).getChildren();
}
if (parent instanceof HostsNames) {
return ((HostsNames)parent).getChildren();
}
return new Object[0];
}

@Override
public Object getParent(Object child) {
if (child instanceof HostsNames) {
return ((HostsNames)child).parent;
}
if (child instanceof Commandos) {
return ((Commandos)child).parent;
}
return null;
}

@Override
public boolean hasChildren(Object element) {
if (element instanceof RootNames)
return ((RootNames)element).hasChildren();
if (element instanceof HostsNames)
return ((HostsNames)element).hasChildren();
return false;
}

getElements and getChildren is here the same.

getChildren() return for RootNames or HostsNames his children list as an array. The same is do getParent() and hasChildren().


Now set the ViewPart:

private TreeViewer viewer;
private RootNames root;

@Override
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
root=ModelCreator.createModel();
viewer.setInput(root);
}

Create the TreeViewer.
Set our Content and Label Provider. Call the Model Creator.

ModelCreator:

public class ModelCreator {

public static RootNames createModel() {
RootNames root = RootNames.getRootNames("root");

HostsNames hn = new HostsNames("localhost", "localhost");
root.addChild(hn);
hn.addChild(new Commandos("syslog", "syslog"));
hn.addChild(new Commandos("top", "top -d 1"));

hn = new HostsNames("134.108.68.107", "134.108.68.107");
root.addChild(hn);
hn.addChild(new Commandos("syslog", "syslog"));
hn.addChild(new Commandos("top", "top -d 1"));

return root;
}
}

createModel() create a root with two hostnames and his commandos.

Then we must set the view in perspective

String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);

layout.addStandaloneView(ViewPart1.ID, false, IPageLayout.LEFT, 0.95f, editorArea);

layout.getViewLayout(ViewPart1.ID).setCloseable(false);


to add some context to the tree (here an example with a Command:

public class CommandAdd extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("blub");
RootNames root = ViewPart1.getTreeRoot();
System.out.println("blub: "+root);

HostsNames hn = new HostsNames("212.40.32.55", "212.40.32.55");
root.addChild(hn);
hn.addChild(new Commandos("syslog", "syslog"));
hn.addChild(new Commandos("top", "top -d 1"));
hn.addChild(new Commandos("network", "network"));

ViewPart1.getTreeViewer().refresh();

return null;
}
}


simple get the singleton and add some childs. Then refresh the view.

Mittwoch, 14. Oktober 2009

OSGi book summary part one

Summary for book "Die OSGI Service Platform-Eine Einführung mit Eclipse Equinox" link

The book is a good introduction to OSGi. It has 24 chapters, from OSGi introduction to OSGi and Equinox Standard Services. The book is divided in three part: part one: OSGi Framework, part two: OSGi Standard Services, part three: Equinox Services(Extensions)

Following chapters are discused in first part:
Bundles, Bundles lifcycles, Packages dependencies, OSGi Services, dynamic Services, Fragment Bundles, Security, Management of OSGi Service Platform, Packaging and Deployment


this blog summary the summary of the book:

* how to install Eclipse PDE (download eclipse-equinox-SDK-3.xxxx.zip)

* describe how OSGi work: bundles, layers, lifecycles, deployment, services, avaiable implementations(felix, equinox), example to start a http game services.


* Bundle Manifest have descriptive information about bundles, the manifest will be readed and interpreted by OSGi platform.
* Bundle-Classpath have locale paths
* Bundle-Activator is the start and stop point of a bundle with org.osgi.framework.BundleActivator
* BundleContext (parameter on start()/stop()), allow access to OSGi framework. Through context you can install new bundles, register listener, register and ask for services.

* Equinox console is a simpler Management Agent. You can ask for state of bundles and OSGi environment. A bundle has different states (installed, uninstalled, running, stoped)
* Activator Policies can change the behavior of bundles starts. (time, sequence, ressources). Lazy Activator set the bundle only start if other required him.
* It exists change of states with code too. (not only manifest-file)
* Bundle listener can notify you about state changes. Listener are registered with BundleContext.
* Bundle Cache save the states for persistence beyound the start()/stop() borders.

* For using other bundles you must explizit import/export you bundles in manifest-file.
* That is done with Export-Package and Import-Package labels.
* Required-Bundle specific the whole bundle. Import-Package only classes/packages. '*' import all class in a package.
* With Versioning you can specify which version of a same bundle the other bundle should use.
* With DynamicImport-Package you can import packages which doesn't exists yet.

* OSGi services are simple java objects (POJO Plain Old Java Objects). The services are registered to Service Registry with theirs class names. The services could quered by other bundles.
* The access to Services happen with ServiceReference and BundleContext
* On registry you can send some properties (which is a simple hash map)
* To get a reference: BundleContext.getServiceReferences() and the class name of service. Then you can use filter.
* With start leveln you can affect the start sequence of bundles.

* Sercice Tracker help you to work with one interface, independent from runtime/lifecycle. Tracker help dynamic react to services in/outgoing.
* ServiceTrackerCustomizer help you to react to different changes with call-back methods.
* Central OSGi Service Registry is the Whiteboard-Pattern and allow simple way the traditional listener-patern to replace.

* Fragments bundles expand the classpath of others bundles ( to avoid overloading of code/info for one bundle). It is a simple way to divide logic part from presentation(templates, languages).
* Fragmenst have no lifecycles (no Activators). manifest: Fragment-Host
* The Import/Export/Requirement information from Fragment Bundle will transfer to Host Bundle (which use the Fragment Bundle)
* Extension Bundles you can change the boot-classpath and expand it with additional features.

* Security in OSGi: local access can be setted to avoid execution in OSGI-INF/permissions.perm
* You can run only signed bundles or with certificates
* Conditional Permission Admin Service asign global authorization (Conditions)

* Management Agent implement an access to OSGi framework. For administrate framework from outside.
* It can be done by shell. or with programmatic.
* You can code your own commands with implement a CommandProvider with org.eclipse.osgi.framework.console.CommandProvider and register it to OSGi Service Registry.

* Plug-in Export Wizard is a simple facility to build bundles for extern world (and not only work with eclipse)
* For automatic build: ant4eclipse, Maven
* To start Eclipse Equinox: use org.eclipse.osgi_version.jar. Or start org.eclipse.core.runtime.adapptor.EclipseStarter from an Java application.
* With System properties or config.ini you can manipulate Equinox

Dienstag, 13. Oktober 2009

Scala test

http://www.scalatest.org/getting_started_with_feature_spec

Leser

Über mich

Mein Foto
Iknofkosremnadteiker
Dipl Ing (FH) techn. Informatik zukunftig MSc Distributed System
Mein Profil vollständig anzeigen
http://nevstokes.com/includes/syntax/scripts/shBrushPerl.js