Example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement.

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.hangum.tadpole.manager.core.editor.resource.ResourceManageEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 1;/* www .j a  va 2 s .com*/
    gl_parent.marginHeight = 1;
    gl_parent.horizontalSpacing = 1;
    gl_parent.marginWidth = 1;
    parent.setLayout(gl_parent);

    Composite compositeToolbar = new Composite(parent, SWT.NONE);
    compositeToolbar.setLayout(new GridLayout(1, false));
    compositeToolbar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    ToolBar toolBar = new ToolBar(compositeToolbar, SWT.FLAT | SWT.RIGHT);
    GridData gd_toolBar = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_toolBar.widthHint = 267;
    toolBar.setLayoutData(gd_toolBar);

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setToolTipText("Refresh");
    tltmRefresh.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/refresh.png")); //$NON-NLS-1$
    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            comboViewer.getCombo().clearSelection();
            textTitle.setText("");
            textDescription.setText("");
            textQuery.setText("");

            initUI();
            //reLoadResource();
        }
    });

    SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    columnFilter = new DefaultTableColumnFilter();

    SashForm sashForm_1 = new SashForm(sashForm, SWT.NONE);

    treeViewer = new TreeViewer(sashForm_1, SWT.BORDER);
    Tree treeDatabase = treeViewer.getTree();
    treeDatabase.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);

    Composite composite_1 = new Composite(sashForm_1, SWT.NONE);
    composite_1.setLayout(new GridLayout(1, false));

    Composite composite_2 = new Composite(composite_1, SWT.NONE);
    composite_2.setLayout(new GridLayout(2, false));
    GridData gd_composite_2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_composite_2.heightHint = 28;
    composite_2.setLayoutData(gd_composite_2);

    Label lblFilter = new Label(composite_2, SWT.NONE);
    lblFilter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblFilter.setText("Filter");

    textFilter = new Text(composite_2, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SEARCH | SWT.CANCEL);
    textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textFilter.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.Selection) {
                columnFilter.setSearchString(textFilter.getText());
                tableViewer.refresh();
            }
        }
    });

    tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION);
    tableResource = tableViewer.getTable();
    tableResource.setHeaderVisible(true);
    tableResource.setLinesVisible(true);
    tableResource.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    sashForm_1.setWeights(new int[] { 230, 359 });
    tableViewer.addFilter(columnFilter);

    Group grpQuery = new Group(sashForm, SWT.NONE);
    grpQuery.setText("Query");
    GridLayout gl_grpQuery = new GridLayout(1, false);
    gl_grpQuery.verticalSpacing = 1;
    gl_grpQuery.horizontalSpacing = 1;
    gl_grpQuery.marginHeight = 1;
    gl_grpQuery.marginWidth = 1;
    grpQuery.setLayout(gl_grpQuery);

    Composite composite = new Composite(grpQuery, SWT.NONE);
    GridLayout gl_composite = new GridLayout(6, false);
    gl_composite.marginHeight = 2;
    gl_composite.marginWidth = 2;
    gl_composite.verticalSpacing = 2;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Label lblNewLabel = new Label(composite, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel.setText("Share");

    comboViewer = new ComboViewer(composite, SWT.NONE);
    comboShare = comboViewer.getCombo();
    comboShare.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboShare.setItems(new String[] { "PUBLIC", "PRIVATE" });

    Label lblNewLabel_1 = new Label(composite, SWT.NONE);
    lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel_1.setText("Title");

    textTitle = new Text(composite, SWT.BORDER);
    textTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnSave = new Button(composite, SWT.NONE);
    btnSave.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // TODO : SAVE... ?  .
            if (tableViewer.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            ResourceManagerDAO dao = (ResourceManagerDAO) ss.getFirstElement();

            try {
                String share_type = comboShare.getText();
                share_type = (share_type == null || "".equals(share_type)) ? "PUBLIC" : share_type;
                dao.setShared_type(share_type);
                dao.setRes_title(textTitle.getText());
                dao.setDescription(textDescription.getText());
                TadpoleSystem_UserDBResource.updateResourceHeader(dao);
                //reLoadResource();
                addUserResouceData();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });
    btnSave.setText("Save");

    Button btnDelete = new Button(composite, SWT.NONE);
    btnDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // TODO : DELYN SET TO 'YES'
            if (tableViewer.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            ResourceManagerDAO dao = (ResourceManagerDAO) ss.getFirstElement();

            // ? ?  (?)?   ? ? dao ?   ?
            // .
            UserDBResourceDAO userDBResource = new UserDBResourceDAO();
            userDBResource.setResource_seq((int) dao.getResource_seq());
            userDBResource.setName(dao.getRes_title());
            userDBResource.setParent(userDB);

            try {
                TadpoleSystem_UserDBResource.delete(userDBResource);
            } catch (Exception e1) {
                logger.error("Resource delete " + dao.toString(), e1);
            }
        }
    });
    btnDelete.setText("Delete");

    Label lblDescription = new Label(composite, SWT.NONE);
    lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDescription.setText("Description");

    textDescription = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.CANCEL | SWT.MULTI);
    GridData gd_textDescription = new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1);
    gd_textDescription.heightHint = 44;
    textDescription.setLayoutData(gd_textDescription);

    textQuery = new Text(composite,
            SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    textQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1));
    sashForm.setWeights(new int[] { 179, 242 });

    createTableColumn();

    initUI();

}

From source file:com.hangum.tadpole.manager.core.editor.resource.ResourceManageEditor.java

License:Open Source License

public void initUI() {
    treeViewer.setContentProvider(new ResourceManagerContentProvider());
    treeViewer.setLabelProvider(new ResourceManagerLabelProvider());
    treeViewer.setInput(treeList);//from   w  ww  . j  a v a2 s  .  co  m
    getSite().setSelectionProvider(treeViewer);

    treeViewer.getTree().clearAll(true);
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection is = (IStructuredSelection) event.getSelection();
            if (is.getFirstElement() instanceof UserDBDAO) {
                userDB = (UserDBDAO) is.getFirstElement();
                addUserResouceData();
            }

            //
            //  (managerTV.getControl().setFocus();) , ? ??
            // event listener ? .
            // ?  .
            //
            treeViewer.getControl().setFocus();
        }
    });

    tableViewer.setInput(null);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {

            if (tableViewer.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            ResourceManagerDAO dao = (ResourceManagerDAO) ss.getFirstElement();

            try {
                SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
                List<String> result = sqlClient.queryForList("userDbResourceData", dao); //$NON-NLS-1$

                comboShare.select("PUBLIC".equals(dao.getShared_type()) ? 0 : 1);
                textTitle.setText(dao.getRes_title());
                textDescription.setText(dao.getDescription());
                textQuery.setText("");
                for (String data : result) {
                    textQuery.append(data);
                }

            } catch (Exception e) {
                logger.error("Resource detail", e);
            }

        }
    });

    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (tableViewer.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            ResourceManagerDAO dao = (ResourceManagerDAO) ss.getFirstElement();

            //  ??? ??     DAO   ?  .
            // TODO : DAO    ?.
            UserDBResourceDAO ad = new UserDBResourceDAO();
            ad.setResource_seq((int) dao.getResource_seq());
            ad.setName(dao.getRes_title());
            ad.setParent(userDB);

            // db object ?  ? ??.
            if (PublicTadpoleDefine.RESOURCE_TYPE.ERD.toString().equals(dao.getResource_types())) {
                if (userDB != null && DBDefine.MONGODB_DEFAULT == DBDefine.getDBDefine(userDB)) {
                    MongoDBERDViewAction ea = new MongoDBERDViewAction();
                    ea.run(ad);
                } else {
                    RDBERDViewAction ea = new RDBERDViewAction();
                    ea.run(ad);
                }
            } else if (PublicTadpoleDefine.RESOURCE_TYPE.SQL.toString().equals(dao.getResource_types())) {
                QueryEditorAction qea = new QueryEditorAction();
                qea.run(ad);
            }
        }
    });
    reLoadResource();

    // google analytic
    AnalyticCaller.track(ResourceManageEditor.ID);
}

From source file:com.hangum.tadpole.manager.core.editor.restfulapi.RESTFulAPIManagerEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    Composite compositeHead = new Composite(parent, SWT.NONE);
    compositeHead.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    compositeHead.setLayout(new GridLayout(1, false));

    ToolBar toolBar = new ToolBar(compositeHead, SWT.FLAT | SWT.RIGHT);

    ToolItem tltmRefrsh = new ToolItem(toolBar, SWT.NONE);
    tltmRefrsh.setToolTipText(Messages.get().Refresh);
    tltmRefrsh.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/refresh.png")); //$NON-NLS-1$
    tltmRefrsh.addSelectionListener(new SelectionAdapter() {
        @Override// ww  w .  j a v a2 s  .co m
        public void widgetSelected(SelectionEvent e) {
            initUI();
        }
    });

    ToolItem tltmAPIExecute = new ToolItem(toolBar, SWT.NONE);
    tltmAPIExecute.setToolTipText(Messages.get().RESTFulAPIManagerEditor_3);
    tltmAPIExecute.setImage(ResourceManager.getPluginImage(com.hangum.tadpole.manager.core.Activator.PLUGIN_ID,
            "resources/icons/restful_api.png")); //$NON-NLS-1$
    tltmAPIExecute.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            UserAPIServiceDialog dialog = new UserAPIServiceDialog(getSite().getShell());
            dialog.open();
        }
    });

    Composite compositeBody = new Composite(parent, SWT.NONE);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    compositeBody.setLayout(new GridLayout(1, false));

    tvAPIList = new TreeViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION);
    tvAPIList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (tvAPIList.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tvAPIList.getSelection();
            RESTFulAPIDAO dao = (RESTFulAPIDAO) ss.getFirstElement();
            rmDAO = dao.getResourceManagerDao();

            if (rmDAO == null)
                return;

            try {
                userDB = TadpoleSystem_UserDBQuery.getUserDBInstance(Integer.parseInt("" + rmDAO.getDb_seq())); //$NON-NLS-1$

                SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
                List<String> result = sqlClient.queryForList("userDbResourceData", rmDAO); //$NON-NLS-1$

                comboShare.getCombo().select("PUBLIC".equals(rmDAO.getShared_type()) ? 0 : 1); //$NON-NLS-1$
                textTitle.setText(rmDAO.getName());
                textDescription.setText(rmDAO.getDescription());
                comboSupportAPI.setText(rmDAO.getRestapi_yesno());
                textAPIURL.setText(rmDAO.getRestapi_uri() == null ? "" : rmDAO.getRestapi_uri()); //$NON-NLS-1$
                textAPIKey.setText(rmDAO.getRestapi_key());
                textQuery.setText(""); //$NON-NLS-1$
                for (String data : result) {
                    textQuery.append(data);
                }

            } catch (Exception e) {
                logger.error("Resource detail", e); //$NON-NLS-1$
            }
        }
    });
    tvAPIList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (tvAPIList.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tvAPIList.getSelection();
            RESTFulAPIDAO dao = (RESTFulAPIDAO) ss.getFirstElement();
            ResourceManagerDAO rmDAO = dao.getResourceManagerDao();

            if (rmDAO == null)
                return;

            try {

                final UserDBDAO userDB = TadpoleSystem_UserDBQuery
                        .getUserDBInstance(Integer.parseInt("" + rmDAO.getDb_seq())); //$NON-NLS-1$

                // TODO :  ??? ??     DAO   ?  .DAO    ?.
                UserDBResourceDAO ad = new UserDBResourceDAO();
                ad.setResource_seq((int) rmDAO.getResource_seq());
                ad.setName(rmDAO.getName());
                ad.setParent(userDB);

                // db object ?  ? ??.
                if (PublicTadpoleDefine.RESOURCE_TYPE.ERD.toString().equals(rmDAO.getResource_types())) {
                    if (userDB != null && DBDefine.MONGODB_DEFAULT == userDB.getDBDefine()) {
                        MongoDBERDViewAction ea = new MongoDBERDViewAction();
                        ea.run(ad);
                    } else {
                        RDBERDViewAction ea = new RDBERDViewAction();
                        ea.run(ad);
                    }
                } else if (PublicTadpoleDefine.RESOURCE_TYPE.SQL.toString().equals(rmDAO.getResource_types())) {
                    QueryEditorAction qea = new QueryEditorAction();
                    qea.run(ad);
                }
            } catch (Exception e) {
                logger.error("select api", e); //$NON-NLS-1$
            }
        }
    });
    Tree tree = tvAPIList.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TreeViewerColumn treeViewerColumn = new TreeViewerColumn(tvAPIList, SWT.NONE);
    TreeColumn trclmnUrl = treeViewerColumn.getColumn();
    trclmnUrl.setWidth(150);
    trclmnUrl.setText(Messages.get().URL);

    TreeViewerColumn tvcName = new TreeViewerColumn(tvAPIList, SWT.NONE);
    TreeColumn trclmnDBName = tvcName.getColumn();
    trclmnDBName.setWidth(150);
    trclmnDBName.setText(Messages.get().APIName);

    TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(tvAPIList, SWT.NONE);
    TreeColumn trclmnName = treeViewerColumn_1.getColumn();
    trclmnName.setWidth(150);
    trclmnName.setText(Messages.get().DBName);

    TreeViewerColumn treeViewerColumn_2 = new TreeViewerColumn(tvAPIList, SWT.NONE);
    TreeColumn trclmnDescription = treeViewerColumn_2.getColumn();
    trclmnDescription.setWidth(300);
    trclmnDescription.setText(Messages.get().Description);

    tvAPIList.setContentProvider(new APIListContentProvider());
    tvAPIList.setLabelProvider(new APIListLabelProvider());

    /////////////////////////////////////////////////////////////////////////////////////////////
    Group grpQuery = new Group(parent, SWT.NONE);
    grpQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpQuery.setText(Messages.get().DetailItem);
    GridLayout gl_grpQuery = new GridLayout(1, false);
    gl_grpQuery.verticalSpacing = 1;
    gl_grpQuery.horizontalSpacing = 1;
    gl_grpQuery.marginHeight = 1;
    gl_grpQuery.marginWidth = 1;
    grpQuery.setLayout(gl_grpQuery);

    Composite compositeDetail = new Composite(grpQuery, SWT.NONE | SWT.READ_ONLY);
    GridLayout gl_compositeDetail = new GridLayout(7, false);
    gl_compositeDetail.marginHeight = 2;
    gl_compositeDetail.marginWidth = 2;
    gl_compositeDetail.verticalSpacing = 2;
    compositeDetail.setLayout(gl_compositeDetail);
    compositeDetail.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Label lblNewLabel = new Label(compositeDetail, SWT.NONE);
    lblNewLabel.setText(Messages.get().Share);

    comboShare = new ComboViewer(compositeDetail, SWT.NONE | SWT.READ_ONLY);
    Combo cShare = comboShare.getCombo();
    cShare.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    cShare.setItems(new String[] { "PUBLIC", "PRIVATE" }); //$NON-NLS-1$ //$NON-NLS-2$

    Label lblNewLabel_1 = new Label(compositeDetail, SWT.NONE);
    lblNewLabel_1.setText(Messages.get().Title);

    textTitle = new Text(compositeDetail, SWT.BORDER);
    textTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Button btnSave = new Button(compositeDetail, SWT.NONE);
    btnSave.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (rmDAO == null)
                return;

            if (!MessageDialog.openConfirm(getSite().getShell(), Messages.get().Confirm,
                    Messages.get().RESTFulAPIManagerEditor_22))
                return;

            try {
                String share_type = comboShare.getCombo().getText();
                share_type = (share_type == null || "".equals(share_type)) ? "PUBLIC" : share_type; //$NON-NLS-1$ //$NON-NLS-2$
                rmDAO.setShared_type(share_type);
                rmDAO.setName(textTitle.getText());
                rmDAO.setDescription(textDescription.getText());
                rmDAO.setRestapi_yesno(comboSupportAPI.getText());
                rmDAO.setRestapi_uri(textAPIURL.getText());

                if (!isValid(rmDAO))
                    return;

                try {
                    TadpoleSystem_UserDBResource.userDBResourceDupUpdate(userDB, rmDAO);
                } catch (Exception ee) {
                    logger.error("Resource validate", ee); //$NON-NLS-1$
                    MessageDialog.openError(null, Messages.get().Error, ee.getMessage()); //$NON-NLS-1$
                    return;
                }

                if (comboSupportAPI.getText().equals(PublicTadpoleDefine.YES_NO.YES.name())
                        && "".equals(rmDAO.getRestapi_key())) { //$NON-NLS-1$
                    rmDAO.setRestapi_key(Utils.getUniqueID());
                }

                TadpoleSystem_UserDBResource.updateResourceHeader(rmDAO);
                tvAPIList.refresh(rmDAO, true);

                MessageDialog.openInformation(getSite().getShell(), Messages.get().Confirm,
                        Messages.get().RESTFulAPIManagerEditor_27);
            } catch (Exception e1) {
                logger.error("save resource", e1); //$NON-NLS-1$
                MessageDialog.openError(getSite().getShell(), Messages.get().Error,
                        Messages.get().RESTFulAPIManagerEditor_30 + e1.getMessage());
            }
        }

        /**
         * is valid
         * @return
         */
        private boolean isValid(ResourceManagerDAO dao) {
            int len = StringUtils.trimToEmpty(textTitle.getText()).length();
            if (len < 3) {
                MessageDialog.openWarning(null, Messages.get().Warning,
                        Messages.get().RESTFulAPIManagerEditor_31); //$NON-NLS-1$
                textTitle.setFocus();
                return false;
            }

            // sql type 
            if (dao.getResource_types().equals(RESOURCE_TYPE.SQL.name())) {
                if (PublicTadpoleDefine.YES_NO.YES.name().equals(comboSupportAPI.getText())) {
                    String strAPIURI = textAPIURL.getText().trim();

                    if (strAPIURI.equals("")) { //$NON-NLS-1$
                        MessageDialog.openWarning(getSite().getShell(), Messages.get().Warning,
                                Messages.get().RESTFulAPIManagerEditor_34);
                        textAPIURL.setFocus();
                        return false;
                    }

                    // check valid url. url pattern is must be /{parent}/{child}
                    if (!RESTfulAPIUtils.validateURL(textAPIURL.getText())) {
                        MessageDialog.openWarning(getSite().getShell(), Messages.get().Warning,
                                Messages.get().RESTFulAPIManagerEditor_36);

                        textAPIURL.setFocus();
                        return false;
                    }
                }
            }

            return true;
        }
    });
    btnSave.setText(Messages.get().Save);

    //      Button btnDelete = new Button(composite, SWT.NONE);
    //      btnDelete.addSelectionListener(new SelectionAdapter() {
    //         @Override
    //         public void widgetSelected(SelectionEvent e) {
    //            if (tableViewer.getSelection().isEmpty()) return;
    //
    //            if(!MessageDialog.openConfirm(getSite().getShell(), Messages.get().Confirm, "Do you wont to delete?")) return;
    //            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
    //            ResourceManagerDAO dao = (ResourceManagerDAO) ss.getFirstElement();
    //
    //            // ? ?  (?)?   ? ? dao ?   ?
    //            // .
    //            UserDBResourceDAO userDBResource = new UserDBResourceDAO();
    //            userDBResource.setResource_seq((int) dao.getResource_seq());
    //            userDBResource.setName(dao.getRes_title());
    //            userDBResource.setParent(userDB);
    //
    //            try {
    //               TadpoleSystem_UserDBResource.delete(userDBResource);
    //               addUserResouceData(null);
    //            } catch (Exception e1) {
    //               logger.error("Resource delete " + dao.toString(), e1);
    //            }
    //         }
    //      });
    //      btnDelete.setText("Delete");

    Label lblDescription = new Label(compositeDetail, SWT.NONE);
    lblDescription.setText(Messages.get().Description);

    textDescription = new Text(compositeDetail, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.CANCEL | SWT.MULTI);
    GridData gd_textDescription = new GridData(SWT.FILL, SWT.CENTER, true, false, 6, 1);
    gd_textDescription.heightHint = 44;
    textDescription.setLayoutData(gd_textDescription);

    Label lblSupportApi = new Label(compositeDetail, SWT.NONE);
    lblSupportApi.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblSupportApi.setText(Messages.get().RESTFulAPIManagerEditor_39);

    comboSupportAPI = new Combo(compositeDetail, SWT.READ_ONLY);
    comboSupportAPI.add("YES"); //$NON-NLS-1$
    comboSupportAPI.add("NO"); //$NON-NLS-1$
    comboSupportAPI.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblApiURI = new Label(compositeDetail, SWT.NONE);
    lblApiURI.setText(Messages.get().APIURL);

    textAPIURL = new Text(compositeDetail, SWT.BORDER);
    textAPIURL.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Button btnShowUrl = new Button(compositeDetail, SWT.NONE);
    btnShowUrl.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!"".equals(textAPIURL.getText())) { //$NON-NLS-1$
                String strURL = RESTfulAPIUtils.makeURL(textQuery.getText(), textAPIURL.getText());

                TadpoleSimpleMessageDialog dialog = new TadpoleSimpleMessageDialog(getSite().getShell(),
                        Messages.get().RESTFulAPIManagerEditor_44, strURL);
                dialog.open();
            }
        }
    });
    btnShowUrl.setText(Messages.get().RESTFulAPIManagerEditor_45);
    new Label(compositeDetail, SWT.NONE);
    new Label(compositeDetail, SWT.NONE);

    Label lblApiKey = new Label(compositeDetail, SWT.NONE);
    lblApiKey.setText(Messages.get().RESTFulAPIManagerEditor_46);

    textAPIKey = new Text(compositeDetail, SWT.BORDER);
    textAPIKey.setEditable(false);
    textAPIKey.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Button btnApiExecute = new Button(compositeDetail, SWT.NONE);
    btnApiExecute.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!"".equals(textAPIURL.getText())) { //$NON-NLS-1$
                if (userDB != null & rmDAO != null) {
                    APIServiceDialog dialog = new APIServiceDialog(getSite().getShell(), userDB,
                            textQuery.getText(), rmDAO);
                    dialog.open();
                }
            }
        }
    });
    btnApiExecute.setText(Messages.get().RESTFulAPIManagerEditor_48);

    textQuery = new Text(compositeDetail,
            SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    textQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 7, 1));
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    initUI();

}

From source file:com.hangum.tadpole.rdb.core.actions.oracle.TableSapceManageEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 1;/* w  w  w .  j  a  v a  2s .c o m*/
    gl_parent.marginHeight = 1;
    gl_parent.horizontalSpacing = 1;
    gl_parent.marginWidth = 1;
    parent.setLayout(gl_parent);

    Composite compositeToolbar = new Composite(parent, SWT.NONE);
    compositeToolbar.setLayout(new GridLayout(2, false));
    compositeToolbar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    ToolBar toolBar = new ToolBar(compositeToolbar, SWT.FLAT | SWT.RIGHT);
    GridData gd_toolBar = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_toolBar.widthHint = 267;
    toolBar.setLayoutData(gd_toolBar);

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setToolTipText(CommonMessages.get().Refresh);
    tltmRefresh.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/refresh.png")); //$NON-NLS-1$

    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshTablespaceList();
        }
    });

    lblDbname = new Label(compositeToolbar, SWT.NONE);
    lblDbname.setText(""); //$NON-NLS-1$

    columnFilter = new DefaultTableColumnFilter();

    Composite compositeTablespaceList = new Composite(parent, SWT.NONE);
    GridData gd_compositeTablespaceList = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_compositeTablespaceList.minimumHeight = 200;
    compositeTablespaceList.setLayoutData(gd_compositeTablespaceList);
    compositeTablespaceList.setLayout(new GridLayout(1, false));

    tableViewer = new TableViewer(compositeTablespaceList, SWT.BORDER | SWT.FULL_SELECTION);
    Table tableTablespace = tableViewer.getTable();
    tableTablespace.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableTablespace.setHeaderVisible(true);
    tableTablespace.setLinesVisible(true);
    tableViewer.addFilter(columnFilter);

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (tableViewer.getSelection().isEmpty()) {
                return;
            }

            StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
            tablespaceDao = (OracleTablespaceDAO) ss.getFirstElement();

            List<HashMap<String, String>> datafileList = new ArrayList<HashMap<String, String>>();
            try {

                SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
                datafileList = (List<HashMap<String, String>>) sqlClient
                        .queryForList("getTablespaceDataFileList", tablespaceDao.getTablespace_name()); //$NON-NLS-1$

            } catch (Exception e) {
                logger.error("Tablespace detail information loading...", e); //$NON-NLS-1$
            }

            textDropScript.setText(StringUtils.trimToEmpty(getDropScript()));
            makeCreateScript();

            tableViewer_datafiles.setInput(datafileList);
            tableViewer_datafiles.refresh();

            if (datafileList.size() > 0) {
                tableViewer_datafiles
                        .setSelection(new StructuredSelection(tableViewer_datafiles.getElementAt(0)), true);

                refreshDatafileInformation();
            } else {
                // ?? ??  ??  .
                tableViewer_property.setInput(new ArrayList<Map<String, String>>());
                tableViewer_property.refresh();
            }
        }
    });

    Group grpQuery = new Group(parent, SWT.NONE);
    grpQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpQuery.setText("Detail Information");
    GridLayout gl_grpQuery = new GridLayout(1, false);
    gl_grpQuery.verticalSpacing = 1;
    gl_grpQuery.horizontalSpacing = 1;
    gl_grpQuery.marginHeight = 1;
    gl_grpQuery.marginWidth = 1;
    grpQuery.setLayout(gl_grpQuery);

    Composite composite = new Composite(grpQuery, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new FillLayout(SWT.HORIZONTAL));

    SashForm sashForm = new SashForm(composite, SWT.NONE);

    SashForm sashForm_1 = new SashForm(sashForm, SWT.VERTICAL);

    Composite composite_2 = new Composite(sashForm_1, SWT.BORDER);
    GridLayout gl_composite_2 = new GridLayout(1, false);
    gl_composite_2.verticalSpacing = 0;
    gl_composite_2.horizontalSpacing = 0;
    gl_composite_2.marginHeight = 0;
    gl_composite_2.marginWidth = 0;
    composite_2.setLayout(gl_composite_2);

    tableViewer_datafiles = new TableViewer(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
    table_datafiles = tableViewer_datafiles.getTable();
    table_datafiles.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table_datafiles.setLinesVisible(true);
    table_datafiles.setHeaderVisible(true);

    tableViewer_datafiles.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (tableViewer_datafiles.getSelection().isEmpty()) {
                return;
            }
            refreshDatafileInformation();
            makeCreateScript();
        }
    });

    Composite composite_6 = new Composite(composite_2, SWT.NONE);
    composite_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_composite_6 = new GridLayout(2, false);
    composite_6.setLayout(gl_composite_6);

    btnDatafileName = new Button(composite_6, SWT.CHECK);
    btnDatafileName.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            textDataFileName.setEnabled(btnDatafileName.getSelection());
            if (btnDatafileName.getSelection()) {
                StructuredSelection ss = (StructuredSelection) tableViewer_datafiles.getSelection();
                if (ss != null) {
                    HashMap<String, Object> datafileMap = (HashMap<String, Object>) ss.getFirstElement();
                    String fileName = (String) datafileMap.get("FILE_NAME");

                    int cnt = tableViewer_datafiles.getTable().getItemCount() + 1;

                    fileName = StringUtils.replaceOnce(fileName, ".", "_Copy" + cnt + ".");
                    textDataFileName.setText(fileName);
                } else {
                    textDataFileName.setFocus();
                }
            }
            makeAddDatafileScript();
        }
    });
    btnDatafileName.setText("Datafile Name");
    textDataFileName = new Text(composite_6, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
    textDataFileName.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textDataFileName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textDataFileName.setText("Auto");
    textDataFileName.setEnabled(false);

    Label lblNewLabel_2 = new Label(composite_6, SWT.NONE);
    lblNewLabel_2.setText("Datafile Size(MB)");

    Composite composite_7 = new Composite(composite_6, SWT.NONE);
    GridLayout gl_composite_7 = new GridLayout(2, false);
    gl_composite_7.verticalSpacing = 0;
    gl_composite_7.horizontalSpacing = 0;
    gl_composite_7.marginWidth = 0;
    gl_composite_7.marginHeight = 0;
    composite_7.setLayout(gl_composite_7);

    textDatafileSize = new Text(composite_7, SWT.BORDER | SWT.RIGHT);
    textDatafileSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    GridData gd_textDatafileSize = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_textDatafileSize.widthHint = 60;
    textDatafileSize.setLayoutData(gd_textDatafileSize);
    textDatafileSize.setText("5");

    btnReuse = new Button(composite_7, SWT.CHECK);
    btnReuse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            makeAddDatafileScript();
        }
    });
    btnReuse.setText("Reuse");

    Composite composite_5 = new Composite(composite_2, SWT.NONE);
    composite_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite_5.setLayout(new GridLayout(4, false));

    btnAutoExtend = new Button(composite_5, SWT.CHECK);
    btnAutoExtend.setSelection(true);
    btnAutoExtend.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            textAutoExtendSize.setEnabled(btnAutoExtend.getSelection());
            btnMaximumSize.setEnabled(btnAutoExtend.getSelection());
            textMaximumSize.setEnabled(btnAutoExtend.getSelection());

            makeAddDatafileScript();
        }
    });
    btnAutoExtend.setText("Auto Extend");

    Label lblExtendSize = new Label(composite_5, SWT.NONE);
    lblExtendSize.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblExtendSize.setText("Extend Size(MB)");

    textAutoExtendSize = new Text(composite_5, SWT.BORDER | SWT.RIGHT);
    textAutoExtendSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textAutoExtendSize.setText("5");
    textAutoExtendSize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(composite_5, SWT.NONE);

    btnMaximumSize = new Button(composite_5, SWT.CHECK);
    btnMaximumSize.setSelection(true);
    btnMaximumSize.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            textMaximumSize.setEnabled(!btnMaximumSize.getSelection());
            textMaximumSize.setText((1024 * 5) + ""); //5GB
            textMaximumSize.setFocus();
            textMaximumSize.setSelection(0, textMaximumSize.getText().length());
            makeAddDatafileScript();
        }
    });
    btnMaximumSize.setText("Maximum Unlimited");

    Label lblMaximumSizemb = new Label(composite_5, SWT.NONE);
    lblMaximumSizemb.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblMaximumSizemb.setText("Maximum Size(MB)");

    textMaximumSize = new Text(composite_5, SWT.BORDER | SWT.RIGHT);
    textMaximumSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            makeAddDatafileScript();
        }
    });
    textMaximumSize.setEnabled(false);
    textMaximumSize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnAddDatafile = new Button(composite_5, SWT.NONE);
    btnAddDatafile.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            makeAddDatafileScript();
        }
    });
    btnAddDatafile.setText("Add Datafile");

    tableViewer_property = new TableViewer(sashForm_1, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer_property.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    TableViewerColumn tvPropertyName = new TableViewerColumn(tableViewer_property, SWT.NONE);
    TableColumn tcPropertyName = tvPropertyName.getColumn();
    tcPropertyName.setWidth(180);
    tcPropertyName.setText("Property");

    TableViewerColumn tvPropertyValue = new TableViewerColumn(tableViewer_property, SWT.NONE);
    TableColumn tcPropertyValue = tvPropertyValue.getColumn();
    tcPropertyValue.setWidth(300);
    tcPropertyValue.setText("Value");

    tableViewer_property.setContentProvider(new ArrayContentProvider());
    tableViewer_property.setLabelProvider(new TablespaceExtInfoLabelProvider());
    sashForm_1.setWeights(new int[] { 1, 1 });

    Composite composite_1 = new Composite(sashForm, SWT.BORDER);
    composite_1.setLayout(new GridLayout(1, false));

    Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
    lblNewLabel_1.setText("Drop Tablespace");

    textDropScript = new Text(composite_1, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textDropScript.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
    GridData gd_textDropScript = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_textDropScript.minimumHeight = 20;
    textDropScript.setLayoutData(gd_textDropScript);

    Composite composite_4 = new Composite(composite_1, SWT.NONE);
    composite_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite_4.setLayout(new GridLayout(3, false));

    btnIncludingContents = new Button(composite_4, SWT.CHECK);
    btnIncludingContents.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // ?? ??  .
            btnCascadeConstraints.setEnabled(btnIncludingContents.getSelection());
            textDropScript.setText(getDropScript());
        }
    });
    btnIncludingContents.setText("Including Contents?");

    btnCascadeConstraints = new Button(composite_4, SWT.CHECK);
    btnCascadeConstraints.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // ?  .
            textDropScript.setText(getDropScript());
        }
    });
    btnCascadeConstraints.setEnabled(false);
    btnCascadeConstraints.setText("Cascade Constraints?");

    Button btnDrop = new Button(composite_4, SWT.NONE);
    btnDrop.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            //Excute script
            RequestResultDAO reqReResultDAO = new RequestResultDAO();
            try {
                ExecuteDDLCommand.executSQL(userDB, reqReResultDAO, textDropScript.getText().trim());
            } catch (Exception ex) {
                logger.error(ex);
            } //$NON-NLS-1$
            if (PublicTadpoleDefine.SUCCESS_FAIL.F.name().equals(reqReResultDAO.getResult())) {
                MessageDialog.openError(getSite().getShell(), CommonMessages.get().Error,
                        Messages.get().RiseError + reqReResultDAO.getMesssage()
                                + reqReResultDAO.getException().getMessage());
            } else {
                MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Information,
                        Messages.get().WorkHasCompleted);
                refreshTablespaceList();
            }

        }
    });
    btnDrop.setSize(94, 28);
    btnDrop.setText("Drop Tablespace");

    Label lblNewLabel = new Label(composite_1, SWT.NONE);
    lblNewLabel.setText("Create Tablespace && Add Datafile");

    textScript = new Text(composite_1, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    textScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite composite_3 = new Composite(composite_1, SWT.NONE);
    composite_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

    Button btnExecute = new Button(composite_3, SWT.NONE);
    btnExecute.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            //Excute script
            RequestResultDAO reqReResultDAO = new RequestResultDAO();
            try {
                ExecuteDDLCommand.executSQL(userDB, reqReResultDAO, textScript.getText().trim());
            } catch (Exception ex) {
                logger.error(ex);
            } //$NON-NLS-1$
            if (PublicTadpoleDefine.SUCCESS_FAIL.F.name().equals(reqReResultDAO.getResult())) {
                MessageDialog.openError(getSite().getShell(), CommonMessages.get().Error,
                        Messages.get().RiseError + reqReResultDAO.getMesssage()
                                + reqReResultDAO.getException().getMessage());
            } else {
                MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Information,
                        Messages.get().WorkHasCompleted);
                refreshTablespaceList();
                refreshDatafileInformation();
            }
        }
    });
    btnExecute.setBounds(0, 0, 150, 28);
    btnExecute.setText("Execute Script");
    sashForm.setWeights(new int[] { 1, 1 });

    createTableColumn();
    createTableDataFileColumn();

    initUI();

}

From source file:com.hangum.tadpole.rdb.core.actions.oracle.TableSapceManageEditor.java

License:Open Source License

private void makeCreateScript() {
    StructuredSelection ss = (StructuredSelection) tableViewer.getSelection();
    tablespaceDao = (OracleTablespaceDAO) ss.getFirstElement();

    List<Map<String, String>> tablespaceScript = new ArrayList<Map<String, String>>();

    try {/*from www .j a va2  s  .  c  om*/

        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        tablespaceScript = (List<Map<String, String>>) sqlClient.queryForList("getTablespaceScript", //$NON-NLS-1$
                tablespaceDao.getTablespace_name());

    } catch (Exception e) {
        logger.error("Tablespace detail information loading...", e); //$NON-NLS-1$
    }

    String create_stmt = "";
    for (Map<String, String> line : tablespaceScript) {
        create_stmt += line.get("DDLSCRIPT") + "\n";
    }

    textScript.setText(StringUtils.trimToEmpty(create_stmt));
}

From source file:com.hangum.tadpole.rdb.core.actions.oracle.TableSapceManageEditor.java

License:Open Source License

private void refreshDatafileInformation() {
    StructuredSelection ss = (StructuredSelection) tableViewer_datafiles.getSelection();

    if (ss == null)
        return;//from  w  ww  .  j a  v a  2 s.com

    HashMap<String, Object> datafileMap = (HashMap<String, Object>) ss.getFirstElement();

    List<HashMap<String, Object>> datafileInformationList = new ArrayList<HashMap<String, Object>>();
    List<Map<String, String>> datafilePropertyList = new ArrayList<Map<String, String>>();

    try {

        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        String file_id = ((BigDecimal) datafileMap.get("FILE_ID")).toString();

        datafileInformationList = (List<HashMap<String, Object>>) sqlClient
                .queryForList("getTablespaceDataFileInfomation", file_id); //$NON-NLS-1$

        for (Map<String, Object> informationMap : datafileInformationList) {
            for (String key : informationMap.keySet()) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("key", key);
                map.put("value", String.valueOf(informationMap.get(key)));
                datafilePropertyList.add(map);
            }
        }

    } catch (Exception e) {
        logger.error("Tablespace detail information loading...", e); //$NON-NLS-1$
    }
    textDropScript.setText(StringUtils.trimToEmpty(getDropScript()));
    tableViewer_property.setInput(datafilePropertyList);
    tableViewer_property.refresh();

}

From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.AWSRDSLoginComposite.java

License:Open Source License

/**
 * Add RDS to Tadpole//from w ww.j  a v  a 2s. com
 */
private void addDatabase() {
    StructuredSelection ss = (StructuredSelection) tvRDS.getSelection();
    if (ss.isEmpty()) {
        MessageDialog.openError(null, Messages.DBLoginDialog_14, Messages.AWSRDSLoginComposite_8);
    } else {
        AWSRDSUserDBDAO amazonRDSDto = (AWSRDSUserDBDAO) ss.getFirstElement();

        SingleAddDBDialog dialog = new SingleAddDBDialog(
                PlatformUI.getWorkbench().getDisplay().getActiveShell(), amazonRDSDto, getListGroupName(),
                getSelGroupName());
        dialog.open();
    }

}

From source file:com.hangum.tadpole.rdb.core.dialog.driver.JDBCDriverManageDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//from www  .  ja va  2s  .com
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) container.getLayout();
    gridLayout.verticalSpacing = 5;
    gridLayout.horizontalSpacing = 5;
    gridLayout.marginHeight = 5;
    gridLayout.marginWidth = 5;

    SashForm sashForm = new SashForm(container, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeLeft = new Composite(sashForm, SWT.NONE);
    compositeLeft.setLayout(new GridLayout(1, false));

    Label lblDriverList = new Label(compositeLeft, SWT.NONE);
    lblDriverList.setText(Messages.get().JDBCDriverSetting_DriverList);

    lvDB = new ListViewer(compositeLeft, SWT.BORDER | SWT.V_SCROLL);
    lvDB.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection ss = (StructuredSelection) lvDB.getSelection();
            if (ss.isEmpty())
                return;

            DBDefine dbDefine = (DBDefine) ss.getFirstElement();
            jdbc_dir = ApplicationArgumentUtils.JDBC_RESOURCE_DIR + dbDefine.getExt()
                    + PublicTadpoleDefine.DIR_SEPARATOR;
            lblRealFullPath.setText(jdbc_dir);
            initDBFileList();
        }
    });
    List list = lvDB.getList();
    list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    lvDB.setContentProvider(new ArrayContentProvider());
    lvDB.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            DBDefine dbDefine = (DBDefine) element;
            return dbDefine.getDBToString();
        }
    });
    lvDB.setInput(DBDefine.getDriver());

    Composite compositeBody = new Composite(sashForm, SWT.NONE);
    compositeBody.setLayout(new GridLayout(3, false));

    Label lblDumy = new Label(compositeBody, SWT.NONE);
    lblDumy.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Label lblPath = new Label(compositeBody, SWT.NONE);
    lblPath.setText(Messages.get().JDBCDriverSetting_Path);

    lblRealFullPath = new Text(compositeBody, SWT.NONE | SWT.READ_ONLY);
    lblRealFullPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Label txtFileList = new Label(compositeBody, SWT.NONE);
    txtFileList.setText(Messages.get().JDBCDriverSetting_FileList);
    new Label(compositeBody, SWT.NONE);
    new Label(compositeBody, SWT.NONE);

    lvDriverFile = new ListViewer(compositeBody, SWT.BORDER | SWT.V_SCROLL);
    lvDriverFile.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            btnDelete.setEnabled(true);
        }
    });
    lvDriverFile.setContentProvider(new ArrayContentProvider());
    lvDriverFile.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            String str = element.toString();
            return str;
        }
    });

    List listDriver = lvDriverFile.getList();
    listDriver.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    Composite compositeBodyBtn = new Composite(compositeBody, SWT.NONE);
    compositeBodyBtn.setLayout(new GridLayout(1, false));
    compositeBodyBtn.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));

    btnDelete = new Button(compositeBodyBtn, SWT.NONE);
    btnDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) lvDriverFile.getSelection();
            if (ss.isEmpty())
                return;

            String strFile = (String) ss.getFirstElement();
            if (!MessageDialog.openConfirm(getShell(), Messages.get().Confirm, Messages.get().Delete))
                return;
            if (logger.isDebugEnabled())
                logger.debug("File delete : " + jdbc_dir + strFile);

            try {
                FileUtils.forceDelete(new File(jdbc_dir + strFile));

                initDBFileList();
            } catch (IOException e1) {
                logger.error("File delete", e1);
                MessageDialog.openError(getShell(), Messages.get().Error, "File deleteing: " + e1.getMessage());
            }

        }
    });
    btnDelete.setText(Messages.get().Delete);

    final String url = startUploadReceiver();
    pushSession = new ServerPushSession();

    fileUpload = new FileUpload(compositeBodyBtn, SWT.NONE);
    fileUpload.setText(Messages.get().JDBCDriverSetting_JARUpload);
    fileUpload.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    fileUpload.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String fileName = fileUpload.getFileName();
            if ("".equals(fileName) || null == fileName) //$NON-NLS-1$
                return;
            if (!MessageDialog.openConfirm(null, Messages.get().Confirm,
                    Messages.get().SQLiteLoginComposite_17))
                return;

            if (logger.isDebugEnabled())
                logger.debug("=[file name]==> " + fileName);

            pushSession.start();
            fileUpload.submit(url);
        }
    });

    Button btnRefresh = new Button(compositeBodyBtn, SWT.NONE);
    btnRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initDBFileList();
        }
    });
    btnRefresh.setText(Messages.get().Refresh);

    sashForm.setWeights(new int[] { 3, 7 });
    initManager();

    return container;
}

From source file:com.hangum.tadpole.rdb.core.dialog.resource.ResourceDetailDialog.java

License:Open Source License

/**
 * Create contents of the dialog./*from  w  w  w .ja  v a2  s.  c  om*/
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) container.getLayout();
    gridLayout.verticalSpacing = 5;
    gridLayout.horizontalSpacing = 5;
    gridLayout.marginHeight = 5;
    gridLayout.marginWidth = 5;

    Composite compositeHead = new Composite(container, SWT.NONE);
    compositeHead.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    compositeHead.setLayout(new GridLayout(3, false));

    Label lblTitle = new Label(compositeHead, SWT.NONE);
    lblTitle.setText(Messages.get().Title);

    textTitle = new Text(compositeHead, SWT.BORDER | SWT.READ_ONLY);
    textTitle.setEditable(true);
    textTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textTitle.setText(resourceManagerDao.getName());
    new Label(compositeHead, SWT.NONE);

    Label lblDescription = new Label(compositeHead, SWT.NONE);
    lblDescription.setText(Messages.get().Description);

    textDescription = new Text(compositeHead,
            SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    textDescription.setEditable(true);
    GridData gd_textDescription = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_textDescription.heightHint = 40;
    textDescription.setLayoutData(gd_textDescription);
    textDescription.setText(resourceManagerDao.getDescription());

    Button btnModify = new Button(compositeHead, SWT.NONE);
    btnModify.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if ("".equals(textTitle.getText().trim())) {
                MessageDialog.openWarning(getShell(), Messages.get().Warning,
                        Messages.get().ResourceDetailDialog_name_empty);
                textTitle.setFocus();
                return;
            }

            if (MessageDialog.openConfirm(getShell(), Messages.get().Confirm,
                    Messages.get().ResourceDetailDialog_delete)) {
                resourceManagerDao.setName(textTitle.getText());
                resourceManagerDao.setDescription(textDescription.getText());

                try {
                    TadpoleSystem_UserDBResource.userDbResourceHeadUpdate(resourceManagerDao);

                    // tree refresh
                    if (originalResourceDB != null) {
                        originalResourceDB.setName(textTitle.getText());
                        originalResourceDB.setDescription(textDescription.getText());
                        ManagerViewer mv = (ManagerViewer) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage().showView(ManagerViewer.ID);
                        mv.refreshResource(originalResourceDB);
                    }
                } catch (Exception ee) {
                    logger.error("Resource title, desc saveing", ee);
                    MessageDialog.openError(getShell(), Messages.get().Confirm,
                            "Save exception." + ee.getMessage());
                }
            }
        }
    });
    btnModify.setText(Messages.get().Modified);

    Composite compositeHeaderUser = new Composite(compositeHead, SWT.NONE);
    compositeHeaderUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    compositeHeaderUser.setLayout(new GridLayout(4, false));

    Label lblUser = new Label(compositeHeaderUser, SWT.NONE);
    lblUser.setText(Messages.get().User);

    textUser = new Text(compositeHeaderUser, SWT.BORDER | SWT.READ_ONLY);
    textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textUser.setText(resourceManagerDao.getUser_name());

    Label lblCreateTime = new Label(compositeHeaderUser, SWT.NONE);
    lblCreateTime.setText(Messages.get().CreatTime);

    textCreateTime = new Text(compositeHeaderUser, SWT.BORDER | SWT.READ_ONLY);
    textCreateTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textCreateTime.setText(resourceManagerDao.getCreate_time());

    SashForm sashForm = new SashForm(container, SWT.BORDER | SWT.VERTICAL);
    sashForm.setLayout(new GridLayout(1, false));
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    tvHistory = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    tvHistory.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection sss = (StructuredSelection) tvHistory.getSelection();
            if (sss.isEmpty())
                return;

            UserDBResourceDataDAO userDBResource = (UserDBResourceDataDAO) sss.getFirstElement();
            compareWidget.changeDiff(userDBResource.getDatas(), "");
        }
    });
    Table table = tvHistory.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TableViewerColumn tvcDate = new TableViewerColumn(tvHistory, SWT.NONE);
    TableColumn tblclmnDate = tvcDate.getColumn();
    tblclmnDate.setWidth(100);
    tblclmnDate.setText(Messages.get().Date);

    TableViewerColumn tvcUser = new TableViewerColumn(tvHistory, SWT.NONE);
    TableColumn tblclmnUser = tvcUser.getColumn();
    tblclmnUser.setWidth(100);
    tblclmnUser.setText(Messages.get().User);

    TableViewerColumn tvcSQL = new TableViewerColumn(tvHistory, SWT.NONE);
    TableColumn tblclmnSql = tvcSQL.getColumn();
    tblclmnSql.setWidth(500);
    tblclmnSql.setText(Messages.get().SQL);

    tvHistory.setContentProvider(new ArrayContentProvider());
    tvHistory.setLabelProvider(new ResourceHistoryLabelProvider());

    //      SashForm compositeCompare = new SashForm(sashForm, SWT.NONE);
    //      compositeCompare.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    //      compositeCompare.setLayout(new GridLayout(2, false));

    compareWidget = new TadpoleCompareWidget(sashForm, SWT.BORDER);
    compareWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    //      textLeft = new TadpoleEditorWidget(compositeCompare, SWT.BORDER, EditorDefine.EXT_DEFAULT, "", "");
    //      textLeft.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    //
    //      textRight = new TadpoleEditorWidget(compositeCompare, SWT.BORDER, EditorDefine.EXT_DEFAULT, "", "");
    //      textRight.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    sashForm.setWeights(new int[] { 6, 4 });
    initUIData();

    return container;
}

From source file:com.hangum.tadpole.rdb.core.editors.sessionlist.SessionListEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 0;//from   ww w  . j ava  2s . co  m
    gl_parent.horizontalSpacing = 0;
    gl_parent.marginHeight = 0;
    gl_parent.marginWidth = 0;
    parent.setLayout(gl_parent);

    Composite compositeHead = new Composite(parent, SWT.NONE);
    compositeHead.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_compositeHead = new GridLayout(1, false);
    gl_compositeHead.marginHeight = 0;
    gl_compositeHead.horizontalSpacing = 0;
    gl_compositeHead.marginWidth = 0;
    compositeHead.setLayout(gl_compositeHead);

    ToolBar toolBar = new ToolBar(compositeHead, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setToolTipText("Refresh");
    tltmRefresh.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/refresh.png")); //$NON-NLS-1$
    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initSessionListData();
        }
    });

    final ToolItem tltmKillProcess = new ToolItem(toolBar, SWT.NONE);
    tltmKillProcess.setToolTipText("Kill Process");
    tltmKillProcess
            .setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/stop_process.png")); //$NON-NLS-1$
    tltmKillProcess.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            killProcess();
        }
    });
    tltmKillProcess.setEnabled(false);

    SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeBody = new Composite(sashForm, SWT.NONE);
    compositeBody.setLayout(new GridLayout(1, false));

    tableViewerSessionList = new TableViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewerSessionList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (tableViewerSessionList.getSelection().isEmpty())
                return;

            tltmKillProcess.setEnabled(true);

            StructuredSelection ss = (StructuredSelection) tableViewerSessionList.getSelection();
            SessionListDAO sl = (SessionListDAO) ss.getFirstElement();
            if (null != sl.getInfo()) {
                textQuery.setText(sl.getInfo());
                textQuery.setFocus();
            } else {
                textQuery.setText("");
            }
        }
    });
    Table tableSessionList = tableViewerSessionList.getTable();
    tableSessionList.setHeaderVisible(true);
    tableSessionList.setLinesVisible(true);
    tableSessionList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Group compositeQuery = new Group(sashForm, SWT.NONE);
    compositeQuery.setLayout(new GridLayout(1, false));
    compositeQuery.setText("Query");

    textQuery = new Text(compositeQuery, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textQuery.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    comparator = new MySQLSessionListTableCompare();
    tableViewerSessionList.setSorter(comparator);

    createColumn();

    tableViewerSessionList.setContentProvider(new ArrayContentProvider());
    tableViewerSessionList.setLabelProvider(new MySQLSessionListLabelProvider());

    sashForm.setWeights(new int[] { 7, 3 });

    // init data
    initSessionListData();
}