Example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty

List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection isEmpty.

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:com.hangum.tadpole.erd.core.actions.TableSelectionAction.java

License:Open Source License

@Override
protected boolean calculateEnabled() {
    IStructuredSelection is = (IStructuredSelection) getViewer().getSelection();
    if (!is.isEmpty()) {
        if (is.getFirstElement() instanceof TableEditPart) {
            TableEditPart tablePart = (TableEditPart) is.getFirstElement();
            Table tableModel = (Table) tablePart.getModel();

            PlatformUI.getPreferenceStore().setValue(Define.SELECT_ERD_TABLE, tableModel.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }/*from   w  ww.  ja  v a  2  s .c  o  m*/
    }

    return true;
}

From source file:com.hangum.tadpole.manager.core.dialogs.users.FindUserAndDBRoleDialog.java

License:Open Source License

@Override
protected void okPressed() {
    IStructuredSelection iss = (IStructuredSelection) tableViewer.getSelection();
    if (iss.isEmpty())
        return;/* w ww  . j  a  v  a 2s.c o  m*/
    UserDAO userDAO = (UserDAO) iss.getFirstElement();

    if ("NONE".equals(comboRoleType.getText())) { //$NON-NLS-1$
        MessageDialog.openWarning(getShell(), Messages.get().Warning, Messages.get().FindUserAndDBRoleDialog_6);
        comboRoleType.setFocus();
        return;
    }

    // ?  ?  ?  . 
    try {
        boolean isAddDBRole = TadpoleSystem_UserRole.isDBAddRole(userDBDao, userDAO);
        if (isAddDBRole) {
            if (!MessageDialog.openConfirm(getShell(), Messages.get().Confirm, Messages.get().FindUserDialog_4))
                return;

            Calendar calStart = Calendar.getInstance();
            calStart.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0);

            Calendar calEnd = Calendar.getInstance();
            calEnd.set(dateTimeEndDay.getYear(), dateTimeEndDay.getMonth(), dateTimeEndDay.getDay(),
                    dateTimeEndTime.getHours(), dateTimeEndTime.getMinutes(), 00);

            tadpoleUserRoleDao = TadpoleSystem_UserRole.insertTadpoleUserDBRole(userDAO.getSeq(),
                    userDBDao.getSeq(), comboRoleType.getText(), "*", //$NON-NLS-1$
                    new Timestamp(calStart.getTimeInMillis()), new Timestamp(calEnd.getTimeInMillis()));

            MessageDialog.openInformation(getShell(), Messages.get().Confirm,
                    Messages.get().FindUserAndDBRoleDialog_10);

            //            super.okPressed();
        } else {
            MessageDialog.openWarning(getShell(), Messages.get().Warning,
                    Messages.get().FindUserAndDBRoleDialog_12);
        }
    } catch (Exception e) {
        logger.error(Messages.get().RoleType, e);
        MessageDialog.openError(getShell(), Messages.get().Error,
                Messages.get().FindUserAndDBRoleDialog_15 + e.getMessage());
    }

}

From source file:com.hangum.tadpole.manager.core.dialogs.users.FindUserDialog.java

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    super.buttonPressed(buttonId);

    if (buttonId == BTN_ADD) {
        IStructuredSelection iss = (IStructuredSelection) tableViewer.getSelection();
        if (iss.isEmpty())
            return;

        if (MessageDialog.openConfirm(null, "Confirm", Messages.FindUserDialog_4)) { //$NON-NLS-1$
            UserDAO userDAO = (UserDAO) iss.getFirstElement();

            try {
                if (TadpoleSystem_UserRole.findGroupUserRole(SessionManager.getGroupSeq(), userDAO.getSeq())) {
                    MessageDialog.openError(null, "Error", Messages.FindUserDialog_6); //$NON-NLS-1$
                    return;
                } else {
                    TadpoleSystem_UserRole.newUserRole(SessionManager.getGroupSeq(), userDAO.getSeq(),
                            PublicTadpoleDefine.USER_TYPE.USER.toString(),
                            PublicTadpoleDefine.YES_NO.YES.toString(), userDAO.getName());
                }/*from w w w . jav  a  2 s  .  c  om*/
            } catch (Exception e) {
                logger.error("Fine user role", e); //$NON-NLS-1$
            }

        }
    }
}

From source file:com.hangum.tadpole.manager.core.editor.auth.AdminUserListComposite.java

License:Open Source License

/**
 * modify user// w  ww.j a v  a 2s  .c  o  m
 */
private void modifyUser() {
    IStructuredSelection ss = (IStructuredSelection) userListViewer.getSelection();
    if (!ss.isEmpty()) {
        UserGroupAUserDAO userGroupAuser = (UserGroupAUserDAO) ss.getFirstElement();

        ModifyUserDialog dialog = new ModifyUserDialog(getShell(), userGroupAuser);
        if (Dialog.OK == dialog.open()) {
            initUI();
        }

    }
}

From source file:com.hangum.tadpole.manager.core.editor.auth.DBListComposite.java

License:Open Source License

/**
 * Create the composite.//w  w  w  . j a v  a 2s .co  m
 * @param parent
 * @param style
 */
public DBListComposite(Composite parent, int style) {
    super(parent, style);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    setLayout(gridLayout);

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

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

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setImage(ImageUtils.getRefresh());
    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            treeViewerDBList.setInput(initData());
        }
    });
    tltmRefresh.setToolTipText("Refresh");

    //      // access control
    //      if(PublicTadpoleDefine.USER_TYPE.MANAGER.toString().equals(SessionManager.getRepresentRole()) || 
    //            PublicTadpoleDefine.USER_TYPE.ADMIN.toString().equals(SessionManager.getRepresentRole())
    //            ) {
    final ToolItem tltmAdd = new ToolItem(toolBar, SWT.NONE);
    tltmAdd.setImage(ImageUtils.getAdd());
    tltmAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            final DBLoginDialog dialog = new DBLoginDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "");
            final int ret = dialog.open();

            if (ret == Dialog.OK) {
                treeViewerDBList.setInput(initData());
                refreshConnections();
            }
        }
    });
    tltmAdd.setToolTipText("Add");

    tltmDBDelete = new ToolItem(toolBar, SWT.NONE);
    tltmDBDelete.setImage(ImageUtils.getDelete());
    tltmDBDelete.setEnabled(false);
    tltmDBDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteDB();
        }
    });
    tltmDBDelete.setToolTipText("DB Delete");

    tltmModify = new ToolItem(toolBar, SWT.NONE);
    tltmModify.setImage(ImageUtils.getModify());
    tltmModify.setEnabled(false);
    tltmModify.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            modifyDB();
        }
    });
    tltmModify.setToolTipText("Modify");

    ToolItem tltmDbExport = new ToolItem(toolBar, SWT.NONE);
    tltmDbExport.setImage(ImageUtils.getExport());
    tltmDbExport.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            exportDB();
        }
    });
    tltmDbExport.setToolTipText("DB Export");

    ToolItem tltmDbImport = new ToolItem(toolBar, SWT.NONE);
    tltmDbImport.setImage(ImageUtils.getImport()); //$NON-NLS-1$
    tltmDbImport.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            importDB();
        }
    });
    tltmDbImport.setToolTipText("DB Import");
    //      }

    tltmQueryHistory = new ToolItem(toolBar, SWT.NONE);
    tltmQueryHistory.setImage(ImageUtils.getQueryHistory()); //$NON-NLS-1$
    tltmQueryHistory.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewQueryHistory();
        }
    });
    tltmQueryHistory.setEnabled(false);
    tltmQueryHistory.setToolTipText("Query History");

    tltmSQLEditor = new ToolItem(toolBar, SWT.NONE);
    tltmSQLEditor.setImage(ImageUtils.getSQLEditor()); //$NON-NLS-1$
    tltmSQLEditor.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            sqlEditor();
        }
    });
    tltmSQLEditor.setEnabled(false);
    tltmSQLEditor.setToolTipText("SQL Editor");

    new Label(compositeHead, SWT.NONE);

    Label lblSearch = new Label(compositeHead, SWT.NONE);
    lblSearch.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblSearch.setText("Search");

    textSearch = new Text(compositeHead, SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    textSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    textSearch.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            filter.setSearchString(textSearch.getText());
            treeViewerDBList.refresh();
        }
    });

    // download dumy
    compositeDumy = new Composite(compositeHead, SWT.NONE);
    compositeDumy.setLayout(new GridLayout(1, false));

    Composite compositeBody = new Composite(this, SWT.NONE);
    GridLayout gl_compositeBody = new GridLayout(1, false);
    gl_compositeBody.verticalSpacing = 2;
    gl_compositeBody.horizontalSpacing = 2;
    gl_compositeBody.marginHeight = 2;
    gl_compositeBody.marginWidth = 2;
    compositeBody.setLayout(gl_compositeBody);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    treeViewerDBList = new TreeViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    treeViewerDBList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {

            IStructuredSelection ss = (IStructuredSelection) treeViewerDBList.getSelection();
            if (ss.isEmpty())
                return;
            UserDBDAO userDB = (UserDBDAO) ss.getFirstElement();
            if (userDB.getGroup_seq() == SessionManager.getGroupSeq()) {
                tltmModify.setEnabled(true);
                tltmDBDelete.setEnabled(true);
            } else {
                tltmModify.setEnabled(false);
                tltmDBDelete.setEnabled(false);
            }

            tltmQueryHistory.setEnabled(true);
            tltmSQLEditor.setEnabled(true);
        }
    });
    treeViewerDBList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            viewQueryHistory();
        }
    });
    Tree treeAdmin = treeViewerDBList.getTree();
    treeAdmin.setLinesVisible(true);
    treeAdmin.setHeaderVisible(true);
    treeAdmin.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TreeViewerColumn colGroupName = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colGroupName.getColumn().setWidth(130);
    colGroupName.getColumn().setText("Group Name");

    TreeViewerColumn colUserType = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colUserType.getColumn().setWidth(100);
    colUserType.getColumn().setText("DB Type");

    TreeViewerColumn colEmail = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colEmail.getColumn().setWidth(150);
    colEmail.getColumn().setText("DB Name");

    TreeViewerColumn colName = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colName.getColumn().setWidth(200);
    colName.getColumn().setText("DB Info");

    TreeViewerColumn colApproval = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colApproval.getColumn().setWidth(70);
    colApproval.getColumn().setText("User");

    TreeViewerColumn colVisible = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colVisible.getColumn().setWidth(40);
    colVisible.getColumn().setText("Visible");

    TreeViewerColumn colCreateTime = new TreeViewerColumn(treeViewerDBList, SWT.NONE);
    colCreateTime.getColumn().setWidth(120);
    colCreateTime.getColumn().setText("Create tiem");

    treeViewerDBList.setContentProvider(new AdminUserContentProvider());
    treeViewerDBList.setLabelProvider(new AdminUserLabelProvider());
    treeViewerDBList.setInput(initData());
    treeViewerDBList.expandToLevel(2);

    filter = new AdminCompFilter();
    treeViewerDBList.addFilter(filter);

    registerServiceHandler();

    // google analytic
    AnalyticCaller.track(this.getClass().getName());

}

From source file:com.hangum.tadpole.manager.core.editor.auth.DBListComposite.java

License:Open Source License

/**
 * modify db//from ww  w . j  a va2  s  .c  o  m
 */
private void modifyDB() {
    IStructuredSelection ss = (IStructuredSelection) treeViewerDBList.getSelection();
    if (!ss.isEmpty()) {
        UserDBDAO userDB = (UserDBDAO) ss.getFirstElement();

        if (userDB.getGroup_seq() == SessionManager.getGroupSeq()) {
            final ModifyDBDialog dialog = new ModifyDBDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), userDB);
            final int ret = dialog.open();

            if (ret == Dialog.OK) {
                treeViewerDBList.setInput(initData());
                refreshConnections();
            }
        }
    }
}

From source file:com.hangum.tadpole.manager.core.editor.auth.DBListComposite.java

License:Open Source License

/**
 * delete db (delete marking)/*from  w w  w  . j a va2  s .c o m*/
 */
private void deleteDB() {
    IStructuredSelection ss = (IStructuredSelection) treeViewerDBList.getSelection();
    if (!ss.isEmpty()) {
        if (!MessageDialog.openConfirm(null, "Confirm", "Do you want to delete the selected database?")) //$NON-NLS-1$
            return;

        UserDBDAO userDB = (UserDBDAO) ss.getFirstElement();

        try {
            if (userDB.getGroup_seq() == SessionManager.getGroupSeq()) {
                TadpoleSystem_UserDBQuery.removeUserDB(userDB.getSeq());
                TadpoleSQLManager.removeInstance(userDB);
                treeViewerDBList.setInput(initData());
                refreshConnections();
            }
        } catch (Exception e) {
            logger.error("disconnection exception", e);
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", //$NON-NLS-1$
                    "Disconnection Exception", errStatus); //$NON-NLS-1$
        }
    }
}

From source file:com.hangum.tadpole.manager.core.editor.auth.dialogs.DBAccessControlDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//  w w w .  j a  v a 2  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(2, false));

    Label lblDbName = new Label(compositeHead, SWT.NONE);
    lblDbName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDbName.setText("DB Name");

    textDBName = new Text(compositeHead, SWT.BORDER);
    textDBName.setEditable(false);
    textDBName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textDBName.setText(useDB.getDisplay_name());

    Label lblUser = new Label(compositeHead, SWT.NONE);
    lblUser.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblUser.setText("User");

    comboUser = new Combo(compositeHead, SWT.READ_ONLY);
    comboUser.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initData();
        }
    });
    comboUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    List<TadpoleUserDbRoleDAO> listUser = useDB.getListChildren();
    for (int i = 0; i < listUser.size(); i++) {
        TadpoleUserDbRoleDAO tadpoleUserDbRoleDAO = listUser.get(i);
        comboUser
                .add(String.format("%s (%s)", tadpoleUserDbRoleDAO.getName(), tadpoleUserDbRoleDAO.getEmail()));
        comboUser.setData("" + i, tadpoleUserDbRoleDAO);
    }
    comboUser.select(0);
    new Label(compositeHead, SWT.NONE);

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

    Group grpAuthority = new Group(compositeBody, SWT.NONE);
    grpAuthority.setLayout(new GridLayout(2, false));
    grpAuthority.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpAuthority.setText("Authority(Does't use check)");

    btnSelect = new Button(grpAuthority, SWT.CHECK);
    btnSelect.setEnabled(false);
    btnSelect.setSelection(true);
    btnSelect.setText("SELECT");

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

    btnSelectAdd = new Button(compositeSelectBtn, SWT.NONE);
    btnSelectAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            TableColumnFilterDialog tableColumnDialog = new TableColumnFilterDialog(getShell(), dbAccessDetail);
            if (Dialog.OK == tableColumnDialog.open()) {
                listTableColumn.add(tableColumnDialog.getUpdateData());
                tvSelect.refresh();
            }
        }
    });
    btnSelectAdd.setText("Add");

    btnSelectDelete = new Button(compositeSelectBtn, SWT.NONE);
    btnSelectDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection iss = (IStructuredSelection) tvSelect.getSelection();
            if (!iss.isEmpty()) {
                if (!MessageDialog.openConfirm(getShell(), "Confirm", "Do you want delete"))
                    return;

                AccessCtlObjectDAO dao = (AccessCtlObjectDAO) iss.getFirstElement();

                listTableColumn.remove(dao);
                tvSelect.refresh();
            }
        }
    });
    btnSelectDelete.setText("Delete");
    btnSelectDelete.setEnabled(false);
    new Label(compositeSelectBtn, SWT.NONE);

    new Label(grpAuthority, SWT.NONE);

    tvSelect = new TableViewer(grpAuthority, SWT.BORDER | SWT.FULL_SELECTION);
    tvSelect.addPostSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            btnSelectDelete.setEnabled(true);
        }
    });
    tvSelect.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection iss = (IStructuredSelection) event.getSelection();
            if (!iss.isEmpty()) {
                AccessCtlObjectDAO acObject = (AccessCtlObjectDAO) iss.getFirstElement();

                TableColumnFilterDialog tableColumnDialog = new TableColumnFilterDialog(getShell(),
                        dbAccessDetail, acObject);
                if (Dialog.OK == tableColumnDialog.open()) {
                    //                  listTableColumn.add(tableColumnDialog.getUpdateData());
                    tvSelect.refresh();
                }
            }

        }
    });
    Table table = tvSelect.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TableViewerColumn tvColumnName = new TableViewerColumn(tvSelect, SWT.NONE);
    TableColumn tblclmnTable = tvColumnName.getColumn();
    tblclmnTable.setWidth(150);
    tblclmnTable.setText("Table");

    TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tvSelect, SWT.NONE);
    TableColumn tblclmnDoNotUse = tableViewerColumn_2.getColumn();
    tblclmnDoNotUse.setWidth(60);
    tblclmnDoNotUse.setText("Do not use");

    TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tvSelect, SWT.NONE);
    TableColumn tblclmnColumn = tableViewerColumn_1.getColumn();
    tblclmnColumn.setWidth(500);
    tblclmnColumn.setText("Column");

    tvSelect.setContentProvider(new ArrayContentProvider());
    tvSelect.setLabelProvider(new SelectTableFilterLabelprovider());
    tvSelect.setInput(listTableColumn);

    btnInsert = new Button(grpAuthority, SWT.CHECK);
    btnInsert.setText("INSERT");
    new Label(grpAuthority, SWT.NONE);

    btnUpdate = new Button(grpAuthority, SWT.CHECK);
    btnUpdate.setText("UPDATE");
    new Label(grpAuthority, SWT.NONE);

    btnDelete = new Button(grpAuthority, SWT.CHECK);
    btnDelete.setText("DELETE");
    new Label(grpAuthority, SWT.NONE);

    btnDdl = new Button(grpAuthority, SWT.CHECK);
    btnDdl.setText("DDL");
    new Label(grpAuthority, SWT.NONE);

    firstInit();
    initData();

    return container;
}

From source file:com.hangum.tadpole.manager.core.editor.auth.dialogs.TableColumnFilterDialog.java

License:Open Source License

/**
 * delete filter/*from  w ww .j  a v  a2s. c  om*/
 */
private void deleteFilter() {
    IStructuredSelection iss = (IStructuredSelection) tvTableFilter.getSelection();
    if (iss.isEmpty())
        return;

    TableFilterDAO tableFilterDao = (TableFilterDAO) iss.getFirstElement();
    if (MessageDialog.openConfirm(getShell(), "Confirm", "Do you want to delete filter?")) {
        try {
            TadpoleSystem_TableColumnFilter.deleteTableColumnFilters(tableFilterDao);
            initData();
        } catch (Exception e) {
            logger.error("delete tablefilter exception", e);
        }
    }
}

From source file:com.hangum.tadpole.manager.core.editor.db.DBListComposite.java

License:Open Source License

/**
 * Create the composite.//from  w  ww .j a  v  a  2 s.  co m
 * @param parent
 * @param style
 * @param userDAO 
 * @param roleType 
 */
public DBListComposite(Composite parent, int style, UserDAO userDAO, USER_ROLE_TYPE roleType) {
    super(parent, style);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    setLayout(gridLayout);
    this.userDAO = userDAO;
    this.roleType = roleType;

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

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

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setImage(GlobalImageUtils.getRefresh());
    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initData();
        }
    });
    tltmRefresh.setToolTipText(Messages.get().Refresh);

    ToolItem toolItem_0 = new ToolItem(toolBar, SWT.SEPARATOR);

    tltmConfigurationDB = new ToolItem(toolBar, SWT.NONE);
    tltmConfigurationDB.setImage(GlobalImageUtils.getConfigurationDatabase());
    tltmConfigurationDB.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            configurationDB();
        }
    });
    tltmConfigurationDB.setToolTipText(Messages.get().DBListComposite_1);
    tltmConfigurationDB.setEnabled(false);

    tltmOtherInformation = new ToolItem(toolBar, SWT.NONE);
    tltmOtherInformation.setImage(GlobalImageUtils.getOtherInformation());
    tltmOtherInformation.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection ss = (IStructuredSelection) tvDBList.getSelection();
            if (ss.isEmpty())
                return;

            DBOthresConfigDialog othersDialog = new DBOthresConfigDialog(getShell(),
                    (UserDBDAO) ss.getFirstElement());
            if (othersDialog.open() == Dialog.OK) {
                tvDBList.refresh(othersDialog.getUserDBDAO());
            }
        }
    });
    tltmOtherInformation.setEnabled(false);
    tltmOtherInformation.setToolTipText(Messages.get().DBListComposite_2);

    ToolItem toolItem_1 = new ToolItem(toolBar, SWT.SEPARATOR);

    tltmAddUser = new ToolItem(toolBar, SWT.NONE);
    tltmAddUser.setImage(GlobalImageUtils.getUserAdd());
    tltmAddUser.setEnabled(false);
    tltmAddUser.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection ss = (IStructuredSelection) tvDBList.getSelection();
            if (ss.isEmpty())
                return;

            UserDBDAO userDB = (UserDBDAO) ss.getFirstElement();

            FindUserAndDBRoleDialog dialog = new FindUserAndDBRoleDialog(getShell(),
                    (UserDBDAO) ss.getFirstElement());
            dialog.open();

            userDB.getListChildren().clear();
            try {
                List<TadpoleUserDbRoleDAO> listUser = TadpoleSystem_UserRole.getUserRoleList(userDB);
                if (userDB.getListChildren().isEmpty()) {
                    for (TadpoleUserDbRoleDAO tadpoleUserDbRoleDAO : listUser) {
                        tadpoleUserDbRoleDAO.setParent(userDB);
                    }

                    userDB.setListChildren(listUser);
                    tvDBList.refresh(userDB, true);
                    tvDBList.expandToLevel(3);
                }
            } catch (Exception e3) {
                logger.error(Messages.get().DBListComposite_10, e3);
            }

            //            TadpoleUserDbRoleDAO userRole = dialog.getUserRoleDAO();
            //            userRole.setParent(userDB);
            //            userDB.getListChildren().add(userRole);
            //            
            //            tvDBList.refresh(userDB);

        }
    });
    tltmAddUser.setToolTipText(Messages.get().DBListComposite_3);

    tltmDBAccessCtl = new ToolItem(toolBar, SWT.NONE);
    tltmDBAccessCtl.setImage(GlobalImageUtils.getFiltering());
    tltmDBAccessCtl.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection ss = (IStructuredSelection) tvDBList.getSelection();
            if (ss.isEmpty())
                return;

            DBAccessControlDialog dbAccessCtlDialog = new DBAccessControlDialog(getShell(),
                    (TadpoleUserDbRoleDAO) ss.getFirstElement());
            dbAccessCtlDialog.open();
        }
    });
    tltmDBAccessCtl.setEnabled(false);
    tltmDBAccessCtl.setToolTipText(Messages.get().DBListComposite_4);

    tltmUserInfo = new ToolItem(toolBar, SWT.NONE);
    tltmUserInfo.setImage(GlobalImageUtils.getUserInfo());
    tltmUserInfo.setEnabled(false);
    tltmUserInfo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            detailUser();
        }
    });
    tltmUserInfo.setToolTipText(Messages.get().DBListComposite_5);

    tltmUserDelete = new ToolItem(toolBar, SWT.NONE);
    tltmUserDelete.setImage(GlobalImageUtils.getUserRemove());
    tltmUserDelete.setEnabled(false);
    tltmUserDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteUser();
        }
    });
    tltmUserDelete.setToolTipText(Messages.get().DBListComposite_6);

    ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);

    tltmQueryHistory = new ToolItem(toolBar, SWT.NONE);
    tltmQueryHistory.setImage(GlobalImageUtils.getQueryHistory()); //$NON-NLS-1$
    tltmQueryHistory.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewQueryHistory();
        }
    });
    tltmQueryHistory.setEnabled(false);
    tltmQueryHistory.setToolTipText(Messages.get().QueryHistory);

    ToolItem toolItem_2 = new ToolItem(toolBar, SWT.SEPARATOR);
    tltmSQLEditor = new ToolItem(toolBar, SWT.NONE);
    tltmSQLEditor.setImage(GlobalImageUtils.getSQLEditor()); //$NON-NLS-1$
    tltmSQLEditor.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            sqlEditor();
        }
    });
    tltmSQLEditor.setEnabled(false);
    tltmSQLEditor.setToolTipText(Messages.get().DBListComposite_8);

    Label label = new Label(compositeHead, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblUser = new Label(compositeHead, SWT.NONE);
    Label lblUserName = new Label(compositeHead, SWT.NONE);
    if (userDAO != null) {
        lblUser.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        lblUser.setText(Messages.get().DBListComposite_26);

        lblUserName.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        lblUserName.setText(String.format("%s(%s)", userDAO.getName(), userDAO.getEmail())); //$NON-NLS-1$
    }
    Label lblSearch = new Label(compositeHead, SWT.NONE);
    lblSearch.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblSearch.setText(Messages.get().Search);

    textSearch = new Text(compositeHead, SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    textSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

    textSearch.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            filter.setSearchString(textSearch.getText());
            tvDBList.refresh();
        }
    });

    Composite compositeBody = new Composite(this, SWT.NONE);
    GridLayout gl_compositeBody = new GridLayout(1, false);
    gl_compositeBody.verticalSpacing = 2;
    gl_compositeBody.horizontalSpacing = 2;
    gl_compositeBody.marginHeight = 2;
    gl_compositeBody.marginWidth = 2;
    compositeBody.setLayout(gl_compositeBody);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    tvDBList = new TreeViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    tvDBList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {

            IStructuredSelection ss = (IStructuredSelection) tvDBList.getSelection();
            if (ss.isEmpty())
                return;

            Object objSelect = ss.getFirstElement();
            if (objSelect instanceof UserDBDAO) {
                UserDBDAO userDB = (UserDBDAO) objSelect;
                try {
                    List<TadpoleUserDbRoleDAO> listUser = TadpoleSystem_UserRole.getUserRoleList(userDB);
                    if (userDB.getListChildren().isEmpty()) {
                        for (TadpoleUserDbRoleDAO tadpoleUserDbRoleDAO : listUser) {
                            tadpoleUserDbRoleDAO.setParent(userDB);
                        }

                        userDB.setListChildren(listUser);
                        tvDBList.refresh(userDB, true);
                        tvDBList.expandToLevel(3);
                    }
                } catch (Exception e) {
                    logger.error(Messages.get().DBListComposite_10, e);
                }

                tltmConfigurationDB.setEnabled(true);
                tltmOtherInformation.setEnabled(true);

                tltmAddUser.setEnabled(true);

                tltmUserDelete.setEnabled(false);
                tltmUserInfo.setEnabled(false);
                tltmDBAccessCtl.setEnabled(false);

                tltmQueryHistory.setEnabled(true);
                tltmSQLEditor.setEnabled(true);
            } else if (objSelect instanceof TadpoleUserDbRoleDAO) {
                TadpoleUserDbRoleDAO userDBRole = (TadpoleUserDbRoleDAO) objSelect;
                if (userDBRole.getParent().getUser_seq() != userDBRole.getUser_seq()) {
                    tltmUserDelete.setEnabled(true);
                    tltmUserInfo.setEnabled(true);
                    tltmDBAccessCtl.setEnabled(true);
                } else {
                    tltmUserDelete.setEnabled(false);
                    tltmUserInfo.setEnabled(false);
                    tltmDBAccessCtl.setEnabled(false);
                }
                tltmAddUser.setEnabled(false);
                tltmConfigurationDB.setEnabled(false);
                tltmOtherInformation.setEnabled(false);

                tltmQueryHistory.setEnabled(false);
                tltmSQLEditor.setEnabled(false);

                // don't use mongodb
                if (userDBRole.getParent().getDBDefine() == DBDefine.MONGODB_DEFAULT) {
                    tltmDBAccessCtl.setEnabled(false);
                }

            } else if (objSelect instanceof ManagerListDTO) {

                tltmConfigurationDB.setEnabled(false);
                tltmOtherInformation.setEnabled(false);

                tltmAddUser.setEnabled(false);
                tltmUserDelete.setEnabled(false);
                tltmUserInfo.setEnabled(false);
                tltmDBAccessCtl.setEnabled(false);
                tltmQueryHistory.setEnabled(false);
                tltmSQLEditor.setEnabled(false);
            }

        }
    });
    tvDBList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            viewQueryHistory();
        }
    });
    Tree treeAdmin = tvDBList.getTree();
    treeAdmin.setLinesVisible(true);
    treeAdmin.setHeaderVisible(true);
    treeAdmin.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    treeAdmin.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);

    TreeViewerColumn colGroupName = new TreeViewerColumn(tvDBList, SWT.NONE);
    colGroupName.getColumn().setWidth(250);
    colGroupName.getColumn().setText(Messages.get().DBListComposite_11);

    TreeViewerColumn colRoleName = new TreeViewerColumn(tvDBList, SWT.NONE);
    colRoleName.getColumn().setWidth(80);
    colRoleName.getColumn().setText(Messages.get().Role);

    TreeViewerColumn colName = new TreeViewerColumn(tvDBList, SWT.NONE);
    colName.getColumn().setWidth(330);
    colName.getColumn().setText(Messages.get().DBInfo + "(" + Messages.get().DBListComposite_16 + ")"); //$NON-NLS-1$ //$NON-NLS-2$

    TreeViewerColumn colApproval = new TreeViewerColumn(tvDBList, SWT.NONE);
    colApproval.getColumn().setWidth(70);
    colApproval.getColumn().setText(Messages.get().User);

    TreeViewerColumn colVisible = new TreeViewerColumn(tvDBList, SWT.NONE);
    colVisible.getColumn().setWidth(50);
    colVisible.getColumn().setText(Messages.get().DBListComposite_15);

    tvDBList.setContentProvider(new DBListContentProvider());
    tvDBList.setLabelProvider(new DBListLabelProvider());
    tvDBList.setInput(listUserDBs);
    initData();
    tvDBList.expandToLevel(2);

    filter = new AdminCompFilter();
    tvDBList.addFilter(filter);

    // google analytic
    AnalyticCaller.track(this.getClass().getName());

}