Example usage for java.awt Panel Panel

List of usage examples for java.awt Panel Panel

Introduction

In this page you can find the example usage for java.awt Panel Panel.

Prototype

public Panel(LayoutManager layout) 

Source Link

Document

Creates a new panel with the specified layout manager.

Usage

From source file:edu.harvard.i2b2.query.ui.QueryC.java

/**
 * @param args/*www.  j  av  a2 s .  c  om*/
 */
protected Control createContents(Composite parent) {
    // log.info("Starting Query Mode");
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    setLayout(topGridLayout);

    Composite queryComposite = new Composite(this, SWT.NONE);
    queryComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    queryComposite.setLayoutData(gridData2);

    // the horizontal sash form
    SashForm horizontalForm = new SashForm(queryComposite, SWT.HORIZONTAL);
    horizontalForm.setOrientation(SWT.HORIZONTAL);
    horizontalForm.setLayout(new GridLayout());

    // left sash form
    SashForm leftVerticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    leftVerticalForm.setOrientation(SWT.VERTICAL);
    leftVerticalForm.setLayout(new GridLayout());

    if (bWantStatusLine) {
        slm.createControl(this, SWT.NULL);
    }
    slm.setMessage("i2b2 Explorer Version 1.6.0");
    slm.update(true);

    // Create the tab folder
    final TabFolder oTabFolder = new TabFolder(leftVerticalForm, SWT.NONE);

    // Create each tab and set its text, tool tip text,
    // image, and control
    TabItem oTreeTab = new TabItem(oTabFolder, SWT.NONE);
    oTreeTab.setText("Concept trees");
    oTreeTab.setToolTipText("Hierarchically organized patient characteristics");
    oTreeTab.setControl(getQueryTabControl(oTabFolder));

    // TabItem oFindTab = new TabItem(oTabFolder, SWT.NONE);
    // oFindTab.setText("Find");
    // oFindTab.setToolTipText(
    // "Free-form find tool for patient characteristics");
    // FindTool find = new FindTool(slm);

    // oFindTab.setControl(find.getFindTabControl(oTabFolder));

    // Select the first tab (index is zero-based)
    oTabFolder.setSelection(0);

    // Create the tab folder
    final TabFolder queryRunFolder = new TabFolder(leftVerticalForm, SWT.NONE);

    TabItem previousRunTab = new TabItem(queryRunFolder, SWT.NONE);
    previousRunTab.setText("Patient Sets and Previous Queries");
    previousRunTab.setToolTipText("Patient Sets & Previous Queries");
    final Composite composite = new Composite(queryRunFolder, SWT.EMBEDDED);
    previousRunTab.setControl(composite);

    /* Create and setting up frame */
    Frame runFrame = SWT_AWT.new_Frame(composite);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    oAwtContainer_left = runRoot.getContentPane();

    // runTreePanel = new QueryPreviousRunsPanel(this, null);
    // oAwtContainer_left.add(runTreePanel);

    // Select the first tab (index is zero-based)
    queryRunFolder.setSelection(0);

    final SashForm verticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    verticalForm.setOrientation(SWT.VERTICAL);
    verticalForm.setLayout(null);

    Composite rightComp = new Composite(verticalForm, SWT.BORDER | SWT.EMBEDDED | SWT.DragDetect);
    /* Create and setting up frame */
    Frame frame = SWT_AWT.new_Frame(rightComp);
    Panel panel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    oAwtContainer = root.getContentPane();

    if (mode_ == 0) {
        queryToolPanel = new QueryToolInvestigatorPanel(this);
    } else {
        queryToolPanel = new QueryToolPanel(this);
    }

    oAwtContainer.add(queryToolPanel);
    queryToolPanel.setSplitBounds(oAwtContainer.getBounds());

    if (mode_ == 0) {
        // bottomC = new ExplorerC(verticalForm, false);
        verticalForm.setWeights(new int[] { 40, 50 });
    }
    verticalForm.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            if (mode_ == 0) {
                int height = verticalForm.getBounds().height;
                // System.out.println("Height: "+height);
                if (height > 285) {
                    try {
                        verticalForm.setWeights(new int[] { 285, height - 285 });
                    } catch (Exception e) {
                        return;
                    }
                }
            }
        }
    });

    horizontalForm.setWeights(new int[] { 20, 70 });
    return parent;
}

From source file:edu.harvard.i2b2.previousquery.QueryC.java

/**
 * @param args/*  www .j  a v  a2  s  .co m*/
 */
protected Control createContents(Composite parent) {
    //log.info("Starting Query Mode");
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    setLayout(topGridLayout);

    Composite queryComposite = new Composite(this, SWT.NONE);
    queryComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    queryComposite.setLayoutData(gridData2);

    // the horizontal sash form
    SashForm horizontalForm = new SashForm(queryComposite, SWT.HORIZONTAL);
    horizontalForm.setOrientation(SWT.HORIZONTAL);
    horizontalForm.setLayout(new GridLayout());

    //left sash form
    SashForm leftVerticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    leftVerticalForm.setOrientation(SWT.VERTICAL);
    leftVerticalForm.setLayout(new GridLayout());

    if (bWantStatusLine) {
        slm.createControl(this, SWT.NULL);
    }
    slm.setMessage("i2b2 Explorer Version 2.0");
    slm.update(true);

    // Create the tab folder
    final TabFolder oTabFolder = new TabFolder(leftVerticalForm, SWT.NONE);

    // Create each tab and set its text, tool tip text,
    // image, and control
    TabItem oTreeTab = new TabItem(oTabFolder, SWT.NONE);
    oTreeTab.setText("Concept trees");
    oTreeTab.setToolTipText("Hierarchically organized patient characteristics");
    oTreeTab.setControl(getQueryTabControl(oTabFolder));

    TabItem oFindTab = new TabItem(oTabFolder, SWT.NONE);
    oFindTab.setText("Find");
    oFindTab.setToolTipText("Free-form find tool for patient characteristics");
    //FindTool find = new FindTool(slm);

    //oFindTab.setControl(find.getFindTabControl(oTabFolder));

    // Select the first tab (index is zero-based)
    oTabFolder.setSelection(0);

    // Create the tab folder
    final TabFolder queryRunFolder = new TabFolder(leftVerticalForm, SWT.NONE);

    TabItem previousRunTab = new TabItem(queryRunFolder, SWT.NONE);
    previousRunTab.setText("Patient Sets and Previous Queries");
    previousRunTab.setToolTipText("Patient Sets & Previous Queries");
    final Composite composite = new Composite(queryRunFolder, SWT.EMBEDDED);
    previousRunTab.setControl(composite);

    /* Create and setting up frame */
    Frame runFrame = SWT_AWT.new_Frame(composite);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    oAwtContainer_left = runRoot.getContentPane();

    runTreePanel = new QueryPreviousRunsPanel(this);//, null);
    oAwtContainer_left.add(runTreePanel);

    // Select the first tab (index is zero-based)
    queryRunFolder.setSelection(0);

    final SashForm verticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    verticalForm.setOrientation(SWT.VERTICAL);
    verticalForm.setLayout(null);

    Composite rightComp = new Composite(verticalForm, SWT.BORDER | SWT.EMBEDDED | SWT.DragDetect);
    /* Create and setting up frame */
    Frame frame = SWT_AWT.new_Frame(rightComp);
    Panel panel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    oAwtContainer = root.getContentPane();

    if (mode_ == 0) {
        //queryPanel = new QueryPanelInvestigator(this);
    } else {
        queryPanel = new QueryPanel(this);
    }

    oAwtContainer.add(queryPanel);
    queryPanel.setSplitBounds(oAwtContainer.getBounds());

    if (mode_ == 0) {
        //bottomC = new ExplorerC(verticalForm, false);
        verticalForm.setWeights(new int[] { 40, 50 });
    }
    verticalForm.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            if (mode_ == 0) {
                int height = verticalForm.getBounds().height;
                //System.out.println("Height: "+height);
                if (height > 285) {
                    try {
                        verticalForm.setWeights(new int[] { 285, height - 285 });
                    } catch (Exception e) {
                        return;
                    }
                }
            }
        }
    });

    horizontalForm.setWeights(new int[] { 20, 70 });
    return parent;
}

From source file:com.microsoft.tfs.client.common.ui.controls.generic.CompatibleBrowser.java

public CompatibleBrowser(final Composite parent, final int style) {
    super(parent, style);

    Check.notNull(parent, "parent"); //$NON-NLS-1$

    final GridLayout gridLayout = new GridLayout(1, true);
    gridLayout.marginHeight = 0;/* www.  ja  va2s .c  o m*/
    gridLayout.marginWidth = 0;

    setLayout(gridLayout);

    if (isNativeBrowserAvailable()) {
        log.info(MessageFormat.format("{0} using SWT Browser", CompatibleBrowser.class.getName())); //$NON-NLS-1$

        final GridData gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessVerticalSpace = true;
        gd.verticalAlignment = SWT.FILL;

        browser = new Browser(this, style);
        browser.setLayoutData(gd);

        editorPane = null;
    } else {
        log.info(MessageFormat.format("{0} using JEditorPane", CompatibleBrowser.class.getName())); //$NON-NLS-1$

        browser = null;

        JEditorPane tempEditorPane = null;
        CompatibilityLinkControl tempErrorLabel = null;

        /*
         * Embedded AWT widgets must be in a Composite with SWT.EMBEDDED
         * set, so create one.
         */
        final Composite embeddableComposite = new Composite(this, SWT.EMBEDDED);

        final GridData compositeGridData = new GridData();
        compositeGridData.grabExcessHorizontalSpace = true;
        compositeGridData.horizontalAlignment = SWT.FILL;
        compositeGridData.grabExcessVerticalSpace = true;
        compositeGridData.verticalAlignment = SWT.FILL;

        embeddableComposite.setLayoutData(compositeGridData);

        /*
         * We have to skip trying AWT entirely some places.
         */
        boolean loadedAWTBrowser = false;
        if (CompatibleBrowser.isAWTDangerousHere() == false) {
            try {
                /*
                 * Create a Frame in the SWT Composite as the top-level
                 * element.
                 */
                final Frame browserFrame = SWT_AWT.new_Frame(embeddableComposite);

                /*
                 * Create a panel with a simple BorderLayout to hold
                 * contents.
                 */
                final Panel panel = new Panel(new BorderLayout());
                browserFrame.add(panel);

                /*
                 * Create an JEditorPane with an HTML document.
                 */
                final String pageContents = "<html><body></body></html>"; //$NON-NLS-1$
                tempEditorPane = new JEditorPane("text/html", pageContents); //$NON-NLS-1$
                tempEditorPane.setEditable(false);

                /*
                 * Put the HTML viewer in a scroll pane and parent the
                 * scroll pane in the panel.
                 */
                final JScrollPane scrollPane = new JScrollPane(tempEditorPane);
                panel.add(scrollPane);

                loadedAWTBrowser = true;
            } catch (final Throwable t) {
                log.warn("Error embedding AWT frame for JEditorPane", t); //$NON-NLS-1$
            }
        }

        if (loadedAWTBrowser == false) {
            /*
             * We don't need the embeddable composite because AWT embedding
             * failed, and we can't put normal (error label) things in it,
             * so hide it.
             */
            compositeGridData.widthHint = 0;
            compositeGridData.heightHint = 0;

            tempErrorLabel = CompatibilityLinkFactory.createLink(this, SWT.NONE);

            tempErrorLabel.setText(
                    MessageFormat.format(Messages.getString("CompatibleBrowser.CouldNotLoadSWTBrowserFormat"), //$NON-NLS-1$
                            AWT_TOOLKIT_ENV_VAR_NAME, XTOOLKIT_ENV_VAR_VALUE));

            final GridData labelGridData = new GridData();
            labelGridData.grabExcessHorizontalSpace = true;
            labelGridData.horizontalAlignment = SWT.FILL;
            labelGridData.grabExcessVerticalSpace = true;
            labelGridData.verticalAlignment = SWT.FILL;

            tempErrorLabel.getControl().setLayoutData(labelGridData);
        }

        editorPane = tempEditorPane;
    }
}

From source file:Sampler.java

private void createUI() {
    setFont(new Font("Serif", Font.PLAIN, 12));
    setLayout(new BorderLayout());
    // Set our location to the left of the image frame.
    setSize(200, 350);//from   ww  w  . j  av  a 2s.com
    Point pt = mImageFrame.getLocation();
    setLocation(pt.x - getSize().width, pt.y);

    final Checkbox accumulateCheckbox = new Checkbox("Accumulate", false);
    final Label statusLabel = new Label("");

    // Make a sorted list of the operators.
    Enumeration e = mOps.keys();
    Vector names = new Vector();
    while (e.hasMoreElements())
        names.addElement(e.nextElement());
    Collections.sort(names);
    final java.awt.List list = new java.awt.List();
    for (int i = 0; i < names.size(); i++)
        list.add((String) names.elementAt(i));
    add(list, BorderLayout.CENTER);

    // When an item is selected, do the corresponding transformation.
    list.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ie) {
            if (ie.getStateChange() != ItemEvent.SELECTED)
                return;
            String key = list.getSelectedItem();
            BufferedImageOp op = (BufferedImageOp) mOps.get(key);
            BufferedImage source = mSplitImageComponent.getSecondImage();
            boolean accumulate = accumulateCheckbox.getState();
            if (source == null || accumulate == false)
                source = mSplitImageComponent.getImage();
            String previous = mImageFrame.getTitle() + " + ";
            if (accumulate == false)
                previous = "";
            mImageFrame.setTitle(previous + key);
            statusLabel.setText("Performing " + key + "...");
            list.setEnabled(false);
            accumulateCheckbox.setEnabled(false);
            BufferedImage destination = op.filter(source, null);
            mSplitImageComponent.setSecondImage(destination);
            mSplitImageComponent.setSize(mSplitImageComponent.getPreferredSize());
            mImageFrame.setSize(mImageFrame.getPreferredSize());
            list.setEnabled(true);
            accumulateCheckbox.setEnabled(true);
            statusLabel.setText("Performing " + key + "...done.");
        }
    });

    Button loadButton = new Button("Load...");
    loadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            FileDialog fd = new FileDialog(Sampler.this);
            fd.show();
            if (fd.getFile() == null)
                return;
            String path = fd.getDirectory() + fd.getFile();
            mSplitImageComponent.setImage(path);
            mSplitImageComponent.setSecondImage(null);
            //            Utilities.sizeContainerToComponent(mImageFrame,
            //               mSplitImageComponent);
            mImageFrame.validate();
            mImageFrame.repaint();
        }
    });

    Panel bottom = new Panel(new GridLayout(2, 1));
    Panel topBottom = new Panel();
    topBottom.add(accumulateCheckbox);
    topBottom.add(loadButton);
    bottom.add(topBottom);
    bottom.add(statusLabel);
    add(bottom, BorderLayout.SOUTH);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            mImageFrame.dispose();
            dispose();
            System.exit(0);
        }
    });
}

From source file:org.geoserver.wms.WMSTestSupport.java

/**
 * Shows <code>image</code> in a Frame.
 * /*from  w  ww .  j ava  2  s. c  om*/
 * @param frameName
 * @param timeOut
 * @param image
 */
public static void showImage(String frameName, long timeOut, final BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    if (((System.getProperty("java.awt.headless") == null)
            || !System.getProperty("java.awt.headless").equals("true")) && INTERACTIVE) {
        Frame frame = new Frame(frameName);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        Panel p = new Panel(null) { // no layout manager so it respects
                                    // setSize
            public void paint(Graphics g) {
                g.drawImage(image, 0, 0, this);
            }
        };

        frame.add(p);
        p.setSize(width, height);
        frame.pack();
        frame.setVisible(true);

        try {
            Thread.sleep(timeOut);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        frame.dispose();
    }
}

From source file:edu.harvard.i2b2.analysis.ui.ExplorerC.java

/**
 * @param args/* www  .ja  v a2 s.c o  m*/
 */
@SuppressWarnings("serial")
protected Control createContents(Composite parent) {
    log.info("Explorer plugin version 1.6.0");
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    setLayout(topGridLayout);

    Composite oTreeComposite = new Composite(this, SWT.NONE);
    oTreeComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    oTreeComposite.setLayoutData(gridData2);

    // the horizontal sash form
    SashForm horizontalForm = new SashForm(oTreeComposite, SWT.HORIZONTAL);
    horizontalForm.setOrientation(SWT.HORIZONTAL);
    horizontalForm.setLayout(new GridLayout());

    if (drawLeft) {
        // left sash form
        SashForm leftVerticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
        leftVerticalForm.setOrientation(SWT.VERTICAL);
        leftVerticalForm.setLayout(new GridLayout());

        if (bWantStatusLine) {
            slm.createControl(this, SWT.NULL);
        }
        slm.setMessage("i2b2 Explorer Version 2.0");
        slm.update(true);

        // Create the tab folder
        final TabFolder oTabFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        // Create each tab and set its text, tool tip text,
        // image, and control
        TabItem oTreeTab = new TabItem(oTabFolder, SWT.NONE);
        oTreeTab.setText("Concept trees");
        oTreeTab.setToolTipText("Hierarchically organized patient characteristics");
        oTreeTab.setControl(getConceptTreeTabControl(oTabFolder));

        // Select the first tab (index is zero-based)
        oTabFolder.setSelection(0);

        // Create the tab folder
        final TabFolder queryRunFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        TabItem previousRunTab = new TabItem(queryRunFolder, SWT.NONE);
        previousRunTab.setText("Patient Sets and Previous Queries");
        previousRunTab.setToolTipText("Patient Sets & Previous Queries");
        final Composite runComposite = new Composite(queryRunFolder, SWT.EMBEDDED);
        previousRunTab.setControl(runComposite);

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame runFrame = SWT_AWT.new_Frame(runComposite);
        Panel runPanel = new Panel(new BorderLayout());
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        runFrame.add(runPanel);
        JRootPane runRoot = new JRootPane();
        runPanel.add(runRoot);

        // Select the first tab (index is zero-based)
        queryRunFolder.setSelection(0);
    }

    SashForm verticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    verticalForm.setOrientation(SWT.VERTICAL);
    verticalForm.setLayout(new GridLayout());

    // put a tab folder in it...
    tabFolder = new TabFolder(verticalForm, SWT.NONE);

    Composite patientNumsComposite = new Composite(verticalForm, SWT.NONE);
    GridData patientNumData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    patientNumData.grabExcessHorizontalSpace = true;
    patientNumsComposite.setLayoutData(patientNumData);
    patientNumsComposite.setLayout(null);

    Label patientset = new Label(patientNumsComposite, SWT.NONE);
    patientset.setText("Patient Set: ");
    patientset.setBounds(5, 9, 60, 22);

    patientSetText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientSetText.setText("");
    // patientSetText.setEditable(false);
    patientSetText.setBounds(70, 5, 300, 35);

    leftArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    leftArrowButton.setText("<<<");
    leftArrowButton.setEnabled(false);
    leftArrowButton.setBounds(380, 5, 38, 22);
    leftArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            int start = new Integer(patientMinNumText.getText()).intValue();
            int inc = new Integer(patientMaxNumText.getText()).intValue();
            if (start - inc - inc <= 0) {
                leftArrowButton.setEnabled(false);
            }

            if (start <= patientSetSize) {
                rightArrowButton.setEnabled(true);
            } else {
                rightArrowButton.setEnabled(false);
            }

            if ((start - inc) >= 0) {
                patientMinNumText.setText("" + (start - inc));
            } else {
                patientMinNumText.setText("1");
            }

            if (tabFolder.getSelectionIndex() == 1) {
                DestroyMiniVisualization(oAwtContainer);
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                PerformVisualizationQuery(oAwtContainer, patientRefId, min, max, bDisplayAllData);
            }
        }
    });

    final Label patNum1 = new Label(patientNumsComposite, SWT.NONE);
    patNum1.setText(" start: ");
    patNum1.setBounds(425, 9, 31, 20);

    patientMinNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMinNumText.setText("1");
    patientMinNumText.setBounds(460, 5, 45, 22);

    final Label patNum2 = new Label(patientNumsComposite, SWT.NONE);
    patNum2.setText("increment:");
    patNum2.setBounds(515, 9, 57, 20);

    patientMaxNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMaxNumText.setText("10");
    patientMaxNumText.setBounds(572, 5, 45, 22);

    rightArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    rightArrowButton.setText(">>>");
    rightArrowButton.setEnabled(false);
    rightArrowButton.setBounds(626, 5, 38, 20);
    rightArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            int start = new Integer(patientMinNumText.getText()).intValue();
            int inc = new Integer(patientMaxNumText.getText()).intValue();
            if (start + inc + inc > patientSetSize) {
                rightArrowButton.setEnabled(false);
            }
            patientMinNumText.setText("" + (start + inc));
            leftArrowButton.setEnabled(true);

            if (tabFolder.getSelectionIndex() == 1) {
                DestroyMiniVisualization(oAwtContainer);
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                PerformVisualizationQuery(oAwtContainer, patientRefId, min, max, bDisplayAllData);
            }
        }
    });

    addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int w = getBounds().width;
            patientSetText.setBounds(70, 5, w - 357, 24);
            leftArrowButton.setBounds(w - 281, 5, 38, 24);
            patNum1.setBounds(w - 239, 9, 31, 24);
            patientMinNumText.setBounds(w - 204, 5, 45, 24);
            patNum2.setBounds(w - 149, 9, 57, 24);
            patientMaxNumText.setBounds(w - 92, 5, 45, 24);
            rightArrowButton.setBounds(w - 42, 5, 37, 24);
        }
    });

    verticalForm.setWeights(new int[] { 25, 3 });

    // Item 1: a Text Table
    TabItem item1 = new TabItem(tabFolder, SWT.NONE);
    item1.setText("Create model for Timeline");

    Composite oModelComposite = new Composite(tabFolder, SWT.NONE);
    item1.setControl(oModelComposite);

    GridLayout gridLayout = new GridLayout(2, false);

    // gridLayout.marginHeight = 0;
    // gridLayout.marginWidth = 0;
    // gridLayout.verticalSpacing = 0;
    // gridLayout.horizontalSpacing = 0;

    gridLayout.marginTop = 2;
    gridLayout.marginLeft = 0;
    gridLayout.marginBottom = 2;
    gridLayout.verticalSpacing = 1;
    gridLayout.horizontalSpacing = 1;
    oModelComposite.setLayout(gridLayout);

    oModelQueryComposite = new FramedComposite(oModelComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelQueryComposite.setLayout(new GridLayout(25, false));
    oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    GridData oModelQueryButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelQueryButtonGridData.grabExcessHorizontalSpace = false;
    oModelQueryButtonGridData.horizontalSpan = 2;
    oModelQueryButtonGridData.verticalAlignment = SWT.CENTER;
    oModelQueryButtonGridData.verticalIndent = 5;
    oModelQueryComposite.setLayoutData(oModelQueryButtonGridData);

    queryNamemrnlistText = new Label(oModelQueryComposite, SWT.NONE);
    queryNamemrnlistText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    queryNamemrnlistText.setText("Query Name: ");
    // queryNamemrnlistText.setBounds(5, 4, 600, 20);

    queryNamemrnlistText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    oModelQueryComposite.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent arg0) {
            // System.out.println("mouse moved");

        }

    });

    oModelQueryComposite.addDragDetectListener(new DragDetectListener() {

        public void dragDetected(DragDetectEvent arg0) {
            // System.out.println("drag moved");

        }

    });

    Composite oGroupComposite = new Composite(oModelComposite, SWT.NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oGroupComposite.setLayout(gridLayout);
    GridData oGroupGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    oGroupGridData.grabExcessHorizontalSpace = true;
    oGroupGridData.grabExcessVerticalSpace = true;
    oGroupGridData.verticalIndent = 1;
    oGroupGridData.verticalSpan = GridData.VERTICAL_ALIGN_FILL;
    // oGroupGridData.verticalAlignment = GridData.VERTICAL_ALIGN_FILL;
    oGroupComposite.setLayoutData(oGroupGridData);

    oModelGroupComposite = new FramedComposite(oGroupComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelGroupComposite.setLayout(new GridLayout(25, false));
    GridData oModelGroupButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelGroupButtonGridData.grabExcessHorizontalSpace = false;
    oModelGroupButtonGridData.horizontalSpan = 2;
    oModelGroupButtonGridData.verticalAlignment = SWT.CENTER;
    oModelGroupButtonGridData.verticalIndent = 5;
    oModelGroupComposite.setLayoutData(oModelGroupButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel1 = new GridData(GridData.FILL_HORIZONTAL);

    groupNameText = new Label(oModelGroupComposite, SWT.NONE);
    gdDel1.horizontalSpan = 4;
    groupNameText.setLayoutData(gdDel1);
    groupNameText.setText("Panel Name: ");
    // groupNameText.setBounds(80, 8, 400, 24);
    // groupNameText.setAlignment(SWT.CENTER);
    // createDragSource(queryNamemrnlistText);
    // createDropTarget(queryNamemrnlistText);

    groupNameText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    // put a table in tabItem1...
    table = new KTable(oGroupComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    table.setFocus();
    table.setBackground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGridData.verticalIndent = 5;
    table.setLayoutData(tableGridData);
    table.setRowSelectionMode(true);
    // table.setMultiSelectionMode(true);
    // table.setModel(new KTableForModel());
    table.setModel(new ConceptTableModel());
    // table.getModel().setColumnWidth(0, oModelComposite.getBounds().width
    // - 35);
    table.addCellSelectionListener(new KTableCellSelectionListener() {
        public void cellSelected(int col, int row, int statemask) {
            log.debug("Cell [" + col + ";" + row + "] selected.");
            System.out.println("Cell [" + col + ";" + row + "] selected.");
            table.selectedRow = row;
            table.selectedColumn = col;
        }

        public void fixedCellSelected(int col, int row, int statemask) {
            log.debug("Header [" + col + ";" + row + "] selected.");
            System.out.println("Header [" + col + ";" + row + "] selected.");
        }

    });

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

    // create drag source
    /*
     * DragSource source = new DragSource(queryNamemrnlistText,
     * DND.DROP_COPY); source.setTransfer(types); source.addDragListener(new
     * DragSourceAdapter() {
     * 
     * @Override public void dragSetData(DragSourceEvent event) {
     * //DragSource ds = (DragSource) event.widget; StringWriter strWriter =
     * new StringWriter(); DndType dndType = new DndType();
     * edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory
     * = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
     * PanelType panelType = new PanelType();
     * 
     * //get table rows and fill the panel object for(int i=0; i<3; i++) {
     * ItemType itemType = new ItemType();
     * panelType.getItem().add(itemType);
     * 
     * dndType.getAny().add(pdoFactory.createPanel(panelType));
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory(); try {
     * ExplorerJAXBUtil
     * .getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType),
     * strWriter); } catch(JAXBUtilException e) { e.printStackTrace(); }
     * 
     * //put the data into the event event.data = strWriter.toString(); }
     * 
     * 
     * });
     */

    Composite oModelAddDelButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL = new GridLayout(25, false);
    oModelAddDelButtonComposite.setLayout(gL);
    GridData oModelAddDelButtonGridData = new GridData(GridData.FILL_HORIZONTAL);// HORIZONTAL_ALIGN_FILL);// |
    // GridData.VERTICAL_ALIGN_FILL);
    oModelAddDelButtonGridData.grabExcessHorizontalSpace = false;
    oModelAddDelButtonGridData.horizontalSpan = 2;
    oModelAddDelButtonComposite.setLayoutData(oModelAddDelButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel = new GridData(GridData.FILL_HORIZONTAL);

    Button deleteArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel.horizontalSpan = 4;
    deleteArrowButton.setLayoutData(gdDel);
    deleteArrowButton.setText("Delete From List");
    deleteArrowButton.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        public void widgetSelected(SelectionEvent event) {
            curRowNumber = 0;
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);

            if ((selectedRow != null) && (selectedRow.length > 0)) {
                String conceptName = (String) m_Model.getContentAt(1, selectedRow[0]);
                if (conceptName.equals("Encounter Range Line")) {
                } else if (conceptName.equals("Vital Status Line")) {
                }

                int rowNumber = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue();
                int rid = selectedRow[0];
                ArrayList list = (ArrayList) rowData.get(rowNumber - 1);
                for (int i = 0; i < list.size(); i++) {
                    ConceptTableRow tr = (ConceptTableRow) list.get(i);
                    if (tr.rowId == rid) {
                        list.remove(i);
                        break;
                    }
                }
                if (list.size() == 0) {
                    rowData.remove(rowNumber - 1);
                }
                curRowNumber = rowData.size();
                resetRowNumber();
                // m_Model.deleteRow(selectedRow[0]);
                ((ConceptTableModel) table.getModel()).deleteAllRows();
                ((ConceptTableModel) table.getModel()).populateTable(rowData);
                /*
                 * int newRow = 0; for(int i=0; i<rowData.size(); i++) {
                 * ArrayList alist = (ArrayList) rowData.get(i); for(int
                 * j=0; j<alist.size(); j++) { TableRow r = (TableRow)
                 * alist.get(j); newRow++; r.rowId = newRow;
                 * table.getModel().setContentAt(0, newRow, new
                 * Integer(r.rowNumber).toString());
                 * table.getModel().setContentAt(1, newRow, r.conceptName);
                 * table.getModel().setContentAt(2, newRow, r.valueType);
                 * table.getModel().setContentAt(3, newRow, r.valueText);
                 * table.getModel().setContentAt(4, newRow, r.height);
                 * table.getModel().setContentAt(5, newRow, r.color);
                 * table.getModel().setContentAt(6, newRow, r.conceptXml); }
                 * }
                 */
                table.redraw();
            }
        }
    });

    Button deleteAllButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    deleteAllButton.setLayoutData(gdDel);
    deleteAllButton.setText("Delete All ");
    deleteAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            m_Model.deleteAllRows();
            curRowNumber = 0;
            rowData.clear();
            table.redraw();
        }
    });

    Button putInOrderButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    putInOrderButton.setLayoutData(gdDel);
    putInOrderButton.setText("Put In Order ");
    putInOrderButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            curRowNumber = 0;
            m_Model.fillDataFromTable(rowData);

            Collections.sort(rowData, new Comparator<Object>() {
                @SuppressWarnings("unchecked")
                public int compare(Object o1, Object o2) {
                    int i1 = ((ConceptTableRow) ((ArrayList) o1).get(0)).rowNumber;
                    int i2 = ((ConceptTableRow) ((ArrayList) o2).get(0)).rowNumber;
                    if (i1 > i2) {
                        return 1;
                    } else if (i1 < i2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            m_Model.deleteAllRows();
            m_Model.populateTable(rowData);
            table.redraw();
        }
    });

    Button upArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    upArrowButton.setText("Move Up");
    upArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index < 1) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index - 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] - 1, true);
            table.redraw();
        }
    });

    Button downArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    downArrowButton.setText("Move Down");
    downArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index == (rowData.size() - 1)) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index + 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] + 1, true);
            table.redraw();
        }
    });

    Composite oModelCheckButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL1 = new GridLayout(20, true);
    oModelCheckButtonComposite.setLayout(gL1);
    GridData oModelCheckButtonGridData = new GridData(
            GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    oModelCheckButtonGridData.grabExcessHorizontalSpace = true;
    oModelCheckButtonGridData.horizontalSpan = 2;
    oModelCheckButtonComposite.setLayoutData(oModelCheckButtonGridData);

    Button displayOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayOrNotButton.setText("Display concepts with no data");
    displayOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // do something here- return null
            bDisplayAllData = !bDisplayAllData;
        }
    });

    Button displayDemographicsOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayDemographicsOrNotButton.setText("Display patient demographics");
    if ((System.getProperty("applicationName") != null)
            && System.getProperty("applicationName").equals("BIRN")) {
        displayDemographicsOrNotButton.setSelection(false);
        displayDemographicsOrNotButton.setEnabled(false);
        bDisplayDemographics = false;
    } else if ((System.getProperty("applicationName") == null)
            || System.getProperty("applicationName").equals("i2b2")) {
        displayDemographicsOrNotButton.setSelection(true);
    }
    displayDemographicsOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            bDisplayDemographics = !bDisplayDemographics;
        }
    });

    if (UserInfoBean.getInstance().getCellDataUrl("identity") != null) {
        Composite oPatientSetComposite = new Composite(oModelComposite, SWT.NONE);
        GridData patientSetData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        patientSetData.grabExcessHorizontalSpace = true;
        oPatientSetComposite.setLayoutData(patientSetData);
        oPatientSetComposite.setLayout(null);

        Label mrnlabel = new Label(oPatientSetComposite, SWT.NONE);
        mrnlabel.setText("MRN site:");
        mrnlabel.setBounds(5, 9, 50, 20);

        final Combo siteCombo = new Combo(oPatientSetComposite, SWT.NULL);
        siteCombo.add("BWH");
        siteCombo.add("MGH");
        siteCombo.setBounds(57, 5, 60, 20);
        siteCombo.select(1);

        Label mrnNumber = new Label(oPatientSetComposite, SWT.NONE);
        mrnNumber.setText("number:");
        mrnNumber.setBounds(121, 9, 40, 20);

        mrnlistText = new Text(oPatientSetComposite, SWT.SINGLE | SWT.BORDER);
        mrnlistText.setBounds(164, 5, 150, 20);
        mrnlistText.setText("");

        Button runButton = new Button(oPatientSetComposite, SWT.PUSH);
        runButton.setText("Search By MRN");
        runButton.setBounds(315, 5, 85, 23);
        runButton.addSelectionListener(new SelectionAdapter() {
            @SuppressWarnings("unchecked")
            public void widgetSelected(SelectionEvent event) {
                String mrns = mrnlistText.getText();
                if (mrns.equals("")) {
                    return;
                }

                String[] mrnArray = mrns.split(",");
                int[] idlist = new int[mrnArray.length];
                String username = UserInfoBean.getInstance().getUserName();
                String password = UserInfoBean.getInstance().getUserPassword();
                // log.debug("User name: "+username+" password: "+password);
                String site = siteCombo.getText();
                for (int i = 0; i < mrnArray.length; i++) {
                    // String[] tmps = new String[2];
                    String tmp = mrnArray[i].replaceAll(" ", "");
                    // tmps = tmp.split(":");

                    String queryStr = "<?xml version=\"1.0\" standalone=\"yes\"?>\n" + "<search_by_local>"
                            + "<match_id site=\"" + site.toUpperCase()/* EMPI */
                            + "\">" + tmp/* 100016900 */
                            + "</match_id>\n" + "</search_by_local>";

                    String resultStr = QueryClient.query(queryStr, username, password);
                    log.debug(queryStr);
                    log.debug(resultStr);

                    SAXBuilder parser = new SAXBuilder();
                    String masterID = null;
                    java.io.StringReader xmlStringReader = new java.io.StringReader(resultStr);
                    try {
                        org.jdom.Document tableDoc = parser.build(xmlStringReader);
                        org.jdom.Element tableXml = tableDoc.getRootElement();
                        Element responseXml = (Element) tableXml.getChild("person_list");
                        // Element mrnXml = (Element)
                        // responseXml.getChild("MRN");
                        java.util.List listChildren = responseXml.getChildren();
                        if (listChildren.isEmpty()) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage("No master id found");
                            mBox.open();
                            return;
                        }

                        Element masterXml = (Element) responseXml.getChild("master_record");
                        masterID = masterXml.getAttributeValue("id");
                        log.debug("Patient id: " + masterID);
                        idlist[i] = new Integer(masterID).intValue();
                        log.debug("MRN: " + site + "-" + tmp);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }

                if (tabFolder.getSelectionIndex() == 1) {
                    DestroyMiniVisualization(oAwtContainer);
                } else if (tabFolder.getSelectionIndex() == 0) {
                    oTheParent.getDisplay().syncExec(new Runnable() {
                        public void run() {
                            tabFolder.setSelection(1);
                        }
                    });
                }

                PerformVisualizationQuery(oAwtContainer, idlist, bDisplayAllData);
            }
        });
    }

    DropTarget targetLable = new DropTarget(oModelQueryComposite, DND.DROP_COPY);
    targetLable.setTransfer(types);
    targetLable.addDropListener(new DropTargetAdapter() {
        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                if (tableXml != null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                boolean isQuery = false;
                if (tableXml == null) {
                    tableXml = tableDoc.getRootElement().getChild("query_master",
                            Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));
                }

                if (tableXml != null) {
                    isQuery = true;
                } else {

                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText("Query Name: " + ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP")) {
                            xmlcontent = CRCQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        } else {
                            xmlcontent = CRCQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        }
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null) {

                            return;
                        } else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null) {
                            log.debug("query definition not null");
                        } else {
                            log.error("query definition is null");
                        }

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();
                        int numOfPanels = queryDefinitionType.getPanel().size();
                        for (int i = 0; i < numOfPanels; i++) {
                            PanelType panelType = queryDefinitionType.getPanel().get(i);

                            for (int j = 0; j < panelType.getItem().size(); j++) {
                                ItemType itemType = panelType.getItem().get(j);
                                QueryModel nodedata = new QueryModel();

                                nodedata.name(itemType.getItemName());
                                nodedata.visualAttribute("FA");
                                nodedata.tooltip(itemType.getTooltip());
                                nodedata.fullname(itemType.getItemKey());
                                nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                                if (itemType.getItemShape() != null) {
                                    nodedata.tableRow().height = new String(itemType.getItemShape());
                                    nodedata.tableRow().color = ((ConceptTableModel) table.getModel())
                                            .getColor(itemType.getItemColor());
                                    nodedata.tableRow().rowNumber = Integer
                                            .parseInt(itemType.getItemRowNumber());
                                } else {
                                    nodedata.tableRow().height = "Medium";
                                    nodedata.tableRow().color = new RGB(0, 0, 128);
                                    nodedata.tableRow().rowNumber = j + 1;
                                }

                                nodedata.constrainByValue(itemType.getConstrainByValue());
                                if (itemType.getConstrainByValue().size() > 0) {
                                    nodedata.setValueConstrains(itemType.getConstrainByValue());

                                    if (itemType.getConstrainByValue().size() > 0) {
                                        nodedata.setValueConstrains(itemType.getConstrainByValue());
                                        if (nodedata.valueModel().hasEnumValue()) {
                                            if (nodedata.valueModel().useTextValue()) {
                                                ArrayList<String> results = new ArrayList<String>();
                                                results.toArray(nodedata.valueModel().value().split(","));
                                                nodedata.valueModel().selectedValues = results;
                                            }
                                        }
                                    }
                                }

                                // Handle Constrain By Dates
                                for (int u = 0; u < itemType.getConstrainByDate().size(); u++) {
                                    nodedata.setTimeConstrain(
                                            itemType.getConstrainByDate().get(u).getDateFrom(),
                                            itemType.getConstrainByDate().get(u).getDateTo());
                                }

                                String status = nodedata.setXmlContent();
                                if (status.equalsIgnoreCase("error")) {
                                    MessageBox mBox = new MessageBox(table.getShell(),
                                            SWT.ICON_INFORMATION | SWT.OK);
                                    mBox.setText("Please Note ...");
                                    mBox.setMessage(
                                            "Response delivered from the remote server could not be understood,\n"
                                                    + "you may wish to retry your last action.");
                                    mBox.open();
                                    event.detail = DND.DROP_NONE;

                                    return;
                                }
                                nodeXmls.add(nodedata);
                            }
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        String xmlResponse = CRCQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = CRCQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {

                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                patientSetText.setText("Patient Set: " + setSize + " patients");
                                patientRefId = new String(setId);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } /*
                  * else { List conceptChildren = tableXml.getChildren();
                  * parseDropConcepts(conceptChildren, event);
                  * table.redraw(); }
                  */

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }
    });

    // create drag source
    DragSource source1 = new DragSource(groupNameText, DND.DROP_COPY);
    source1.setTransfer(types);
    source1.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragSetData(DragSourceEvent event) {

            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            StringWriter strWriter = new StringWriter();
            DndType dndType = new DndType();
            edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
            PanelType panelType = new PanelType();
            panelType.setInvert(0);
            PanelType.TotalItemOccurrences totalOccurrences = new PanelType.TotalItemOccurrences();
            totalOccurrences.setValue(1);
            panelType.setTotalItemOccurrences(totalOccurrences);
            panelType.setPanelNumber(0 + 1);
            // panelType.setName(panelData.getItems().get(0).name() + "_"
            // + generateMessageId().substring(0, 4));
            panelType.setName("Panel-1");

            // TO DO: get table rows and fill the panel object
            for (int i = 1; i < i2b2Model.getRowCount(); i++) {
                QueryModel node = (QueryModel) i2b2Model.getContentAt(7, i);
                ItemType itemType = new ItemType();
                itemType.setItemKey(node.fullname());
                itemType.setItemName(node.name());
                itemType.setTooltip(node.tooltip());
                itemType.setHlevel(Integer.parseInt(node.hlevel()));
                itemType.setClazz("ENC");
                itemType.setItemIcon(node.visualAttribute().trim());
                itemType.setItemColor(i2b2Model.getColorString((RGB) i2b2Model.getContentAt(5, i)));
                itemType.setItemRowNumber((String) i2b2Model.getContentAt(0, i));
                itemType.setItemShape((String) i2b2Model.getContentAt(4, i));

                itemType.getConstrainByValue().add(node.valueModel().writeValueConstrain());
                itemType.getConstrainByDate().add(node.writeTimeConstrain());

                panelType.getItem().add(itemType);
            }

            dndType.getAny().add(pdoFactory.createPanel(panelType));
            edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory();
            try {
                AnalysisJAXBUtil.getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType), strWriter);
            } catch (JAXBUtilException e) {
                e.printStackTrace();
            }

            // put the data into the event
            event.data = strWriter.toString();
        }

    });

    DropTarget nameTarget = new DropTarget(groupNameText, DND.DROP_COPY);
    nameTarget.setTransfer(types);
    nameTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document panelDoc = parser.build(xmlStringReader);
                org.jdom.Element panelXml = panelDoc.getRootElement().getChild("panel",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/"));

                if (panelXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                else {

                    String domString = (new XMLOutputter()).outputString(panelXml);
                    JAXBContext jc1 = JAXBContext
                            .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                    Unmarshaller unMarshaller = jc1.createUnmarshaller();
                    JAXBElement panelJaxbElement = (JAXBElement) unMarshaller
                            .unmarshal(new StringReader(domString));

                    PanelType panelType = (PanelType) panelJaxbElement.getValue();
                    String panelname = panelType.getName();
                    groupNameText.setText("Panel Name: " + panelname);
                    for (int j = 0; j < panelType.getItem().size(); j++) {
                        ItemType itemType = panelType.getItem().get(j);
                        QueryModel nodedata = new QueryModel();

                        nodedata.name(itemType.getItemName());
                        nodedata.visualAttribute("FA");
                        nodedata.tooltip(itemType.getTooltip());
                        nodedata.fullname(itemType.getItemKey());
                        nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                        // / need to handle query tool generated panels
                        if (itemType.getItemShape() != null) {
                            nodedata.tableRow().height = new String(itemType.getItemShape());
                            nodedata.tableRow().color = ((ConceptTableModel) table.getModel())
                                    .getColor(itemType.getItemColor());
                            nodedata.tableRow().rowNumber = Integer.parseInt(itemType.getItemRowNumber());
                        } else {
                            nodedata.tableRow().height = "Medium";
                            nodedata.tableRow().color = new RGB(0, 0, 128);
                            nodedata.tableRow().rowNumber = j + 1;
                        }

                        nodedata.constrainByValue(itemType.getConstrainByValue());
                        if (itemType.getConstrainByValue().size() > 0) {
                            nodedata.setValueConstrains(itemType.getConstrainByValue());

                            if (itemType.getConstrainByValue().size() > 0) {
                                nodedata.setValueConstrains(itemType.getConstrainByValue());
                                if (nodedata.valueModel().hasEnumValue()) {
                                    if (nodedata.valueModel().useTextValue()) {
                                        ArrayList<String> results = new ArrayList<String>();
                                        results.toArray(nodedata.valueModel().value().split(","));
                                        nodedata.valueModel().selectedValues = results;
                                    }
                                }
                            }
                        }

                        // Handle Constrain By Dates
                        for (int u = 0; u < itemType.getConstrainByDate().size(); u++) {
                            nodedata.setTimeConstrain(itemType.getConstrainByDate().get(u).getDateFrom(),
                                    itemType.getConstrainByDate().get(u).getDateTo());
                        }

                        String status = nodedata.setXmlContent();
                        if (status.equalsIgnoreCase("error")) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage(
                                    "Response delivered from the remote server could not be understood,\n"
                                            + "you may wish to retry your last action.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;

                            return;
                        }
                        nodeXmls.add(nodedata);
                    }
                    // event.detail = DND.DROP_NONE;
                }
                populateTable(nodeXmls);

            }

            catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            if (textTransfer.isSupportedType(event.currentDataType)) {

                event.detail = DND.DROP_COPY;
            }

            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }
    });

    DropTarget target = new DropTarget(table, DND.DROP_COPY);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                boolean isQuery = false;
                if (tableXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText(ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP")) {
                            xmlcontent = CRCQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        } else {
                            xmlcontent = CRCQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        }
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null) {

                            return;
                        } else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null) {
                            log.debug("query definition not null");
                        } else {
                            log.error("query definition is null");
                        }

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();
                        int numOfPanels = queryDefinitionType.getPanel().size();
                        for (int i = 0; i < numOfPanels; i++) {
                            PanelType panelType = queryDefinitionType.getPanel().get(i);

                            for (int j = 0; j < panelType.getItem().size(); j++) {
                                ItemType itemType = panelType.getItem().get(j);
                                QueryModel nodedata = new QueryModel();

                                nodedata.name(itemType.getItemName());
                                nodedata.visualAttribute("FA");
                                nodedata.tooltip(itemType.getTooltip());
                                nodedata.fullname(itemType.getItemKey());
                                nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                                String status = nodedata.setXmlContent();
                                if (status.equalsIgnoreCase("error")) {
                                    MessageBox mBox = new MessageBox(table.getShell(),
                                            SWT.ICON_INFORMATION | SWT.OK);
                                    mBox.setText("Please Note ...");
                                    mBox.setMessage(
                                            "Response delivered from the remote server could not be understood,\n"
                                                    + "you may wish to retry your last action.");
                                    mBox.open();
                                    event.detail = DND.DROP_NONE;

                                    return;
                                }
                                nodeXmls.add(nodedata);
                            }
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        // log.debug(xmlRequest);
                        String xmlResponse = CRCQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = CRCQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {
                                // resultData.name("Patient Set - "+resultData
                                // .patientCount()+" Patients");
                                // QueryResultData resultData = new
                                // QueryResultData();
                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                patientSetText.setText("Patient Set: " + setSize + " patients");// strs[0]);
                                patientRefId = new String(setId);// strs[1]);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } else {
                    List conceptChildren = tableXml.getChildren();
                    parseDropConcepts(conceptChildren, event);
                    // System.setProperty("XMLfrommodel",(String)
                    // event.data);
                    table.redraw();
                }

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    DropTarget target1 = new DropTarget(patientSetText, DND.DROP_COPY);
    target1.setTransfer(types);
    target1.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            String tmp = patientSetText.getText();
            String dragStr = (String) event.data;
            String[] strs = dragStr.split(":");
            if (strs[0].equalsIgnoreCase("logicquery")) {
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                patientSetText.setText(tmp);
                return;
            }

            JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil();

            try {
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(dragStr);
                DndType dndType = (DndType) jaxbElement.getValue();
                QueryResultInstanceType queryResultInstanceType = (QueryResultInstanceType) new JAXBUnWrapHelper()
                        .getObjectByClass(dndType.getAny(), QueryResultInstanceType.class);

                if (queryResultInstanceType == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String resultTypeName = queryResultInstanceType.getQueryResultType().getName();
                if (resultTypeName == null || !resultTypeName.equalsIgnoreCase("PATIENTSET")) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String setId = queryResultInstanceType.getResultInstanceId();
                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                patientSetText.setText("Patient Set: " + setSize + " patients");// strs[0]);
                patientRefId = new String(setId);// strs[1]);
                patientMinNumText.setText("1");
                leftArrowButton.setEnabled(false);

                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                patientSetSize = queryResultInstanceType.getSetSize();
                if (patientSetSize > maxPatientNum) {
                    rightArrowButton.setEnabled(true);
                    patientMaxNumText.setText("10");
                } else {
                    rightArrowButton.setEnabled(false);
                    // if(patientSetSize>0) {
                    // patientMaxNumText.setText(setSize);
                    // }
                }

                log.debug("Dropped set of: " + setSize + " patients"/*
                                                                    * strs[0
                                                                    * ]
                                                                    */
                        + " with refId: " + setId/* strs[1] */);
            } catch (Exception e) {
                e.printStackTrace();
                event.detail = DND.DROP_NONE;
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    table.addCellResizeListener(new KTableCellResizeListener() {
        public void columnResized(int col, int newWidth) {
            log.debug("Column " + col + " resized to " + newWidth);
        }

        public void rowResized(int newHeight) {
            log.debug("Rows resized to " + newHeight);
        }

    });

    table.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int tableWidth = table.getBounds().width;
            table.getModel().setColumnWidth(1, tableWidth - 425);
        }
    });

    table.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {

        }

        public void mouseExit(MouseEvent arg0) {

        }

        public void mouseHover(MouseEvent arg0) {
            MouseEvent evt = arg0;

            Rectangle rect = table.getCellRect(3, getRowNumber());
            Rectangle rect1 = table.getCellRect(5, 1);

            // System.out.println("rect X and width: "+rect.x+","+rect.width)
            // ;
            // System.out.println("mouse X and Y: "+evt.x+","+evt.y);
            if (evt.y < rect.y && evt.x > rect1.x && evt.x < rect1.x + rect1.width) {
                table.setToolTipText("Double click the cell to change color.");
            } else {
                table.setToolTipText("");
            }
        }

    });

    // Item 2: a Color Palette
    TabItem item2 = new TabItem(tabFolder, SWT.NONE);
    item2.setText("Render a Timeline");
    final Composite comp2 = new Composite(tabFolder, SWT.NONE);
    item2.setControl(comp2);

    GridLayout oGridLayout0 = new GridLayout();
    oGridLayout0.marginWidth = 1;
    oGridLayout0.marginHeight = 5;
    comp2.setLayout(oGridLayout0);

    if (false) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);

        /*
         * Set a Windows specific AWT property that prevents heavyweight
         * components from erasing their background. Note that this is a
         * global property and cannot be scoped. It might not be suitable
         * for your application.
         */
        try {
            // System.setProperty("sun.awt.noerasebackground", "true");
        } catch (NoSuchMethodError error) {
        }

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout()) {
            public void update(java.awt.Graphics g) {
                /* Do not erase the background */
                paint(g);
            }
        };
        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        java.awt.Container contentPane = root.getContentPane();
        log.debug("got to here");

        record record1 = new record();
        record1.start();
        record1.init();

        JScrollPane scrollPane = new JScrollPane(record1);
        contentPane.setLayout(new BorderLayout());
        contentPane.add(scrollPane);
    }

    if (true) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);
        GridData gridData3 = new GridData();
        gridData3.horizontalIndent = 0;
        gridData3.verticalIndent = 0;
        gridData3.horizontalAlignment = GridData.FILL;
        gridData3.verticalAlignment = GridData.FILL;
        gridData3.grabExcessHorizontalSpace = true;
        gridData3.grabExcessVerticalSpace = true;
        composite.setLayoutData(gridData3);
        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout());// {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        oAwtContainer = root.getContentPane();
        log.debug("got to here");
    }

    tabFolder.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {

            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                if (patientSetStr.equalsIgnoreCase("All")) {
                    int minPatient = 0;
                    try {
                        String minText = patientMinNumText.getText();
                        minPatient = Integer.parseInt(minText);
                    } catch (Exception e1) {
                        minPatient = -1;
                    }

                    int maxPatient = 0;
                    try {
                        maxPatient = Integer.parseInt(patientMaxNumText.getText());
                    } catch (Exception e2) {
                        maxPatient = -1;
                    }
                    PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
                } else {
                    int min = Integer.parseInt(patientMinNumText.getText());
                    int max = Integer.parseInt(patientMaxNumText.getText());
                    PerformVisualizationQuery(oAwtContainer, patientRefId, min, max, bDisplayAllData);
                }
            } else {
                DestroyMiniVisualization(oAwtContainer);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    if (drawLeft) {
        horizontalForm.setWeights(new int[] { 30, 70 });
    }

    return parent;
}

From source file:edu.harvard.i2b2.patientMapping.ui.MainComposite.java

/**
 * @param args/* w  ww .  j a va 2s . co  m*/
 */
@SuppressWarnings("serial")
protected Control createContents(Composite parent) {
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    setLayout(topGridLayout);

    Composite oTreeComposite = new Composite(this, SWT.NONE);
    oTreeComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    oTreeComposite.setLayoutData(gridData2);

    // the horizontal sash form
    SashForm horizontalForm = new SashForm(oTreeComposite, SWT.HORIZONTAL);
    horizontalForm.setOrientation(SWT.HORIZONTAL);
    horizontalForm.setLayout(new GridLayout());

    if (drawLeft) {
        // left sash form
        SashForm leftVerticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
        leftVerticalForm.setOrientation(SWT.VERTICAL);
        leftVerticalForm.setLayout(new GridLayout());

        if (bWantStatusLine) {
            slm.createControl(this, SWT.NULL);
        }
        slm.setMessage("i2b2 Explorer Version 2.0");
        slm.update(true);

        // Create the tab folder
        final TabFolder oTabFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        // Create each tab and set its text, tool tip text,
        // image, and control
        TabItem oTreeTab = new TabItem(oTabFolder, SWT.NONE);
        oTreeTab.setText("Concept trees");
        oTreeTab.setToolTipText("Hierarchically organized patient characteristics");
        oTreeTab.setControl(getConceptTreeTabControl(oTabFolder));

        // Select the first tab (index is zero-based)
        oTabFolder.setSelection(0);

        // Create the tab folder
        final TabFolder queryRunFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        TabItem previousRunTab = new TabItem(queryRunFolder, SWT.NONE);
        previousRunTab.setText("Patient Sets and Previous Queries");
        previousRunTab.setToolTipText("Patient Sets & Previous Queries");
        final Composite runComposite = new Composite(queryRunFolder, SWT.EMBEDDED);
        previousRunTab.setControl(runComposite);

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame runFrame = SWT_AWT.new_Frame(runComposite);
        Panel runPanel = new Panel(new BorderLayout());
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        runFrame.add(runPanel);
        JRootPane runRoot = new JRootPane();
        runPanel.add(runRoot);

        // Select the first tab (index is zero-based)
        queryRunFolder.setSelection(0);
    }

    SashForm verticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    verticalForm.setOrientation(SWT.VERTICAL);
    verticalForm.setLayout(new GridLayout());

    // put a tab folder in it...
    tabFolder = new TabFolder(verticalForm, SWT.NONE);

    Composite patientNumsComposite = new Composite(verticalForm, SWT.NONE);
    GridData patientNumData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    patientNumData.grabExcessHorizontalSpace = true;
    patientNumsComposite.setLayoutData(patientNumData);
    patientNumsComposite.setLayout(null);

    Label patientset = new Label(patientNumsComposite, SWT.NONE);
    patientset.setText("Patient Set: ");
    patientset.setBounds(5, 9, 60, 22);

    patientSetText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientSetText.setText("");
    patientSetText.setEditable(false);
    patientSetText.setBounds(70, 5, 300, 35);

    leftArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    leftArrowButton.setText("<<<");
    leftArrowButton.setEnabled(false);
    leftArrowButton.setBounds(380, 5, 38, 22);
    leftArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            runMode = -1;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                int start = new Integer(patientMinNumText.getText()).intValue();
                int inc = new Integer(patientMaxNumText.getText()).intValue();
                if (start - inc <= 1) {
                    leftArrowButton.setEnabled(false);
                }

                if (start <= patientSetSize) {
                    rightArrowButton.setEnabled(true);
                } else {
                    rightArrowButton.setEnabled(false);
                }

                //if ((start - inc) > 1) {
                //patientMinNumText.setText("" + (start - inc));
                //} else {
                //patientMinNumText.setText("1");
                //}
                PerformVisualizationQuery(oAwtContainer, patientRefId, min - max, max - 1, bDisplayAllData);
            }

        }
    });

    final Label patNum1 = new Label(patientNumsComposite, SWT.NONE);
    patNum1.setText(" start: ");
    patNum1.setBounds(425, 9, 31, 20);

    patientMinNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMinNumText.setText("1");
    patientMinNumText.setBounds(460, 5, 45, 22);

    final Label patNum2 = new Label(patientNumsComposite, SWT.NONE);
    patNum2.setText("increment:");
    patNum2.setBounds(515, 9, 57, 20);

    patientMaxNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMaxNumText.setText("10");
    patientMaxNumText.setBounds(572, 5, 45, 22);

    rightArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    rightArrowButton.setText(">>>");
    rightArrowButton.setEnabled(false);
    rightArrowButton.setBounds(626, 5, 38, 20);
    rightArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            runMode = 1;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                int start = new Integer(patientMinNumText.getText()).intValue();
                int inc = new Integer(patientMaxNumText.getText()).intValue();
                if (start + inc > patientSetSize) {
                    rightArrowButton.setEnabled(false);
                }
                //patientMinNumText.setText("" + (start + inc));
                leftArrowButton.setEnabled(true);
                PerformVisualizationQuery(oAwtContainer, patientRefId, min, max - 1, bDisplayAllData);
            }
            // getDisplay().syncExec(new Runnable() {
            // public void run() {
            // if(returnedNumber >= 0) {
            // setIncrementNumber(returnedNumber);
            // MessageBox mBox = new MessageBox(getShell(),
            // SWT.ICON_INFORMATION
            // | SWT.OK);
            // mBox.setText("Please Note ...");
            // mBox.setMessage(/*"Can't return all the requested "+
            // requestIndex+" patients, */"Only "+returnedNumber+" patients
            // returned");
            // mBox.open();
            // }
            // }
            // });
        }
    });

    addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int w = getBounds().width;
            patientSetText.setBounds(70, 5, w - 357, 24);
            leftArrowButton.setBounds(w - 281, 5, 38, 24);
            patNum1.setBounds(w - 239, 9, 31, 24);
            patientMinNumText.setBounds(w - 204, 5, 45, 24);
            patNum2.setBounds(w - 149, 9, 57, 24);
            patientMaxNumText.setBounds(w - 92, 5, 45, 24);
            rightArrowButton.setBounds(w - 42, 5, 37, 24);
        }
    });

    verticalForm.setWeights(new int[] { 25, 3 });

    // Item 1: a Text Table
    TabItem item1 = new TabItem(tabFolder, SWT.NONE);
    item1.setText("Create model for Timeline");

    Composite oModelComposite = new Composite(tabFolder, SWT.NONE);
    item1.setControl(oModelComposite);

    GridLayout gridLayout = new GridLayout(2, false);

    // gridLayout.marginHeight = 0;
    // gridLayout.marginWidth = 0;
    // gridLayout.verticalSpacing = 0;
    // gridLayout.horizontalSpacing = 0;

    gridLayout.marginTop = 2;
    gridLayout.marginLeft = 0;
    gridLayout.marginBottom = 2;
    gridLayout.verticalSpacing = 1;
    gridLayout.horizontalSpacing = 1;
    oModelComposite.setLayout(gridLayout);

    oModelQueryComposite = new FramedComposite(oModelComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelQueryComposite.setLayout(new GridLayout(25, false));
    oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    GridData oModelQueryButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelQueryButtonGridData.grabExcessHorizontalSpace = false;
    oModelQueryButtonGridData.horizontalSpan = 2;
    oModelQueryButtonGridData.verticalAlignment = SWT.CENTER;
    oModelQueryButtonGridData.verticalIndent = 5;
    oModelQueryComposite.setLayoutData(oModelQueryButtonGridData);

    queryNamemrnlistText = new Label(oModelQueryComposite, SWT.NONE);
    queryNamemrnlistText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    queryNamemrnlistText.setText("Query Name: ");
    // queryNamemrnlistText.setBounds(5, 4, 600, 20);

    queryNamemrnlistText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    oModelQueryComposite.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent arg0) {

        }

    });

    oModelQueryComposite.addDragDetectListener(new DragDetectListener() {

        public void dragDetected(DragDetectEvent arg0) {

        }

    });

    Composite oGroupComposite = new Composite(oModelComposite, SWT.NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oGroupComposite.setLayout(gridLayout);
    GridData oGroupGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    oGroupGridData.grabExcessHorizontalSpace = true;
    oGroupGridData.grabExcessVerticalSpace = true;
    oGroupGridData.verticalIndent = 1;
    oGroupGridData.verticalSpan = GridData.VERTICAL_ALIGN_FILL;
    // oGroupGridData.verticalAlignment = GridData.VERTICAL_ALIGN_FILL;
    oGroupComposite.setLayoutData(oGroupGridData);

    oModelGroupComposite = new FramedComposite(oGroupComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelGroupComposite.setLayout(new GridLayout(25, false));
    GridData oModelGroupButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelGroupButtonGridData.grabExcessHorizontalSpace = false;
    oModelGroupButtonGridData.horizontalSpan = 2;
    oModelGroupButtonGridData.verticalAlignment = SWT.CENTER;
    oModelGroupButtonGridData.verticalIndent = 5;
    oModelGroupComposite.setLayoutData(oModelGroupButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel1 = new GridData(GridData.FILL_HORIZONTAL);

    groupNameText = new Label(oModelGroupComposite, SWT.NONE);
    gdDel1.horizontalSpan = 4;
    groupNameText.setLayoutData(gdDel1);
    groupNameText.setText("Panel Name: ");
    // groupNameText.setBounds(80, 8, 400, 24);
    // groupNameText.setAlignment(SWT.CENTER);
    // createDragSource(queryNamemrnlistText);
    // createDropTarget(queryNamemrnlistText);

    groupNameText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    // put a table in tabItem1...
    table = new KTable(oGroupComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    table.setFocus();
    table.setBackground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGridData.verticalIndent = 5;
    table.setLayoutData(tableGridData);
    table.setRowSelectionMode(true);
    // table.setMultiSelectionMode(true);
    // table.setModel(new KTableForModel());
    table.setModel(new ConceptTableModel());
    // table.getModel().setColumnWidth(0, oModelComposite.getBounds().width
    // - 35);
    table.addCellSelectionListener(new KTableCellSelectionListener() {
        public void cellSelected(int col, int row, int statemask) {
            log.debug("Cell [" + col + ";" + row + "] selected.");
            // System.out.println("Cell [" + col + ";" + row +
            // "] selected.");
            table.selectedRow = row;
            table.selectedColumn = col;
        }

        public void fixedCellSelected(int col, int row, int statemask) {
            log.debug("Header [" + col + ";" + row + "] selected.");
            // System.out.println("Header [" + col + ";" + row +
            // "] selected.");
        }

    });

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

    // create drag source
    /*
     * DragSource source = new DragSource(queryNamemrnlistText,
     * DND.DROP_COPY); source.setTransfer(types); source.addDragListener(new
     * DragSourceAdapter() {
     * 
     * @Override public void dragSetData(DragSourceEvent event) {
     * //DragSource ds = (DragSource) event.widget; StringWriter strWriter =
     * new StringWriter(); DndType dndType = new DndType();
     * edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory
     * = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
     * PanelType panelType = new PanelType();
     * 
     * //get table rows and fill the panel object for(int i=0; i<3; i++) {
     * ItemType itemType = new ItemType();
     * panelType.getItem().add(itemType);
     * 
     * dndType.getAny().add(pdoFactory.createPanel(panelType));
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory(); try {
     * ExplorerJAXBUtil
     * .getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType),
     * strWriter); } catch(JAXBUtilException e) { e.printStackTrace(); }
     * 
     * //put the data into the event event.data = strWriter.toString(); }
     * 
     * 
     * });
     */

    Composite oModelAddDelButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL = new GridLayout(25, false);
    oModelAddDelButtonComposite.setLayout(gL);
    GridData oModelAddDelButtonGridData = new GridData(GridData.FILL_HORIZONTAL);// HORIZONTAL_ALIGN_FILL);// |
    // GridData.VERTICAL_ALIGN_FILL);
    oModelAddDelButtonGridData.grabExcessHorizontalSpace = false;
    oModelAddDelButtonGridData.horizontalSpan = 2;
    oModelAddDelButtonComposite.setLayoutData(oModelAddDelButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel = new GridData(GridData.FILL_HORIZONTAL);

    Button deleteArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel.horizontalSpan = 4;
    deleteArrowButton.setLayoutData(gdDel);
    deleteArrowButton.setText("Delete From List");
    deleteArrowButton.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        public void widgetSelected(SelectionEvent event) {
            curRowNumber = 0;
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);

            if ((selectedRow != null) && (selectedRow.length > 0)) {
                String conceptName = (String) m_Model.getContentAt(1, selectedRow[0]);
                if (conceptName.equals("Encounter Range Line")) {
                } else if (conceptName.equals("Vital Status Line")) {
                }

                int rowNumber = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue();
                int rid = selectedRow[0];
                ArrayList list = (ArrayList) rowData.get(rowNumber - 1);
                for (int i = 0; i < list.size(); i++) {
                    ConceptTableRow tr = (ConceptTableRow) list.get(i);
                    if (tr.rowId == rid) {
                        list.remove(i);
                        break;
                    }
                }
                if (list.size() == 0) {
                    rowData.remove(rowNumber - 1);
                }
                curRowNumber = rowData.size();
                resetRowNumber();
                // m_Model.deleteRow(selectedRow[0]);
                ((ConceptTableModel) table.getModel()).deleteAllRows();
                ((ConceptTableModel) table.getModel()).populateTable(rowData);
                /*
                 * int newRow = 0; for(int i=0; i<rowData.size(); i++) {
                 * ArrayList alist = (ArrayList) rowData.get(i); for(int
                 * j=0; j<alist.size(); j++) { TableRow r = (TableRow)
                 * alist.get(j); newRow++; r.rowId = newRow;
                 * table.getModel().setContentAt(0, newRow, new
                 * Integer(r.rowNumber).toString());
                 * table.getModel().setContentAt(1, newRow, r.conceptName);
                 * table.getModel().setContentAt(2, newRow, r.valueType);
                 * table.getModel().setContentAt(3, newRow, r.valueText);
                 * table.getModel().setContentAt(4, newRow, r.height);
                 * table.getModel().setContentAt(5, newRow, r.color);
                 * table.getModel().setContentAt(6, newRow, r.conceptXml); }
                 * }
                 */
                table.redraw();
                queryNamemrnlistText.setText("Query Name: ");
                groupNameText.setText("Panel Name: ");
            }
        }
    });

    Button deleteAllButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    deleteAllButton.setLayoutData(gdDel);
    deleteAllButton.setText("Delete All ");
    deleteAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            m_Model.deleteAllRows();
            curRowNumber = 0;
            rowData.clear();
            queryNamemrnlistText.setText("Query Name: ");
            groupNameText.setText("Panel Name: ");
            table.redraw();
        }
    });

    Button putInOrderButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    putInOrderButton.setLayoutData(gdDel);
    putInOrderButton.setText("Put In Order ");
    putInOrderButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            curRowNumber = 0;
            m_Model.fillDataFromTable(rowData);

            Collections.sort(rowData, new Comparator<Object>() {
                @SuppressWarnings("unchecked")
                public int compare(Object o1, Object o2) {
                    int i1 = ((ConceptTableRow) ((ArrayList) o1).get(0)).rowNumber;
                    int i2 = ((ConceptTableRow) ((ArrayList) o2).get(0)).rowNumber;
                    if (i1 > i2) {
                        return 1;
                    } else if (i1 < i2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            m_Model.deleteAllRows();
            m_Model.populateTable(rowData);
            table.redraw();
        }
    });

    Button upArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    upArrowButton.setText("Move Up");
    upArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index < 1) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index - 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] - 1, true);
            table.redraw();
        }
    });

    Button downArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    downArrowButton.setText("Move Down");
    downArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index == (rowData.size() - 1)) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index + 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] + 1, true);
            table.redraw();
        }
    });

    Composite oModelCheckButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL1 = new GridLayout(20, true);
    oModelCheckButtonComposite.setLayout(gL1);
    GridData oModelCheckButtonGridData = new GridData(
            GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    oModelCheckButtonGridData.grabExcessHorizontalSpace = true;
    oModelCheckButtonGridData.horizontalSpan = 2;
    oModelCheckButtonComposite.setLayoutData(oModelCheckButtonGridData);

    Button displayOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayOrNotButton.setText("Display concepts with no data");
    displayOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // do something here- return null
            bDisplayAllData = !bDisplayAllData;
        }
    });

    Button displayDemographicsOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayDemographicsOrNotButton.setText("Display patient demographics");
    if ((System.getProperty("applicationName") != null)
            && System.getProperty("applicationName").equals("BIRN")) {
        displayDemographicsOrNotButton.setSelection(false);
        displayDemographicsOrNotButton.setEnabled(false);
        bDisplayDemographics = false;
    } else if ((System.getProperty("applicationName") == null)
            || System.getProperty("applicationName").equals("i2b2")) {
        displayDemographicsOrNotButton.setSelection(true);
    }
    displayDemographicsOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            bDisplayDemographics = !bDisplayDemographics;
        }
    });

    if (UserInfoBean.getInstance().getCellDataUrl("identity") != null) {
        Composite oPatientSetComposite = new Composite(oModelComposite, SWT.NONE);
        GridData patientSetData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        patientSetData.grabExcessHorizontalSpace = true;
        oPatientSetComposite.setLayoutData(patientSetData);
        oPatientSetComposite.setLayout(null);

        Label mrnlabel = new Label(oPatientSetComposite, SWT.NONE);
        mrnlabel.setText("MRN site:");
        mrnlabel.setBounds(5, 9, 50, 20);

        final Combo siteCombo = new Combo(oPatientSetComposite, SWT.NULL);
        siteCombo.add("BWH");
        siteCombo.add("MGH");
        siteCombo.setBounds(57, 5, 60, 20);
        siteCombo.select(1);

        Label mrnNumber = new Label(oPatientSetComposite, SWT.NONE);
        mrnNumber.setText("number:");
        mrnNumber.setBounds(121, 9, 40, 20);

        mrnlistText = new Text(oPatientSetComposite, SWT.SINGLE | SWT.BORDER);
        mrnlistText.setBounds(164, 5, 150, 20);
        mrnlistText.setText("");

        Button runButton = new Button(oPatientSetComposite, SWT.PUSH);
        runButton.setText("Search By MRN");
        runButton.setBounds(315, 5, 85, 23);
        runButton.addSelectionListener(new SelectionAdapter() {
            @SuppressWarnings("unchecked")
            public void widgetSelected(SelectionEvent event) {
                String mrns = mrnlistText.getText();
                if (mrns.equals("")) {
                    return;
                }

                String[] mrnArray = mrns.split(",");
                int[] idlist = new int[mrnArray.length];
                String username = UserInfoBean.getInstance().getUserName();
                String password = UserInfoBean.getInstance().getUserPassword();
                // log.debug("User name: "+username+" password: "+password);
                String site = siteCombo.getText();
                for (int i = 0; i < mrnArray.length; i++) {
                    // String[] tmps = new String[2];
                    String tmp = mrnArray[i].replaceAll(" ", "");
                    // tmps = tmp.split(":");

                    String queryStr = "<?xml version=\"1.0\" standalone=\"yes\"?>\n" + "<search_by_local>"
                            + "<match_id site=\"" + site.toUpperCase()/* EMPI */
                            + "\">" + tmp/* 100016900 */
                            + "</match_id>\n" + "</search_by_local>";

                    //String resultStr = QueryClient.query(queryStr,
                    //   username, password);
                    //log.debug(queryStr);
                    //log.debug(resultStr);

                    /*SAXBuilder parser = new SAXBuilder();
                    String masterID = null;
                    java.io.StringReader xmlStringReader = new java.io.StringReader(
                          resultStr);
                    try {
                       org.jdom.Document tableDoc = parser
                             .build(xmlStringReader);
                       org.jdom.Element tableXml = tableDoc
                             .getRootElement();
                       Element responseXml = (Element) tableXml
                             .getChild("person_list");
                       // Element mrnXml = (Element)
                       // responseXml.getChild("MRN");
                       java.util.List listChildren = responseXml
                             .getChildren();
                       if (listChildren.isEmpty()) {
                          MessageBox mBox = new MessageBox(table
                      .getShell(), SWT.ICON_INFORMATION
                      | SWT.OK);
                          mBox.setText("Please Note ...");
                          mBox.setMessage("No master id found");
                          mBox.open();
                          return;
                       }
                            
                       Element masterXml = (Element) responseXml
                             .getChild("master_record");
                       masterID = masterXml.getAttributeValue("id");
                       log.debug("Patient id: " + masterID);
                       idlist[i] = new Integer(masterID).intValue();
                       log.debug("MRN: " + site + "-" + tmp);
                    } catch (Exception e1) {
                       e1.printStackTrace();
                    }*/
                }

                if (tabFolder.getSelectionIndex() == 1) {
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            DestroyMiniVisualization(oAwtContainer);
                        }
                    });
                } else if (tabFolder.getSelectionIndex() == 0) {
                    oTheParent.getDisplay().syncExec(new Runnable() {
                        public void run() {
                            tabFolder.setSelection(1);
                        }
                    });
                }

                PerformVisualizationQuery(oAwtContainer, idlist, bDisplayAllData);
            }
        });
    }

    DropTarget targetLable = new DropTarget(oModelQueryComposite, DND.DROP_COPY);
    targetLable.setTransfer(types);
    targetLable.addDropListener(new DropTargetAdapter() {
        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                if (tableXml != null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                boolean isQuery = false;
                if (tableXml == null) {
                    tableXml = tableDoc.getRootElement().getChild("query_master",
                            Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));
                }

                if (tableXml != null) {
                    isQuery = true;
                } else {

                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = PatientMappingJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText("Query Name: " + ndata.name());
                        groupNameText.setText("Panel Name: All items of Query " + ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP")) {
                            xmlcontent = PatientMappingQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        } else {
                            xmlcontent = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        }
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null) {

                            return;
                        } else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null) {
                            log.debug("query definition not null");
                        } else {
                            log.error("query definition is null");
                        }

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();
                        int numOfPanels = queryDefinitionType.getPanel().size();
                        int conceptCount = 0;
                        for (int i = 0; i < numOfPanels; i++) {
                            PanelType panelType = queryDefinitionType.getPanel().get(i);

                            for (int j = 0; j < panelType.getItem().size(); j++) {
                                ItemType itemType = panelType.getItem().get(j);

                                ///////////////////////////////////////////////
                                QueryModel nodedata = null;
                                ConstrainByModifier md = itemType.getConstrainByModifier();
                                if (md != null) {
                                    nodedata = new ModifierData();
                                    nodedata.isModifier(true);
                                    ((ModifierData) nodedata).modifier_key(md.getModifierKey());
                                    ((ModifierData) nodedata).applied_path(md.getAppliedPath());
                                    ((ModifierData) nodedata).modifier_name(md.getModifierName());
                                    ((ModifierData) nodedata)
                                            .setModifierValueConstraint(md.getConstrainByValue());
                                } else {
                                    nodedata = new QueryModel();
                                }

                                nodedata.name(itemType.getItemName());
                                nodedata.visualAttribute("FA");
                                nodedata.tooltip(itemType.getTooltip());
                                nodedata.fullname(itemType.getItemKey());
                                nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                                if (itemType.getItemShape() != null) {
                                    nodedata.tableRow().height = new String(itemType.getItemShape());
                                    nodedata.tableRow().color = ((ConceptTableModel) table.getModel())
                                            .getColor(itemType.getItemColor());
                                    // nodedata.tableRow().rowNumber =
                                    // Integer
                                    // .parseInt(itemType
                                    // .getItemRowNumber());
                                    nodedata.tableRow().rowNumber = conceptCount + 1;
                                } else {
                                    nodedata.tableRow().height = "Medium";
                                    nodedata.tableRow().color = new RGB(0, 0, 128);
                                    nodedata.tableRow().rowNumber = conceptCount + 1;
                                }

                                nodedata.constrainByValue(itemType.getConstrainByValue());
                                if (itemType.getConstrainByValue().size() > 0) {
                                    nodedata.setValueConstrains(itemType.getConstrainByValue());

                                    if (itemType.getConstrainByValue().size() > 0) {
                                        nodedata.setValueConstrains(itemType.getConstrainByValue());
                                        if (nodedata.valueModel().hasEnumValue()) {
                                            if (nodedata.valueModel().useTextValue()) {
                                                ArrayList<String> results = new ArrayList<String>();
                                                results.toArray(nodedata.valueModel().value().split(","));
                                                nodedata.valueModel().selectedValues = results;
                                            }
                                        }
                                    }
                                }

                                // Handle Constrain By Dates
                                for (int u = 0; u < itemType.getConstrainByDate().size(); u++) {
                                    nodedata.setTimeConstrain(
                                            itemType.getConstrainByDate().get(u).getDateFrom(),
                                            itemType.getConstrainByDate().get(u).getDateTo());
                                }

                                nodedata.updateNodeMetaDataXML();
                                //if (status.equalsIgnoreCase("error")) {
                                // MessageBox mBox = new
                                // MessageBox(table
                                // .getShell(),
                                // SWT.ICON_INFORMATION | SWT.OK);
                                // mBox.setText("Please Note ...");
                                // mBox.setMessage("Response delivered from the remote server could not be understood,\n"
                                // +
                                // "you may wish to retry your last action.");
                                // mBox.open();
                                // event.detail = DND.DROP_NONE;

                                //continue;
                                //} else {
                                nodeXmls.add(nodedata);
                                conceptCount++;
                                //}
                            }
                        }
                        if (nodeXmls.size() == 0) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage("No valid concept was found.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        String xmlResponse = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {

                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                String description = queryResultInstanceType.getDescription();
                                if (description != null) {
                                    patientSetText.setText(description);
                                } else {
                                    patientSetText.setText("Patient Set: " + setSize + " patients");
                                }
                                patientRefId = new String(setId);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } /*
                  * else { List conceptChildren = tableXml.getChildren();
                  * parseDropConcepts(conceptChildren, event);
                  * table.redraw(); }
                  */

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }
    });

    // create drag source
    DragSource source1 = new DragSource(groupNameText, DND.DROP_COPY);
    source1.setTransfer(types);
    source1.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragSetData(DragSourceEvent event) {

            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            StringWriter strWriter = new StringWriter();
            DndType dndType = new DndType();
            edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
            PanelType panelType = new PanelType();
            panelType.setInvert(0);
            PanelType.TotalItemOccurrences totalOccurrences = new PanelType.TotalItemOccurrences();
            totalOccurrences.setValue(1);
            panelType.setTotalItemOccurrences(totalOccurrences);
            panelType.setPanelNumber(0 + 1);
            // panelType.setName(panelData.getItems().get(0).name() + "_"
            // + generateMessageId().substring(0, 4));
            panelType.setName("Panel-1");

            // TO DO: get table rows and fill the panel object
            for (int i = 1; i < i2b2Model.getRowCount(); i++) {
                QueryModel node = (QueryModel) i2b2Model.getContentAt(7, i);
                ItemType itemType = new ItemType();
                itemType.setItemKey(node.fullname());
                itemType.setItemName(node.name());
                itemType.setTooltip(node.tooltip());
                itemType.setHlevel(Integer.parseInt(node.hlevel()));
                itemType.setClazz("ENC");
                itemType.setItemIcon(node.visualAttribute().trim());
                itemType.setItemColor(i2b2Model.getColorString((RGB) i2b2Model.getContentAt(5, i)));
                itemType.setItemRowNumber((String) i2b2Model.getContentAt(0, i));
                itemType.setItemShape((String) i2b2Model.getContentAt(4, i));

                itemType.getConstrainByValue().add(node.valueModel().writeValueConstraint());
                itemType.getConstrainByDate().add(node.writeTimeConstrain());

                panelType.getItem().add(itemType);
            }

            dndType.getAny().add(pdoFactory.createPanel(panelType));
            edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory();
            try {
                PatientMappingJAXBUtil.getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType),
                        strWriter);
            } catch (JAXBUtilException e) {
                e.printStackTrace();
            }

            // put the data into the event
            event.data = strWriter.toString();
        }

    });

    DropTarget nameTarget = new DropTarget(groupNameText, DND.DROP_COPY);
    nameTarget.setTransfer(types);
    nameTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document panelDoc = parser.build(xmlStringReader);
                org.jdom.Element panelXml = panelDoc.getRootElement().getChild("panel",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/"));

                if (panelXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                else {

                    String domString = (new XMLOutputter()).outputString(panelXml);
                    JAXBContext jc1 = JAXBContext
                            .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                    Unmarshaller unMarshaller = jc1.createUnmarshaller();
                    JAXBElement panelJaxbElement = (JAXBElement) unMarshaller
                            .unmarshal(new StringReader(domString));

                    PanelType panelType = (PanelType) panelJaxbElement.getValue();
                    String panelname = panelType.getName();
                    groupNameText.setText("Panel Name: " + panelname);
                    queryNamemrnlistText.setText("Query Name: ");
                    for (int j = 0; j < panelType.getItem().size(); j++) {
                        ItemType itemType = panelType.getItem().get(j);
                        QueryModel nodedata = new QueryModel();

                        nodedata.name(itemType.getItemName());
                        nodedata.visualAttribute("FA");
                        nodedata.tooltip(itemType.getTooltip());
                        nodedata.fullname(itemType.getItemKey());
                        nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                        // / need to handle query tool generated panels
                        if (itemType.getItemShape() != null) {
                            nodedata.tableRow().height = new String(itemType.getItemShape());
                            nodedata.tableRow().color = ((ConceptTableModel) table.getModel())
                                    .getColor(itemType.getItemColor());
                            nodedata.tableRow().rowNumber = Integer.parseInt(itemType.getItemRowNumber());
                        } else {
                            nodedata.tableRow().height = "Medium";
                            nodedata.tableRow().color = new RGB(0, 0, 128);
                            nodedata.tableRow().rowNumber = j + 1;
                        }

                        nodedata.constrainByValue(itemType.getConstrainByValue());
                        if (itemType.getConstrainByValue().size() > 0) {
                            nodedata.setValueConstrains(itemType.getConstrainByValue());

                            if (itemType.getConstrainByValue().size() > 0) {
                                nodedata.setValueConstrains(itemType.getConstrainByValue());
                                if (nodedata.valueModel().hasEnumValue()) {
                                    if (nodedata.valueModel().useTextValue()) {
                                        ArrayList<String> results = new ArrayList<String>();
                                        results.toArray(nodedata.valueModel().value().split(","));
                                        nodedata.valueModel().selectedValues = results;
                                    }
                                }
                            }
                        }

                        // Handle Constrain By Dates
                        for (int u = 0; u < itemType.getConstrainByDate().size(); u++) {
                            nodedata.setTimeConstrain(itemType.getConstrainByDate().get(u).getDateFrom(),
                                    itemType.getConstrainByDate().get(u).getDateTo());
                        }

                        String status = nodedata.setXmlContent();
                        if (status.equalsIgnoreCase("error")) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage(
                                    "Response delivered from the remote server could not be understood,\n"
                                            + "you may wish to retry your last action.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;

                            return;
                        }
                        nodeXmls.add(nodedata);
                    }
                    // event.detail = DND.DROP_NONE;
                }
                populateTable(nodeXmls);

            }

            catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            if (textTransfer.isSupportedType(event.currentDataType)) {

                event.detail = DND.DROP_COPY;
            }

            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }
    });

    DropTarget target = new DropTarget(table, DND.DROP_COPY);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                boolean isQuery = false;
                if (tableXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = PatientMappingJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText(ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP")) {
                            xmlcontent = PatientMappingQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        } else {
                            xmlcontent = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        }
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null) {

                            return;
                        } else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null) {
                            log.debug("query definition not null");
                        } else {
                            log.error("query definition is null");
                        }

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();
                        int numOfPanels = queryDefinitionType.getPanel().size();
                        for (int i = 0; i < numOfPanels; i++) {
                            PanelType panelType = queryDefinitionType.getPanel().get(i);

                            for (int j = 0; j < panelType.getItem().size(); j++) {
                                ItemType itemType = panelType.getItem().get(j);
                                QueryModel nodedata = new QueryModel();

                                nodedata.name(itemType.getItemName());
                                nodedata.visualAttribute("FA");
                                nodedata.tooltip(itemType.getTooltip());
                                nodedata.fullname(itemType.getItemKey());
                                nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                                String status = nodedata.setXmlContent();
                                if (status.equalsIgnoreCase("error")) {
                                    MessageBox mBox = new MessageBox(table.getShell(),
                                            SWT.ICON_INFORMATION | SWT.OK);
                                    mBox.setText("Please Note ...");
                                    mBox.setMessage(
                                            "Response delivered from the remote server could not be understood,\n"
                                                    + "you may wish to retry your last action.");
                                    mBox.open();
                                    event.detail = DND.DROP_NONE;

                                    return;
                                }
                                nodeXmls.add(nodedata);
                            }
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        // log.debug(xmlRequest);
                        String xmlResponse = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = PatientMappingQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {
                                // resultData.name("Patient Set - "+resultData
                                // .patientCount()+" Patients");
                                // QueryResultData resultData = new
                                // QueryResultData();
                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                patientSetText.setText("Patient Set: " + setSize + " patients");// strs[0]);
                                patientRefId = new String(setId);// strs[1]);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } else {
                    List conceptChildren = tableXml.getChildren();
                    parseDropConcepts(conceptChildren, event);
                    // System.setProperty("XMLfrommodel",(String)
                    // event.data);
                    table.redraw();
                    queryNamemrnlistText.setText("Query Name: ");
                    groupNameText.setText("Panel Name: ");
                }

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    DropTarget target1 = new DropTarget(patientSetText, DND.DROP_COPY);
    target1.setTransfer(types);
    target1.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            String tmp = patientSetText.getText();
            String dragStr = (String) event.data;
            String[] strs = dragStr.split(":");
            if (strs[0].equalsIgnoreCase("logicquery")) {
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                patientSetText.setText(tmp);
                return;
            }

            JAXBUtil jaxbUtil = PatientMappingJAXBUtil.getJAXBUtil();

            try {
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(dragStr);
                DndType dndType = (DndType) jaxbElement.getValue();
                QueryResultInstanceType queryResultInstanceType = (QueryResultInstanceType) new JAXBUnWrapHelper()
                        .getObjectByClass(dndType.getAny(), QueryResultInstanceType.class);

                if (queryResultInstanceType == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String resultTypeName = queryResultInstanceType.getQueryResultType().getName();
                if (resultTypeName == null || !resultTypeName.equalsIgnoreCase("PATIENTSET")) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String setId = queryResultInstanceType.getResultInstanceId();
                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                patientSetText.setText(queryResultInstanceType.getDescription());// "Patient Set: " + setSize
                // + " patients");// strs[0]);
                patientRefId = new String(setId);// strs[1]);
                patientMinNumText.setText("1");
                leftArrowButton.setEnabled(false);
                queryNamemrnlistText.setText("Query Name: ");
                // groupNameText.setText("Panel Name: ");

                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                patientSetSize = queryResultInstanceType.getSetSize();
                if (patientSetSize > maxPatientNum) {
                    rightArrowButton.setEnabled(true);
                    patientMaxNumText.setText("10");
                } else {
                    rightArrowButton.setEnabled(false);
                    // if(patientSetSize>0) {
                    // patientMaxNumText.setText(setSize);
                    // }
                }

                log.debug("Dropped set of: " + setSize + " patients"/*
                                                                    * strs[0
                                                                    * ]
                                                                    */
                        + " with refId: " + setId/* strs[1] */);
            } catch (Exception e) {
                e.printStackTrace();
                event.detail = DND.DROP_NONE;
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    table.addCellResizeListener(new KTableCellResizeListener() {
        public void columnResized(int col, int newWidth) {
            log.debug("Column " + col + " resized to " + newWidth);
        }

        public void rowResized(int newHeight) {
            log.debug("Rows resized to " + newHeight);
        }

    });

    table.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int tableWidth = table.getBounds().width;
            table.getModel().setColumnWidth(1, tableWidth - 505);
        }
    });

    table.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {

        }

        public void mouseExit(MouseEvent arg0) {

        }

        public void mouseHover(MouseEvent arg0) {
            MouseEvent evt = arg0;

            Rectangle rect = table.getCellRect(3, getRowNumber());
            Rectangle rect1 = table.getCellRect(5, 1);

            // System.out.println("rect X and width: "+rect.x+","+rect.width)
            // ;
            // System.out.println("mouse X and Y: "+evt.x+","+evt.y);
            if (evt.y < rect.y && evt.x > rect1.x && evt.x < rect1.x + rect1.width) {
                table.setToolTipText("Double click the cell to change color.");
            } else {
                table.setToolTipText("");
            }
        }

    });

    // Item 2: a Color Palette
    TabItem item2 = new TabItem(tabFolder, SWT.NONE);
    item2.setText("Render a Timeline");
    final Composite comp2 = new Composite(tabFolder, SWT.NONE);
    item2.setControl(comp2);

    GridLayout oGridLayout0 = new GridLayout();
    oGridLayout0.marginWidth = 1;
    oGridLayout0.marginHeight = 5;
    comp2.setLayout(oGridLayout0);

    if (false) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);

        /*
         * Set a Windows specific AWT property that prevents heavyweight
         * components from erasing their background. Note that this is a
         * global property and cannot be scoped. It might not be suitable
         * for your application.
         */
        try {
            // System.setProperty("sun.awt.noerasebackground", "true");
        } catch (NoSuchMethodError error) {
        }

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout()) {
            public void update(java.awt.Graphics g) {
                /* Do not erase the background */
                paint(g);
            }
        };
        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        java.awt.Container contentPane = root.getContentPane();
        log.debug("got to here");

        //Record record1 = new Record();
        // record1.start();
        //record1.init();

        //JScrollPane scrollPane = new JScrollPane(record1);
        //contentPane.setLayout(new BorderLayout());
        //contentPane.add(scrollPane);
    }

    if (true) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);
        GridData gridData3 = new GridData();
        gridData3.horizontalIndent = 0;
        gridData3.verticalIndent = 0;
        gridData3.horizontalAlignment = GridData.FILL;
        gridData3.verticalAlignment = GridData.FILL;
        gridData3.grabExcessHorizontalSpace = true;
        gridData3.grabExcessVerticalSpace = true;
        composite.setLayoutData(gridData3);
        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout());// {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        oAwtContainer = root.getContentPane();
        log.debug("got to here");
    }

    tabFolder.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            runMode = 0;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                if (patientSetStr.equalsIgnoreCase("All")) {
                    int minPatient = 0;
                    try {
                        String minText = patientMinNumText.getText();
                        minPatient = Integer.parseInt(minText);
                    } catch (Exception e1) {
                        minPatient = -1;
                    }

                    int maxPatient = 0;
                    try {
                        maxPatient = Integer.parseInt(patientMaxNumText.getText());
                    } catch (Exception e2) {
                        maxPatient = -1;
                    }
                    PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
                } else {
                    int min = Integer.parseInt(patientMinNumText.getText());
                    int max = Integer.parseInt(patientMaxNumText.getText());
                    int start = new Integer(patientMinNumText.getText()).intValue();
                    int inc = new Integer(patientMaxNumText.getText()).intValue();
                    if (start + inc - 1 > patientSetSize) {
                        rightArrowButton.setEnabled(false);
                    }
                    //patientMinNumText.setText("" + (start + inc));
                    leftArrowButton.setEnabled(true);

                    PerformVisualizationQuery(oAwtContainer, patientRefId, min, max - 1, bDisplayAllData);
                }

                // getDisplay().syncExec(new Runnable() {
                // public void run() {
                // if(returnedNumber >= 0) {
                // //setDecreaseNumber(returnedNumber);
                // MessageBox mBox = new MessageBox(getShell(),
                // SWT.ICON_INFORMATION
                // | SWT.OK);
                // mBox.setText("Please Note ...");
                // mBox.setMessage(/*"Can't return all the requested "+
                // requestIndex+" patients, */"Only "+returnedNumber+"
                // patients returned");
                // mBox.open();
                // }
                // }
                // });
            } else {
                patientMinNumText.setText("1");
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    if (drawLeft) {
        horizontalForm.setWeights(new int[] { 30, 70 });
    }

    return parent;
}

From source file:edu.harvard.i2b2.explorer.ui.MainComposite.java

/**
 * @param args/*w w w.j  a va 2  s .c o  m*/
 */
@SuppressWarnings("serial")
protected Control createContents(Composite parent) {
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    setLayout(topGridLayout);

    Composite oTreeComposite = new Composite(this, SWT.NONE);
    oTreeComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    oTreeComposite.setLayoutData(gridData2);

    // the horizontal sash form
    SashForm horizontalForm = new SashForm(oTreeComposite, SWT.HORIZONTAL);
    horizontalForm.setOrientation(SWT.HORIZONTAL);
    horizontalForm.setLayout(new GridLayout());

    if (drawLeft) {
        // left sash form
        SashForm leftVerticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
        leftVerticalForm.setOrientation(SWT.VERTICAL);
        leftVerticalForm.setLayout(new GridLayout());

        if (bWantStatusLine) {
            slm.createControl(this, SWT.NULL);
        }
        slm.setMessage("i2b2 Explorer Version 2.0");
        slm.update(true);

        // Create the tab folder
        final TabFolder oTabFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        // Create each tab and set its text, tool tip text,
        // image, and control
        TabItem oTreeTab = new TabItem(oTabFolder, SWT.NONE);
        oTreeTab.setText("Concept trees");
        oTreeTab.setToolTipText("Hierarchically organized patient characteristics");
        oTreeTab.setControl(getConceptTreeTabControl(oTabFolder));

        // Select the first tab (index is zero-based)
        oTabFolder.setSelection(0);

        // Create the tab folder
        final TabFolder queryRunFolder = new TabFolder(leftVerticalForm, SWT.NONE);

        TabItem previousRunTab = new TabItem(queryRunFolder, SWT.NONE);
        previousRunTab.setText("Patient Sets and Previous Queries");
        previousRunTab.setToolTipText("Patient Sets & Previous Queries");
        final Composite runComposite = new Composite(queryRunFolder, SWT.EMBEDDED);
        previousRunTab.setControl(runComposite);

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame runFrame = SWT_AWT.new_Frame(runComposite);
        Panel runPanel = new Panel(new BorderLayout());
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        runFrame.add(runPanel);
        JRootPane runRoot = new JRootPane();
        runPanel.add(runRoot);

        // Select the first tab (index is zero-based)
        queryRunFolder.setSelection(0);
    }

    SashForm verticalForm = new SashForm(horizontalForm, SWT.VERTICAL);
    verticalForm.setOrientation(SWT.VERTICAL);
    verticalForm.setLayout(new GridLayout());

    // put a tab folder in it...
    tabFolder = new TabFolder(verticalForm, SWT.NONE);

    Composite patientNumsComposite = new Composite(verticalForm, SWT.NONE);
    GridData patientNumData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    patientNumData.grabExcessHorizontalSpace = true;
    patientNumsComposite.setLayoutData(patientNumData);
    patientNumsComposite.setLayout(null);

    Label patientset = new Label(patientNumsComposite, SWT.NONE);
    patientset.setText("Patient Set: ");
    patientset.setBounds(5, 9, 60, 22);

    patientSetText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientSetText.setText("");
    patientSetText.setEditable(false);
    patientSetText.setBounds(70, 5, 300, 35);

    leftArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    leftArrowButton.setText("<<<");
    leftArrowButton.setEnabled(false);
    leftArrowButton.setBounds(380, 5, 38, 22);
    leftArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            runMode = -1;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                int start = new Integer(patientMinNumText.getText()).intValue();
                int inc = new Integer(patientMaxNumText.getText()).intValue();
                if (start - inc <= 1) {
                    leftArrowButton.setEnabled(false);
                }

                if (start <= patientSetSize) {
                    rightArrowButton.setEnabled(true);
                } else {
                    rightArrowButton.setEnabled(false);
                }

                //if ((start - inc) > 1) {
                //patientMinNumText.setText("" + (start - inc));
                //} else {
                //patientMinNumText.setText("1");
                //}
                PerformVisualizationQuery(oAwtContainer, patientRefId, min - max, max - 1, bDisplayAllData);
            }

        }
    });

    final Label patNum1 = new Label(patientNumsComposite, SWT.NONE);
    patNum1.setText(" start: ");
    patNum1.setBounds(425, 9, 31, 20);

    patientMinNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMinNumText.setText("1");
    patientMinNumText.setBounds(460, 5, 45, 22);

    final Label patNum2 = new Label(patientNumsComposite, SWT.NONE);
    patNum2.setText("increment:");
    patNum2.setBounds(515, 9, 57, 20);

    patientMaxNumText = new Text(patientNumsComposite, SWT.SINGLE | SWT.BORDER);
    patientMaxNumText.setText("10");
    patientMaxNumText.setBounds(572, 5, 45, 22);

    rightArrowButton = new Button(patientNumsComposite, SWT.PUSH);
    rightArrowButton.setText(">>>");
    rightArrowButton.setEnabled(false);
    rightArrowButton.setBounds(626, 5, 38, 20);
    rightArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            runMode = 1;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            } else if (tabFolder.getSelectionIndex() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(1);
                    }
                });
            }

            if (patientSetStr.equalsIgnoreCase("All")) {
                int minPatient = 0;
                try {
                    String minText = patientMinNumText.getText();
                    minPatient = Integer.parseInt(minText);
                } catch (Exception e1) {
                    minPatient = -1;
                }

                int maxPatient = 0;
                try {
                    maxPatient = Integer.parseInt(patientMaxNumText.getText());
                } catch (Exception e2) {
                    maxPatient = -1;
                }

                PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
            } else {
                int min = Integer.parseInt(patientMinNumText.getText());
                int max = Integer.parseInt(patientMaxNumText.getText());
                int start = new Integer(patientMinNumText.getText()).intValue();
                int inc = new Integer(patientMaxNumText.getText()).intValue();
                if (start + inc > patientSetSize) {
                    rightArrowButton.setEnabled(false);
                }
                //patientMinNumText.setText("" + (start + inc));
                leftArrowButton.setEnabled(true);
                PerformVisualizationQuery(oAwtContainer, patientRefId, min, max - 1, bDisplayAllData);
            }
            // getDisplay().syncExec(new Runnable() {
            // public void run() {
            // if(returnedNumber >= 0) {
            // setIncrementNumber(returnedNumber);
            // MessageBox mBox = new MessageBox(getShell(),
            // SWT.ICON_INFORMATION
            // | SWT.OK);
            // mBox.setText("Please Note ...");
            // mBox.setMessage(/*"Can't return all the requested "+
            // requestIndex+" patients, */"Only "+returnedNumber+" patients
            // returned");
            // mBox.open();
            // }
            // }
            // });
        }
    });

    addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int w = getBounds().width;
            patientSetText.setBounds(70, 5, w - 357, 24);
            leftArrowButton.setBounds(w - 281, 5, 38, 24);
            patNum1.setBounds(w - 239, 9, 31, 24);
            patientMinNumText.setBounds(w - 204, 5, 45, 24);
            patNum2.setBounds(w - 149, 9, 57, 24);
            patientMaxNumText.setBounds(w - 92, 5, 45, 24);
            rightArrowButton.setBounds(w - 42, 5, 37, 24);
        }
    });

    verticalForm.setWeights(new int[] { 25, 3 });

    // Item 1: a Text Table
    TabItem item1 = new TabItem(tabFolder, SWT.NONE);
    item1.setText("Create model for Timeline");

    Composite oModelComposite = new Composite(tabFolder, SWT.NONE);
    item1.setControl(oModelComposite);

    GridLayout gridLayout = new GridLayout(2, false);

    // gridLayout.marginHeight = 0;
    // gridLayout.marginWidth = 0;
    // gridLayout.verticalSpacing = 0;
    // gridLayout.horizontalSpacing = 0;

    gridLayout.marginTop = 2;
    gridLayout.marginLeft = 0;
    gridLayout.marginBottom = 2;
    gridLayout.verticalSpacing = 1;
    gridLayout.horizontalSpacing = 1;
    oModelComposite.setLayout(gridLayout);

    oModelQueryComposite = new FramedComposite(oModelComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelQueryComposite.setLayout(new GridLayout(25, false));
    oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    GridData oModelQueryButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelQueryButtonGridData.grabExcessHorizontalSpace = false;
    oModelQueryButtonGridData.horizontalSpan = 2;
    oModelQueryButtonGridData.verticalAlignment = SWT.CENTER;
    oModelQueryButtonGridData.verticalIndent = 5;
    oModelQueryComposite.setLayoutData(oModelQueryButtonGridData);

    queryNamemrnlistText = new Label(oModelQueryComposite, SWT.NONE);
    queryNamemrnlistText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    queryNamemrnlistText.setText("Query Name: ");
    // queryNamemrnlistText.setBounds(5, 4, 600, 20);

    queryNamemrnlistText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    oModelQueryComposite.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent arg0) {

        }

    });

    oModelQueryComposite.addDragDetectListener(new DragDetectListener() {

        public void dragDetected(DragDetectEvent arg0) {

        }

    });

    Composite oGroupComposite = new Composite(oModelComposite, SWT.NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oGroupComposite.setLayout(gridLayout);
    GridData oGroupGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    oGroupGridData.grabExcessHorizontalSpace = true;
    oGroupGridData.grabExcessVerticalSpace = true;
    oGroupGridData.verticalIndent = 1;
    oGroupGridData.verticalSpan = GridData.VERTICAL_ALIGN_FILL;
    // oGroupGridData.verticalAlignment = GridData.VERTICAL_ALIGN_FILL;
    oGroupComposite.setLayoutData(oGroupGridData);

    oModelGroupComposite = new FramedComposite(oGroupComposite, SWT.SHADOW_NONE);
    // GridLayout gLq = new GridLayout(25, false);
    oModelGroupComposite.setLayout(new GridLayout(25, false));
    GridData oModelGroupButtonGridData = new GridData(GridData.FILL_HORIZONTAL);
    oModelGroupButtonGridData.grabExcessHorizontalSpace = false;
    oModelGroupButtonGridData.horizontalSpan = 2;
    oModelGroupButtonGridData.verticalAlignment = SWT.CENTER;
    oModelGroupButtonGridData.verticalIndent = 5;
    oModelGroupComposite.setLayoutData(oModelGroupButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel1 = new GridData(GridData.FILL_HORIZONTAL);

    groupNameText = new Label(oModelGroupComposite, SWT.NONE);
    gdDel1.horizontalSpan = 4;
    groupNameText.setLayoutData(gdDel1);
    groupNameText.setText("Panel Name: ");
    // groupNameText.setBounds(80, 8, 400, 24);
    // groupNameText.setAlignment(SWT.CENTER);
    // createDragSource(queryNamemrnlistText);
    // createDropTarget(queryNamemrnlistText);

    groupNameText.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        public void mouseExit(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void mouseHover(MouseEvent arg0) {
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

    });

    // put a table in tabItem1...
    table = new KTable(oGroupComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    table.setFocus();
    table.setBackground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGridData.verticalIndent = 5;
    table.setLayoutData(tableGridData);
    table.setRowSelectionMode(true);
    // table.setMultiSelectionMode(true);
    // table.setModel(new KTableForModel());
    table.setModel(new ConceptTableModel());
    // table.getModel().setColumnWidth(0, oModelComposite.getBounds().width
    // - 35);
    table.addCellSelectionListener(new KTableCellSelectionListener() {
        public void cellSelected(int col, int row, int statemask) {
            log.debug("Cell [" + col + ";" + row + "] selected.");
            // System.out.println("Cell [" + col + ";" + row +
            // "] selected.");
            table.selectedRow = row;
            table.selectedColumn = col;
        }

        public void fixedCellSelected(int col, int row, int statemask) {
            log.debug("Header [" + col + ";" + row + "] selected.");
            // System.out.println("Header [" + col + ";" + row +
            // "] selected.");
        }

    });

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

    // create drag source
    /*
     * DragSource source = new DragSource(queryNamemrnlistText,
     * DND.DROP_COPY); source.setTransfer(types); source.addDragListener(new
     * DragSourceAdapter() {
     * 
     * @Override public void dragSetData(DragSourceEvent event) {
     * //DragSource ds = (DragSource) event.widget; StringWriter strWriter =
     * new StringWriter(); DndType dndType = new DndType();
     * edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory
     * = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
     * PanelType panelType = new PanelType();
     * 
     * //get table rows and fill the panel object for(int i=0; i<3; i++) {
     * ItemType itemType = new ItemType();
     * panelType.getItem().add(itemType);
     * 
     * dndType.getAny().add(pdoFactory.createPanel(panelType));
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new
     * edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory(); try {
     * ExplorerJAXBUtil
     * .getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType),
     * strWriter); } catch(JAXBUtilException e) { e.printStackTrace(); }
     * 
     * //put the data into the event event.data = strWriter.toString(); }
     * 
     * 
     * });
     */

    Composite oModelAddDelButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL = new GridLayout(25, false);
    oModelAddDelButtonComposite.setLayout(gL);
    GridData oModelAddDelButtonGridData = new GridData(GridData.FILL_HORIZONTAL);// HORIZONTAL_ALIGN_FILL);// |
    // GridData.VERTICAL_ALIGN_FILL);
    oModelAddDelButtonGridData.grabExcessHorizontalSpace = false;
    oModelAddDelButtonGridData.horizontalSpan = 2;
    oModelAddDelButtonComposite.setLayoutData(oModelAddDelButtonGridData);

    // GridData gdAdd = new GridData(GridData.FILL_HORIZONTAL);
    GridData gdDel = new GridData(GridData.FILL_HORIZONTAL);

    Button deleteArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel.horizontalSpan = 4;
    deleteArrowButton.setLayoutData(gdDel);
    deleteArrowButton.setText("Delete From List");
    deleteArrowButton.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("unchecked")
        public void widgetSelected(SelectionEvent event) {
            curRowNumber = 0;
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);

            if ((selectedRow != null) && (selectedRow.length > 0)) {
                String conceptName = (String) m_Model.getContentAt(1, selectedRow[0]);
                if (conceptName.equals("Encounter Range Line")) {
                } else if (conceptName.equals("Vital Status Line")) {
                }

                int rowNumber = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue();
                int rid = selectedRow[0];
                ArrayList list = (ArrayList) rowData.get(rowNumber - 1);
                for (int i = 0; i < list.size(); i++) {
                    ConceptTableRow tr = (ConceptTableRow) list.get(i);
                    if (tr.rowId == rid) {
                        list.remove(i);
                        break;
                    }
                }
                if (list.size() == 0) {
                    rowData.remove(rowNumber - 1);
                }
                curRowNumber = rowData.size();
                resetRowNumber();
                // m_Model.deleteRow(selectedRow[0]);
                ((ConceptTableModel) table.getModel()).deleteAllRows();
                ((ConceptTableModel) table.getModel()).populateTable(rowData);
                /*
                 * int newRow = 0; for(int i=0; i<rowData.size(); i++) {
                 * ArrayList alist = (ArrayList) rowData.get(i); for(int
                 * j=0; j<alist.size(); j++) { TableRow r = (TableRow)
                 * alist.get(j); newRow++; r.rowId = newRow;
                 * table.getModel().setContentAt(0, newRow, new
                 * Integer(r.rowNumber).toString());
                 * table.getModel().setContentAt(1, newRow, r.conceptName);
                 * table.getModel().setContentAt(2, newRow, r.valueType);
                 * table.getModel().setContentAt(3, newRow, r.valueText);
                 * table.getModel().setContentAt(4, newRow, r.height);
                 * table.getModel().setContentAt(5, newRow, r.color);
                 * table.getModel().setContentAt(6, newRow, r.conceptXml); }
                 * }
                 */
                table.redraw();
                queryNamemrnlistText.setText("Query Name: ");
                groupNameText.setText("Panel Name: ");
            }
        }
    });

    Button deleteAllButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    deleteAllButton.setLayoutData(gdDel);
    deleteAllButton.setText("Delete All ");
    deleteAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            m_Model.deleteAllRows();
            curRowNumber = 0;
            rowData.clear();
            queryNamemrnlistText.setText("Query Name: ");
            groupNameText.setText("Panel Name: ");
            table.redraw();
        }
    });

    Button putInOrderButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    gdDel = new GridData(GridData.FILL_HORIZONTAL);
    gdDel.horizontalSpan = 4;
    putInOrderButton.setLayoutData(gdDel);
    putInOrderButton.setText("Put In Order ");
    putInOrderButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            curRowNumber = 0;
            m_Model.fillDataFromTable(rowData);

            Collections.sort(rowData, new Comparator<Object>() {
                @SuppressWarnings("unchecked")
                public int compare(Object o1, Object o2) {
                    int i1 = ((ConceptTableRow) ((ArrayList) o1).get(0)).rowNumber;
                    int i2 = ((ConceptTableRow) ((ArrayList) o2).get(0)).rowNumber;
                    if (i1 > i2) {
                        return 1;
                    } else if (i1 < i2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            m_Model.deleteAllRows();
            m_Model.populateTable(rowData);
            table.redraw();
        }
    });

    Button upArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    upArrowButton.setText("Move Up");
    upArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index < 1) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index - 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] - 1, true);
            table.redraw();
        }
    });

    Button downArrowButton = new Button(oModelAddDelButtonComposite, SWT.PUSH);
    downArrowButton.setText("Move Down");
    downArrowButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {

            ConceptTableModel m_Model = (ConceptTableModel) table.getModel();
            int[] selectedRow = table.getRowSelection();
            curRowNumber = 0;
            // KTableI2B2Model m_Model = (KTableI2B2Model) table.getModel();
            // int[] selectedRow = table.getRowSelection();
            m_Model.fillDataFromTable(rowData);
            int index = new Integer((String) (m_Model.getContentAt(0, selectedRow[0]))).intValue() - 1;
            if (index == (rowData.size() - 1)) {
                return;
            }
            if ((selectedRow != null) && (selectedRow.length > 0)) {
                // m_Model.moveRow(selectedRow[0], selectedRow[0] -1);
                ArrayList<ConceptTableRow> list = rowData.get(index);
                rowData.remove(index);
                rowData.add(index + 1, list);
                resetRowNumber();
                m_Model.populateTable(rowData);
            }
            table.setSelection(0, selectedRow[0] + 1, true);
            table.redraw();
        }
    });

    Composite oModelCheckButtonComposite = new Composite(oModelComposite, SWT.NONE);
    GridLayout gL1 = new GridLayout();
    gL1.numColumns = 20;
    oModelCheckButtonComposite.setLayout(gL1);
    GridData oModelCheckButtonGridData = new GridData();
    oModelCheckButtonGridData.horizontalSpan = 4;
    oModelCheckButtonGridData.verticalAlignment = GridData.FILL;
    oModelCheckButtonGridData.grabExcessHorizontalSpace = true;
    oModelCheckButtonGridData.horizontalAlignment = GridData.FILL;
    oModelCheckButtonComposite.setLayoutData(oModelCheckButtonGridData);

    Button displayOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayOrNotButton.setText("Display concepts with no data");
    displayOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // do something here- return null
            bDisplayAllData = !bDisplayAllData;
        }
    });

    Button displayDemographicsOrNotButton = new Button(oModelCheckButtonComposite, SWT.CHECK);
    displayDemographicsOrNotButton.setText("Display patient demographics");
    if ((System.getProperty("applicationName") != null)
            && System.getProperty("applicationName").equals("BIRN")) {
        displayDemographicsOrNotButton.setSelection(false);
        displayDemographicsOrNotButton.setEnabled(false);

        bDisplayDemographics = false;
    } else if ((System.getProperty("applicationName") == null)
            || System.getProperty("applicationName").equals("i2b2")) {
        displayDemographicsOrNotButton.setSelection(true);
    }
    displayDemographicsOrNotButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            bDisplayDemographics = !bDisplayDemographics;
        }
    });

    {
        label2 = new Label(oModelCheckButtonComposite, SWT.NONE);
        GridData label2LData = new GridData();
        label2LData.horizontalIndent = 10;
        label2.setLayoutData(label2LData);
        label2.setText("Filter:");
    }
    {
        filterCCombo = new CCombo(oModelCheckButtonComposite, SWT.BORDER);
        filterCCombo.setBackground(SWTResourceManager.getColor(255, 255, 255));
        filterCCombo.setEditable(false);
        filterCCombo.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent evt) {
                System.out.println("filterCCombo.widgetSelected, event=" + evt);
                int index = filterCCombo.getSelectionIndex();

                if (index == 0) {
                    filter = "none";
                } else if (index == 1) {
                    filter = "max";
                } else if (index == 2) {
                    filter = "min";
                } else if (index == 3) {
                    filter = "first";
                } else if (index == 4) {
                    filter = "last";
                }
            }
        });
        filterCCombo.add("none");
        filterCCombo.add("max");
        filterCCombo.add("min");
        filterCCombo.add("first");
        filterCCombo.add("last");
        filterCCombo.select(0);
    }
    {
        //combo1 = new Combo(oModelCheckButtonComposite, SWT.NONE);
    }
    {
        //label1 = new Label(oModelCheckButtonComposite, SWT.NONE);
        //label1.setText("Filter: ");
    }
    /*{
       filterCombo = new Combo(oModelCheckButtonComposite, SWT.NONE);
       GridData filterComboLData = new GridData();
       filterComboLData.widthHint = 28;
       filterComboLData.heightHint = 21;
       filterCombo.setLayoutData(filterComboLData);
       filterCombo.add("max");
       filterCombo.add("min");
       filterCombo.add("first");
       filterCombo.add("last");
       filterCombo.select(0);
       //filterCombo.set;
               
       //filterCombo.setText("combo1");
    }*/

    if (UserInfoBean.getInstance().getCellDataUrl("identity") != null) {
        Composite oPatientSetComposite = new Composite(oModelComposite, SWT.NONE);
        GridData patientSetData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        patientSetData.grabExcessHorizontalSpace = true;
        oPatientSetComposite.setLayoutData(patientSetData);
        oPatientSetComposite.setLayout(null);

        Label mrnlabel = new Label(oPatientSetComposite, SWT.NONE);
        mrnlabel.setText("MRN site:");
        mrnlabel.setBounds(5, 9, 50, 20);

        final Combo siteCombo = new Combo(oPatientSetComposite, SWT.NULL);
        siteCombo.add("BWH");
        siteCombo.add("MGH");
        siteCombo.setBounds(57, 5, 60, 20);
        siteCombo.select(1);

        Label mrnNumber = new Label(oPatientSetComposite, SWT.NONE);
        mrnNumber.setText("number:");
        mrnNumber.setBounds(121, 9, 40, 20);

        mrnlistText = new Text(oPatientSetComposite, SWT.SINGLE | SWT.BORDER);
        mrnlistText.setBounds(164, 5, 150, 20);
        mrnlistText.setText("");

        Button runButton = new Button(oPatientSetComposite, SWT.PUSH);
        runButton.setText("Search By MRN");
        runButton.setBounds(315, 5, 85, 23);
        runButton.addSelectionListener(new SelectionAdapter() {
            @SuppressWarnings("unchecked")
            public void widgetSelected(SelectionEvent event) {
                String mrns = mrnlistText.getText();
                if (mrns.equals("")) {
                    return;
                }

                String[] mrnArray = mrns.split(",");
                int[] idlist = new int[mrnArray.length];
                String username = UserInfoBean.getInstance().getUserName();
                String password = UserInfoBean.getInstance().getUserPassword();
                // log.debug("User name: "+username+" password: "+password);
                String site = siteCombo.getText();
                for (int i = 0; i < mrnArray.length; i++) {
                    // String[] tmps = new String[2];
                    String tmp = mrnArray[i].replaceAll(" ", "");
                    // tmps = tmp.split(":");

                    String queryStr = "<?xml version=\"1.0\" standalone=\"yes\"?>\n" + "<search_by_local>"
                            + "<match_id site=\"" + site.toUpperCase()/* EMPI */
                            + "\">" + tmp/* 100016900 */
                            + "</match_id>\n" + "</search_by_local>";

                    String resultStr = QueryClient.query(queryStr, username, password);
                    log.debug(queryStr);
                    log.debug(resultStr);

                    SAXBuilder parser = new SAXBuilder();
                    String masterID = null;
                    java.io.StringReader xmlStringReader = new java.io.StringReader(resultStr);
                    try {
                        org.jdom.Document tableDoc = parser.build(xmlStringReader);
                        org.jdom.Element tableXml = tableDoc.getRootElement();
                        Element responseXml = (Element) tableXml.getChild("person_list");
                        // Element mrnXml = (Element)
                        // responseXml.getChild("MRN");
                        java.util.List listChildren = responseXml.getChildren();
                        if (listChildren.isEmpty()) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage("No master id found");
                            mBox.open();
                            return;
                        }

                        Element masterXml = (Element) responseXml.getChild("master_record");
                        masterID = masterXml.getAttributeValue("id");
                        log.debug("Patient id: " + masterID);
                        idlist[i] = new Integer(masterID).intValue();
                        log.debug("MRN: " + site + "-" + tmp);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }

                if (tabFolder.getSelectionIndex() == 1) {
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            DestroyMiniVisualization(oAwtContainer);
                        }
                    });
                } else if (tabFolder.getSelectionIndex() == 0) {
                    oTheParent.getDisplay().syncExec(new Runnable() {
                        public void run() {
                            tabFolder.setSelection(1);
                        }
                    });
                }

                PerformVisualizationQuery(oAwtContainer, idlist, bDisplayAllData);
            }
        });
    }

    DropTarget targetLable = new DropTarget(oModelQueryComposite, DND.DROP_COPY);
    targetLable.setTransfer(types);
    targetLable.addDropListener(new DropTargetAdapter() {
        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
            oModelQueryComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                if (tableXml != null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                boolean isQuery = false;
                if (tableXml == null)
                    tableXml = tableDoc.getRootElement().getChild("query_master",
                            Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/"));

                if (tableXml != null)
                    isQuery = true;
                else {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = ExplorerJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText("Query Name: " + ndata.name());
                        groupNameText.setText("Panel Name: All items of Query " + ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP"))
                            xmlcontent = PDOQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        else
                            xmlcontent = PDOQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null)
                            return;
                        else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null)
                            log.debug("query definition not null");
                        else
                            log.error("query definition is null");

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();

                        int numOfPanels = queryDefinitionType.getPanel().size();
                        int conceptCount = 0;

                        if (queryDefinitionType.getSubquery().size() == 0) // it's a normal query
                            conceptCount = addQueryModel(queryDefinitionType, nodeXmls, conceptCount); // add concepts to nodeXmls, increment conceptCount
                        else if (queryDefinitionType.getSubquery().size() > 0) // temporal queries have subqueries
                        {
                            conceptCount = addQueryModel(queryDefinitionType, nodeXmls, conceptCount);
                            List<QueryDefinitionType> subqueries = queryDefinitionType.getSubquery();
                            for (QueryDefinitionType subQuery : subqueries)
                                conceptCount = addQueryModel(subQuery, nodeXmls, conceptCount); // for each subquery, add concepts to nodeXmls, increment conceptCount
                        }

                        if (nodeXmls.size() == 0) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage("No valid concept was found.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        String xmlResponse = PDOQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = PDOQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {

                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                String description = queryResultInstanceType.getDescription();
                                if (description != null) {
                                    patientSetText.setText(description);
                                } else {
                                    patientSetText.setText("Patient Set: " + setSize + " patients");
                                }
                                patientRefId = new String(setId);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } /*
                  * else { List conceptChildren = tableXml.getChildren();
                  * parseDropConcepts(conceptChildren, event);
                  * table.redraw(); }
                  */

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }
    });

    // create drag source
    DragSource source1 = new DragSource(groupNameText, DND.DROP_COPY);
    source1.setTransfer(types);
    source1.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragSetData(DragSourceEvent event) {

            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            StringWriter strWriter = new StringWriter();
            DndType dndType = new DndType();
            edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory pdoFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
            PanelType panelType = new PanelType();
            panelType.setInvert(0);
            PanelType.TotalItemOccurrences totalOccurrences = new PanelType.TotalItemOccurrences();
            totalOccurrences.setValue(1);
            panelType.setTotalItemOccurrences(totalOccurrences);
            panelType.setPanelNumber(0 + 1);
            // panelType.setName(panelData.getItems().get(0).name() + "_"
            // + generateMessageId().substring(0, 4));
            panelType.setName("Panel-1");

            // TO DO: get table rows and fill the panel object
            for (int i = 1; i < i2b2Model.getRowCount(); i++) {
                QueryModel node = (QueryModel) i2b2Model.getContentAt(7, i);
                ItemType itemType = new ItemType();
                itemType.setItemKey(node.fullname());
                itemType.setItemName(node.name());
                itemType.setTooltip(node.tooltip());
                itemType.setHlevel(Integer.parseInt(node.hlevel()));
                itemType.setClazz("ENC");
                itemType.setItemIcon(node.visualAttribute().trim());
                itemType.setItemColor(i2b2Model.getColorString((RGB) i2b2Model.getContentAt(5, i)));
                itemType.setItemRowNumber((String) i2b2Model.getContentAt(0, i));
                itemType.setItemShape((String) i2b2Model.getContentAt(4, i));

                itemType.getConstrainByValue().add(node.valueModel().writeValueConstraint());
                itemType.getConstrainByDate().add(node.writeTimeConstrain());

                panelType.getItem().add(itemType);
            }

            dndType.getAny().add(pdoFactory.createPanel(panelType));
            edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory dndFactory = new edu.harvard.i2b2.crcxmljaxb.datavo.dnd.ObjectFactory();
            try {
                ExplorerJAXBUtil.getJAXBUtil().marshaller(dndFactory.createPluginDragDrop(dndType), strWriter);
            } catch (JAXBUtilException e) {
                e.printStackTrace();
            }

            // put the data into the event
            event.data = strWriter.toString();
        }

    });

    DropTarget nameTarget = new DropTarget(groupNameText, DND.DROP_COPY);
    nameTarget.setTransfer(types);
    nameTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dragLeave(DropTargetEvent event) {
            super.dragLeave(event);
            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
        }

        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document panelDoc = parser.build(xmlStringReader);
                org.jdom.Element panelXml = panelDoc.getRootElement().getChild("panel",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/querydefinition/1.1/"));

                if (panelXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                else {

                    String domString = (new XMLOutputter()).outputString(panelXml);
                    JAXBContext jc1 = JAXBContext
                            .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                    Unmarshaller unMarshaller = jc1.createUnmarshaller();
                    JAXBElement panelJaxbElement = (JAXBElement) unMarshaller
                            .unmarshal(new StringReader(domString));

                    PanelType panelType = (PanelType) panelJaxbElement.getValue();
                    String panelname = panelType.getName();
                    groupNameText.setText("Panel Name: " + panelname);
                    queryNamemrnlistText.setText("Query Name: ");
                    for (int j = 0; j < panelType.getItem().size(); j++) {
                        ItemType itemType = panelType.getItem().get(j);
                        QueryModel nodedata = new QueryModel();

                        nodedata.name(itemType.getItemName());
                        nodedata.visualAttribute("FA");
                        nodedata.tooltip(itemType.getTooltip());
                        nodedata.fullname(itemType.getItemKey());
                        nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                        // / need to handle query tool generated panels
                        if (itemType.getItemShape() != null) {
                            nodedata.tableRow().height = new String(itemType.getItemShape());
                            nodedata.tableRow().color = ((ConceptTableModel) table.getModel())
                                    .getColor(itemType.getItemColor());
                            nodedata.tableRow().rowNumber = Integer.parseInt(itemType.getItemRowNumber());
                        } else {
                            nodedata.tableRow().height = "Medium";
                            nodedata.tableRow().color = getRGBfromList(curRowNumber);//new RGB(0, 0, 128);
                            nodedata.tableRow().rowNumber = j + 1;
                        }

                        nodedata.constrainByValue(itemType.getConstrainByValue());
                        if (itemType.getConstrainByValue().size() > 0) {
                            nodedata.setValueConstrains(itemType.getConstrainByValue());

                            if (itemType.getConstrainByValue().size() > 0) {
                                nodedata.setValueConstrains(itemType.getConstrainByValue());
                                if (nodedata.valueModel().hasEnumValue()) {
                                    if (nodedata.valueModel().useTextValue()) {
                                        ArrayList<String> results = new ArrayList<String>();
                                        results.toArray(nodedata.valueModel().value().split(","));
                                        nodedata.valueModel().selectedValues = results;
                                    }
                                }
                            }
                        }

                        // Handle Constrain By Dates
                        for (int u = 0; u < itemType.getConstrainByDate().size(); u++) {
                            nodedata.setTimeConstrain(itemType.getConstrainByDate().get(u).getDateFrom(),
                                    itemType.getConstrainByDate().get(u).getDateTo());
                        }

                        String status = nodedata.setXmlContent();
                        if (status.equalsIgnoreCase("error")) {
                            MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                            mBox.setText("Please Note ...");
                            mBox.setMessage(
                                    "Response delivered from the remote server could not be understood,\n"
                                            + "you may wish to retry your last action.");
                            mBox.open();
                            event.detail = DND.DROP_NONE;

                            return;
                        }
                        nodeXmls.add(nodedata);
                    }
                    // event.detail = DND.DROP_NONE;
                }
                populateTable(nodeXmls);

            }

            catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            if (textTransfer.isSupportedType(event.currentDataType)) {

                event.detail = DND.DROP_COPY;
            }

            oModelGroupComposite.setForeground(oTheParent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        }
    });

    DropTarget target = new DropTarget(table, DND.DROP_COPY);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            try {
                SAXBuilder parser = new SAXBuilder();
                String xmlContent = (String) event.data;
                java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
                org.jdom.Document tableDoc = parser.build(xmlStringReader);
                org.jdom.Element tableXml = tableDoc.getRootElement().getChild("concepts",
                        Namespace.getNamespace("http://www.i2b2.org/xsd/cell/ont/1.1/"));

                boolean isQuery = false;
                if (tableXml == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    return;
                }

                if (isQuery) {
                    ArrayList<QueryModel> nodeXmls = new ArrayList<QueryModel>();
                    try {
                        JAXBUtil jaxbUtil = ExplorerJAXBUtil.getJAXBUtil();
                        QueryMasterData ndata = new QueryMasterData();
                        ndata.name(tableXml.getChildText("name"));
                        queryNamemrnlistText.setText(ndata.name());
                        ndata.xmlContent(null);
                        ndata.id(tableXml.getChildTextTrim("query_master_id"));
                        ndata.userId(tableXml.getChildTextTrim("user_id"));

                        String xmlcontent = null;
                        String xmlrequest = null;

                        xmlrequest = ndata.writeDefinitionQueryXML();
                        lastRequestMessage(xmlrequest);

                        if (System.getProperty("webServiceMethod").equals("SOAP")) {
                            xmlcontent = PDOQueryClient.sendPDQQueryRequestSOAP(xmlrequest);
                        } else {
                            xmlcontent = PDOQueryClient.sendPDQQueryRequestREST(xmlrequest);
                        }
                        lastResponseMessage(xmlcontent);

                        if (xmlcontent == null) {

                            return;
                        } else {
                            log.debug("Query content response: " + xmlcontent);
                            ndata.xmlContent(xmlcontent);
                        }

                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(ndata.xmlContent());
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                        BodyType bt = messageType.getMessageBody();
                        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), MasterResponseType.class);
                        RequestXmlType requestXmlType = masterResponseType.getQueryMaster().get(0)
                                .getRequestXml();

                        org.w3c.dom.Element element = (org.w3c.dom.Element) requestXmlType.getContent().get(0);
                        if (element != null) {
                            log.debug("query definition not null");
                        } else {
                            log.error("query definition is null");
                        }

                        String domString = edu.harvard.i2b2.common.util.xml.XMLUtil
                                .convertDOMElementToString(element);
                        log.debug("string output" + domString);

                        JAXBContext jc1 = JAXBContext
                                .newInstance(edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory.class);
                        Unmarshaller unMarshaller = jc1.createUnmarshaller();
                        JAXBElement queryDefinitionJaxbElement = (JAXBElement) unMarshaller
                                .unmarshal(new StringReader(domString));

                        QueryDefinitionType queryDefinitionType = (QueryDefinitionType) queryDefinitionJaxbElement
                                .getValue();
                        int numOfPanels = queryDefinitionType.getPanel().size();
                        for (int i = 0; i < numOfPanels; i++) {
                            PanelType panelType = queryDefinitionType.getPanel().get(i);

                            for (int j = 0; j < panelType.getItem().size(); j++) {
                                ItemType itemType = panelType.getItem().get(j);
                                QueryModel nodedata = new QueryModel();

                                nodedata.name(itemType.getItemName());
                                nodedata.visualAttribute("FA");
                                nodedata.tooltip(itemType.getTooltip());
                                nodedata.fullname(itemType.getItemKey());
                                nodedata.hlevel(new Integer(itemType.getHlevel()).toString());

                                String status = nodedata.setXmlContent();
                                if (status.equalsIgnoreCase("error")) {
                                    MessageBox mBox = new MessageBox(table.getShell(),
                                            SWT.ICON_INFORMATION | SWT.OK);
                                    mBox.setText("Please Note ...");
                                    mBox.setMessage(
                                            "Response delivered from the remote server could not be understood,\n"
                                                    + "you may wish to retry your last action.");
                                    mBox.open();
                                    event.detail = DND.DROP_NONE;

                                    return;
                                }
                                nodeXmls.add(nodedata);
                            }
                        }
                        populateTable(nodeXmls);

                        // get query instance
                        String xmlRequest = ndata.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);
                        // log.debug(xmlRequest);
                        String xmlResponse = PDOQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                        QueryInstanceData instanceData = null;
                        XMLGregorianCalendar startDate = null;
                        for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                            QueryInstanceData runData = new QueryInstanceData();

                            runData.visualAttribute("FA");
                            runData.tooltip("The results of the query run");
                            runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                            XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                            runData.name("Results of " + "[" + cldr.getMonth() + "-" + cldr.getDay() + "-"
                                    + cldr.getYear() + " " + cldr.getHour() + ":" + cldr.getMinute() + ":"
                                    + cldr.getSecond() + "]");

                            if (instanceData == null) {
                                startDate = cldr;
                                instanceData = runData;
                            } else {
                                if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) {
                                    startDate = cldr;
                                    instanceData = runData;
                                }
                            }
                        }
                        // get patient set
                        if (instanceData == null) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        log.debug("Got query instance: " + instanceData.name());

                        xmlRequest = instanceData.writeContentQueryXML();
                        lastRequestMessage(xmlRequest);

                        xmlResponse = PDOQueryClient.sendPDQQueryRequestREST(xmlRequest);
                        lastResponseMessage(xmlResponse);

                        jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                        messageType = (ResponseMessageType) jaxbElement.getValue();
                        bt = messageType.getMessageBody();
                        ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                                .getObjectByClass(bt.getAny(), ResultResponseType.class);

                        for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                                .getQueryResultInstance()) {
                            if (!(queryResultInstanceType.getQueryResultType().getName()
                                    .equalsIgnoreCase("PATIENTSET"))) {
                                continue;
                            }

                            String status = queryResultInstanceType.getQueryStatusType().getName();

                            if (status.equalsIgnoreCase("FINISHED")) {
                                // resultData.name("Patient Set - "+resultData
                                // .patientCount()+" Patients");
                                // QueryResultData resultData = new
                                // QueryResultData();
                                String setId = new Integer(queryResultInstanceType.getResultInstanceId())
                                        .toString();
                                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                                patientSetText.setText("Patient Set: " + setSize + " patients");// strs[0]);
                                patientRefId = new String(setId);// strs[1]);
                                patientMinNumText.setText("1");
                                leftArrowButton.setEnabled(false);

                                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                                patientSetSize = queryResultInstanceType.getSetSize();
                                if (patientSetSize > maxPatientNum) {
                                    rightArrowButton.setEnabled(true);
                                    patientMaxNumText.setText("10");
                                } else {
                                    rightArrowButton.setEnabled(false);
                                    if (patientSetSize > 0) {
                                        patientMaxNumText.setText(setSize);
                                    }
                                }

                                log.debug("Dropped set of: " + setSize + " patients"/* strs[0] */
                                        + " with refId: " + setId/*
                                                                 * strs[ 1 ]
                                                                 */);
                            } else {
                                // message
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } else {
                    List conceptChildren = tableXml.getChildren();
                    parseDropConcepts(conceptChildren, event);
                    // System.setProperty("XMLfrommodel",(String)
                    // event.data);
                    table.redraw();
                    queryNamemrnlistText.setText("Query Name: ");
                    groupNameText.setText("Panel Name: ");
                }

                event.detail = DND.DROP_NONE;
            } catch (JDOMException e) {
                System.err.println(e.getMessage());
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                event.detail = DND.DROP_NONE;
                e.printStackTrace();
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    DropTarget target1 = new DropTarget(patientSetText, DND.DROP_COPY);
    target1.setTransfer(types);
    target1.addDropListener(new DropTargetAdapter() {
        @SuppressWarnings("unchecked")
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            String tmp = patientSetText.getText();
            String dragStr = (String) event.data;
            String[] strs = dragStr.split(":");
            if (strs[0].equalsIgnoreCase("logicquery")) {
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                mBox.open();
                event.detail = DND.DROP_NONE;
                patientSetText.setText(tmp);
                return;
            }

            JAXBUtil jaxbUtil = ExplorerJAXBUtil.getJAXBUtil();

            try {
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(dragStr);
                DndType dndType = (DndType) jaxbElement.getValue();
                QueryResultInstanceType queryResultInstanceType = (QueryResultInstanceType) new JAXBUnWrapHelper()
                        .getObjectByClass(dndType.getAny(), QueryResultInstanceType.class);

                if (queryResultInstanceType == null) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String resultTypeName = queryResultInstanceType.getQueryResultType().getName();
                if (resultTypeName == null || !resultTypeName.equalsIgnoreCase("PATIENTSET")) {
                    MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                    mBox.setText("Please Note ...");
                    mBox.setMessage("You can not drop this item here. It accepts a patient set only.");
                    mBox.open();
                    event.detail = DND.DROP_NONE;
                    patientSetText.setText(tmp);
                    return;
                }

                String setId = queryResultInstanceType.getResultInstanceId();
                String setSize = new Integer(queryResultInstanceType.getSetSize()).toString();
                patientSetText.setText(queryResultInstanceType.getDescription());// "Patient Set: " + setSize
                // + " patients");// strs[0]);
                patientRefId = new String(setId);// strs[1]);
                patientMinNumText.setText("1");
                leftArrowButton.setEnabled(false);
                queryNamemrnlistText.setText("Query Name: ");
                // groupNameText.setText("Panel Name: ");

                int maxPatientNum = new Integer(patientMaxNumText.getText()).intValue();
                patientSetSize = queryResultInstanceType.getSetSize();
                if (patientSetSize > maxPatientNum) {
                    rightArrowButton.setEnabled(true);
                    patientMaxNumText.setText("10");
                } else {
                    rightArrowButton.setEnabled(false);
                    // if(patientSetSize>0) {
                    // patientMaxNumText.setText(setSize);
                    // }
                }

                log.debug("Dropped set of: " + setSize + " patients"/*
                                                                    * strs[0
                                                                    * ]
                                                                    */
                        + " with refId: " + setId/* strs[1] */);
            } catch (Exception e) {
                e.printStackTrace();
                event.detail = DND.DROP_NONE;
                return;
            }
        }

        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }
    });

    table.addCellResizeListener(new KTableCellResizeListener() {
        public void columnResized(int col, int newWidth) {
            log.debug("Column " + col + " resized to " + newWidth);
        }

        public void rowResized(int newHeight) {
            log.debug("Rows resized to " + newHeight);
        }

    });

    table.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            int tableWidth = table.getBounds().width;
            table.getModel().setColumnWidth(1, tableWidth - 505);
        }
    });

    table.addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent arg0) {

        }

        public void mouseExit(MouseEvent arg0) {

        }

        public void mouseHover(MouseEvent arg0) {
            MouseEvent evt = arg0;

            Rectangle rect = table.getCellRect(3, getRowNumber());
            Rectangle rect1 = table.getCellRect(5, 1);

            // System.out.println("rect X and width: "+rect.x+","+rect.width)
            // ;
            // System.out.println("mouse X and Y: "+evt.x+","+evt.y);
            if (evt.y < rect.y && evt.x > rect1.x && evt.x < rect1.x + rect1.width) {
                table.setToolTipText("Double click the cell to change color.");
            } else {
                table.setToolTipText("");
            }
        }

    });

    // Item 2: a Color Palette
    TabItem item2 = new TabItem(tabFolder, SWT.NONE);
    item2.setText("Render a Timeline");
    final Composite comp2 = new Composite(tabFolder, SWT.NONE);
    item2.setControl(comp2);

    GridLayout oGridLayout0 = new GridLayout();
    oGridLayout0.marginWidth = 1;
    oGridLayout0.marginHeight = 5;
    comp2.setLayout(oGridLayout0);

    if (false) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);

        /*
         * Set a Windows specific AWT property that prevents heavyweight
         * components from erasing their background. Note that this is a
         * global property and cannot be scoped. It might not be suitable
         * for your application.
         */
        try {
            // System.setProperty("sun.awt.noerasebackground", "true");
        } catch (NoSuchMethodError error) {
        }

        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout()) {
            public void update(java.awt.Graphics g) {
                /* Do not erase the background */
                paint(g);
            }
        };
        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        java.awt.Container contentPane = root.getContentPane();
        log.debug("got to here");

        Record record1 = new Record();
        // record1.start();
        record1.init();

        JScrollPane scrollPane = new JScrollPane(record1);
        contentPane.setLayout(new BorderLayout());
        contentPane.add(scrollPane);
    }

    if (true) {
        Composite composite = new Composite(comp2, SWT.NO_BACKGROUND | SWT.EMBEDDED);
        GridData gridData3 = new GridData();
        gridData3.horizontalIndent = 0;
        gridData3.verticalIndent = 0;
        gridData3.horizontalAlignment = GridData.FILL;
        gridData3.verticalAlignment = GridData.FILL;
        gridData3.grabExcessHorizontalSpace = true;
        gridData3.grabExcessVerticalSpace = true;
        composite.setLayoutData(gridData3);
        /* Create and setting up frame */
        ////for mac fix
        //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
        //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout());// {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.debug("Error setting native LAF: " + e);
        }

        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        oAwtContainer = root.getContentPane();
        log.debug("got to here");
    }

    tabFolder.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            runMode = 0;
            ConceptTableModel i2b2Model = (ConceptTableModel) table.getModel();
            i2b2Model.fillDataFromTable(rowData);
            if (rowData.size() == 0) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("The set up table is empty.");
                mBox.open();
                return;
            }

            String patientSetStr = patientSetText.getText();
            if (patientSetStr.equals("") && !isAll) {
                oTheParent.getDisplay().syncExec(new Runnable() {
                    public void run() {
                        tabFolder.setSelection(0);
                    }
                });
                MessageBox mBox = new MessageBox(table.getShell(), SWT.ICON_INFORMATION | SWT.OK);
                mBox.setText("Please Note ...");
                mBox.setMessage("Please set a patient set or choose all datamart option.");
                mBox.open();
                return;
            }

            if (tabFolder.getSelectionIndex() == 1) {
                if (patientSetStr.equalsIgnoreCase("All")) {
                    int minPatient = 0;
                    try {
                        String minText = patientMinNumText.getText();
                        minPatient = Integer.parseInt(minText);
                    } catch (Exception e1) {
                        minPatient = -1;
                    }

                    int maxPatient = 0;
                    try {
                        maxPatient = Integer.parseInt(patientMaxNumText.getText());
                    } catch (Exception e2) {
                        maxPatient = -1;
                    }
                    PerformVisualizationQuery(oAwtContainer, "All", minPatient, maxPatient, bDisplayAllData);
                } else {
                    int min = Integer.parseInt(patientMinNumText.getText());
                    int max = Integer.parseInt(patientMaxNumText.getText());
                    int start = new Integer(patientMinNumText.getText()).intValue();
                    int inc = new Integer(patientMaxNumText.getText()).intValue();
                    if (start + inc - 1 > patientSetSize) {
                        rightArrowButton.setEnabled(false);
                    }
                    //patientMinNumText.setText("" + (start + inc));
                    leftArrowButton.setEnabled(true);

                    PerformVisualizationQuery(oAwtContainer, patientRefId, min, max - 1, bDisplayAllData);
                }

                // getDisplay().syncExec(new Runnable() {
                // public void run() {
                // if(returnedNumber >= 0) {
                // //setDecreaseNumber(returnedNumber);
                // MessageBox mBox = new MessageBox(getShell(),
                // SWT.ICON_INFORMATION
                // | SWT.OK);
                // mBox.setText("Please Note ...");
                // mBox.setMessage(/*"Can't return all the requested "+
                // requestIndex+" patients, */"Only "+returnedNumber+"
                // patients returned");
                // mBox.open();
                // }
                // }
                // });
            } else {
                patientMinNumText.setText("1");
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DestroyMiniVisualization(oAwtContainer);
                    }
                });
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    if (drawLeft) {
        horizontalForm.setWeights(new int[] { 30, 70 });
    }

    return parent;
}

From source file:edu.harvard.i2b2.eclipse.plugins.admin.utilities.views.PatientCountView.java

private void setPassword() {
    if (right != null && !right.isDisposed()) {
        right.dispose();/*from  www .ja  v a 2 s  .  c  o m*/
        right = null;
    }

    right = new Composite(composite, SWT.NONE);
    GridLayout rightLayout1 = new GridLayout();
    GridData rightLData = new GridData();
    rightLData.grabExcessHorizontalSpace = true;
    rightLData.grabExcessVerticalSpace = true;
    rightLData.horizontalAlignment = GridData.FILL;
    rightLData.verticalAlignment = GridData.FILL;
    right.setLayoutData(rightLData);
    right.setLayout(rightLayout1);
    GridData composite1LData = new GridData();
    composite1LData.grabExcessHorizontalSpace = true;
    composite1LData.grabExcessVerticalSpace = true;
    composite1LData.horizontalAlignment = GridData.FILL;
    composite1LData.verticalAlignment = GridData.FILL;

    composite1 = new Composite(right, SWT.EMBEDDED);
    composite1.setLayoutData(composite1LData);

    /* Create and setting up frame */
    ////for mac fix
    //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
    //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";

    Frame runFrame = SWT_AWT.new_Frame(composite1);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e1) {
        System.out.println("Error setting native LAF: " + e1);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    java.awt.Container oAwtContainer = runRoot.getContentPane();

    AdminToolSetPasswordJPanel runTreePanel = new AdminToolSetPasswordJPanel();//PatientMappingJPanel();//PreviousQueryPanel(this);
    //runTreePanel.setBackground(Color.BLUE);

    oAwtContainer.add(runTreePanel);
    //oAwtContainer.setVisible(true);
    //oAwtContainer.setSize(500, 500);

    //right.layout(true);
    //right.setVisible(true);
    //right.update();

    composite.layout(true);
    //composite.setVisible(true);
    //composite.update();
}

From source file:edu.harvard.i2b2.eclipse.plugins.admin.utilities.views.PatientCountView.java

private void setKey() {
    if (right != null && !right.isDisposed()) {
        right.dispose();/*from   w  w w. j  a v a 2s.  c om*/
        right = null;
    }

    right = new Composite(composite, SWT.NONE);
    GridLayout rightLayout1 = new GridLayout();
    GridData rightLData = new GridData();
    rightLData.grabExcessHorizontalSpace = true;
    rightLData.grabExcessVerticalSpace = true;
    rightLData.horizontalAlignment = GridData.FILL;
    rightLData.verticalAlignment = GridData.FILL;
    right.setLayoutData(rightLData);
    right.setLayout(rightLayout1);
    GridData composite1LData = new GridData();
    composite1LData.grabExcessHorizontalSpace = true;
    composite1LData.grabExcessVerticalSpace = true;
    composite1LData.horizontalAlignment = GridData.FILL;
    composite1LData.verticalAlignment = GridData.FILL;

    composite1 = new Composite(right, SWT.EMBEDDED);
    composite1.setLayoutData(composite1LData);

    /* Create and setting up frame */
    ////for mac fix
    //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
    //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
    Frame runFrame = SWT_AWT.new_Frame(composite1);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e1) {
        System.out.println("Error setting native LAF: " + e1);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    java.awt.Container oAwtContainer = runRoot.getContentPane();

    AdminToolSetKeyJPanel runTreePanel = new AdminToolSetKeyJPanel();//PatientMappingJPanel();//PreviousQueryPanel(this);
    //runTreePanel.setBackground(Color.BLUE);

    oAwtContainer.add(runTreePanel);
    //oAwtContainer.setVisible(true);
    //oAwtContainer.setSize(500, 500);

    //right.layout(true);
    //right.setVisible(true);
    //right.update();

    composite.layout(true);
    //composite.setVisible(true);
    //composite.update();
}