Saturday, February 28, 2009

Apie knygą: Jurga Ivanauskaitė Viršvalandžiai ISBN 978-9986-16-581-1 (www.tytoalba.lt) Tai knyga kuri priverčia susimastyti, įvetinti ir branginti kiekvieną gyvenimo akimirką. Vaistas visiems niurzgantiems dėl dabartinės ekonominės situacijos. Sako: prisminkit, yra ir svarbesnių dalykų už buitį – būtis. Proga prisiminti pačius svarbiausius, rutinos užgoštus, klausimus. Meilė. Meilė gyvenimui. Besalygiška meilė gyvenimui. Drąsa žiūrėti neprisimerkus į mirties akis. Viltis iki pat paskutinės akimirkos. Dėkingumas ir gebėjimas džiauktis gyvenimu! Žmogiškumas iš didžiosios raidės. Suteikta dar viena proga susimastyti kaip mes elgiamės su silpnaisiais. Skaitydamas šią knyga nekartą turėjau sau pripažinti, kad pasidariau per nelyg pragmatiškas, kad nesugebėčiau duoti tiek šilumos ir paguodos nelaimingėms žmonėms. Pamiršau ką reiškia dalintis. Turėjau nubraukti dulkes dar nuo vieno klausimo, kuri patogiai buvau nugrūdes į rutinos užmirštį. Tas klausimas: ar aš tikiu į Jį? Kiekvienas skaitantis šitą knygą neišvengs šio klausimo. Akcija: Aš aplankiau www.wikipedia.org esanti straipsnelį apie Jurgą, labai jau jis skurdus ir mažas, ar tikrai viena iš geriausių Lietuvos rašytojų nusipelno tik tokio paminėjimo? Visų kam ne visvien prašau įdėti į savo puslapi šį linką: nelik abejingas, gerbk ir papildyk Jurgos atminimą! Tikiuosi taip atkreipt dėmesi žmonių kurie galėtų papildyti tą skurdų puslapėlį. Dėkui! Book review: Jurga Ivanauskaitė Viršvalandžiai ISBN 978-9986-16-581-1 (www.tytoalba.lt) It is the book which makes you to take thought and to value every moment of your life. It is a relief for everyone who are worried about the economic crisis. It shows that existence is more important than every-day life. It allows to remember the things that are forgotten in the flow of the routine. Love. Love for Life. True love for life. Courage to look into death without fear. Hope till the very last moment. Thankfulness and joy of life. Real humanness. It gives one more chance to realize how the weak ones feel. While reading this book I had to acknowledge few times that I became too pragmatic and could not care about the unhappy people. I forgot what it means to give. I had to face one more question that was forgotten. Do I believe in Him? Everyone reading this book will face that question.

Thursday, February 26, 2009

Monday, February 23, 2009

c++ stl - vector concatenation (use std::copy or vector::insert)

My friend Saulius showed me a new way of concatenation of two vectors in c++:
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

std::copy(inVec.begin(), inVec.end(), std::back_inserter(outVec));
or:
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

outVec.insert(outVec.end(), inVec.begin(), inVec.end());
Oh, it is simple when you know it but you would never guess if you didn't know! :)

Sunday, February 22, 2009

Lithuania, Kaunas IX Fort and summer

I am posting some of my personal photos here... It is a very interesting object to take a photo of: the old Fort, now it is a museum. It is also very nice to remember the summer, because it is cold outside. :) Enjoy...

Tuesday, February 17, 2009

How to add popup menu to your SWT/JFace TreeViewer

Hi, in your applications main class (that extends ApplicationWindow) in protected Control createContents(Composite parent) method you should add code like this:
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

// Create the popup menu
  MenuManager menuMgr = new MenuManager();
  Menu menu = menuMgr.createContextMenu(mTreeViewer.getControl());
  menuMgr.addMenuListener(new IMenuListener() {
    @Override
    public void menuAboutToShow(IMenuManager manager) {
      if(mTreeViewer.getSelection().isEmpty()) {
        return;
      }
      
      if(mTreeViewer.getSelection() instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection)mTreeViewer.getSelection();
        DatabaseModelObject object = (DatabaseModelObject)selection.getFirstElement();

        if (object.getType() == DATABASE_OBJECT_TYPE.TABLE){
          manager.add(new ShowTableDataAction(SWTApp.this));
        }
      }
    }
  });

  menuMgr.setRemoveAllWhenShown(true);
  mTreeViewer.getControl().setMenu(menu);
DatabaseModelObject - is class from my problem domain (specific to my program). mTreeViewer - is object of TreeViewer class (JFace). Thanks, have a nice day!

Wednesday, February 11, 2009

Lazy tree content provider in SWT/JFace

I'm currently learning JAVA SWT/JFace for my pet project JSQLMaster (I will post more details about that project maybe other time :). So I was doing this project and I thought it would be grate to have lazy tree in my application. I believe this example could be useful for others so I post it here. Add TreeViewer to Application So in your ApplicationWindow you should add your tree viewer:
TreeViewer treeViewer = new TreeViewer(treePanel, SWT.BORDER | SWT.VIRTUAL);
treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 3));
treeViewer.setContentProvider(new DatabaseTreeContentProvider(getDatabase(), this));
treeViewer.setLabelProvider(new DatabaseTreeLabelProvider());
Construct TreeContentProvider Next you should construct your TreeContentProvider:
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

public class DatabaseTreeContentProvider implements ITreeContentProvider {
  
  public DatabaseTreeContentProvider(DatabaseWrapper db, SWTApp w){
    database = db;
    window = w;
  }

  @Override
  public Object[] getChildren(Object parentElement) {
    final DatabaseModelObject obj = (DatabaseModelObject)parentElement;
    
    if (obj.getType() == DATABASE_OBJECT_TYPE.DATABASE){
      if (obj.getChildren().size() == 0){
        List<string> types = database.getTableTypes();
        for(String typeName: types){
          DatabaseModelObject type = new DatabaseModelObject(typeName);
          type.setType(DATABASE_OBJECT_TYPE.TYPE);
          obj.addChild(type);
        }
      }
    } else if (obj.getType() == DATABASE_OBJECT_TYPE.TYPE){
      if (obj.getChildren().size() == 0){
        List<string> tables = database.getTables(obj.getName());
        for(String tableName: tables){
          DatabaseModelObject type = new DatabaseModelObject(tableName);
          type.setType(DATABASE_OBJECT_TYPE.TABLE);
          obj.addChild(type);
        }
      }
    } else if (obj.getType() == DATABASE_OBJECT_TYPE.TABLE){
      if (obj.getChildren().size() == 0){
        List<Map<string, string>> columns = database.getColumns(obj.getName());
        for(Map<string, string> column: columns){
          DatabaseModelObject columnName = new DatabaseModelObject(column.get("COLUMN_NAME"));
          columnName.setType(DATABASE_OBJECT_TYPE.COLUMN);
          obj.addChild(columnName);

          DatabaseModelObject columnType = new DatabaseModelObject(column.get("TYPE_NAME"));
          columnType.setType(DATABASE_OBJECT_TYPE.PROPERTY);
          columnName.addChild(columnType);
        }
      }
      return obj.getChildren().toArray();
    }

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

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

    @Override
    public Object[] getElements(Object inputElement) {
      DatabaseModelObject obj = (DatabaseModelObject)inputElement;
      if (obj.getType() == DATABASE_OBJECT_TYPE.ROOT){
        if (obj.getChildren().size() == 0){
          DatabaseConfiguration dbCfg = database.getDatabaseConfiguration();
          String databaseName = dbCfg.getName();
          databaseName += "[" + dbCfg.getDriver() + "]";
          
          DatabaseModelObject db = new DatabaseModelObject(databaseName);
          db.setType(DATABASE_OBJECT_TYPE.DATABASE);
          obj.addChild(db);
        }
      }
      return obj.getChildren().toArray();
    }

    @Override
    public void dispose() {
    }

    @Override
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    }
    
    final private DatabaseWrapper database;
    final private SWTApp window;
}
Write Domain Model Next you should write your domain model:
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

public class DatabaseModelObject {
 public enum DATABASE_OBJECT_TYPE {NULL, ROOT, DATABASE, TYPE, TABLE, COLUMN, PROPERTY, PRIMARY_KEY, PROCEDURE};
 
 public DatabaseModelObject(String n) {
  name = n;
  children = new ArrayList<DatabaseModelObject>();
  parent = null;
  type = DATABASE_OBJECT_TYPE.NULL;
 }
 
 public String getName() {
  return name;
 }
 
 public String toString() {
  return getName();
 }
 
 public DatabaseModelObject getParent() {
  return parent;
 }
 
 public List getChildren(){
  return children;
 }
 
 public void addChild(DatabaseModelObject child) {
  children.add(child);
  child.setParent(this);
 }
 
 public void setParent(DatabaseModelObject p) {
  parent = p;
 }
 
 public DATABASE_OBJECT_TYPE getType() {
  return type;
 }
 
 public void setType(DATABASE_OBJECT_TYPE t) {
  type = t;
 }
 
 public void removeAllChilds(){
  children.clear();
 }

 private DATABASE_OBJECT_TYPE type;
 private String name = "";
 private List<DatabaseModelObject> children = null;
 private DatabaseModelObject parent = null;
}