Search in sources :

Example 1 with InputDialog

use of net.heartsome.cat.ts.ui.dialog.InputDialog in project translationstudio8 by heartsome.

the class ProjectPropertiesPreferencePage method initListener.

private void initListener() {
    btnFieldAdd.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            String[] arrField = fieldList.getItems();
            InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title1"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl1"), null, new InputValidator(FIELD_ADD, new ArrayList<String>(Arrays.asList(arrField))));
            if (dialog.open() == IDialogConstants.OK_ID) {
                String fieldVal = dialog.getValue();
                fieldList.add(fieldVal.trim());
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnFieldEdit.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (fieldList.getSelectionCount() <= 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg10"));
                return;
            } else if (fieldList.getSelectionCount() > 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg11"));
                return;
            } else {
                int selIndex = fieldList.getSelectionIndex();
                String selVal = fieldList.getSelection()[0];
                ArrayList<String> lstField = new ArrayList<String>(Arrays.asList(fieldList.getItems()));
                lstField.remove(selVal);
                InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title4"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl1"), selVal, new InputValidator(FIELD_ADD, lstField));
                if (dialog.open() == IDialogConstants.OK_ID) {
                    String fieldVal = dialog.getValue().trim();
                    fieldList.remove(selIndex);
                    fieldList.add(fieldVal, selIndex);
                    fieldList.select(selIndex);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnFieldDel.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (fieldList.getSelectionCount() == 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg8"));
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle1"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg1"))) {
                fieldList.remove(fieldList.getSelectionIndices());
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    attrNameList.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrNameList.getSelectionCount() > 0) {
                String strSel = attrNameList.getSelection()[0];
                ArrayList<String> lstAttrVal = mapAttr.get(strSel);
                attrValList.removeAll();
                attrValList.setItems(lstAttrVal.toArray(new String[lstAttrVal.size()]));
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrNameAdd.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            String[] arrAttrName = attrNameList.getItems();
            InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl2"), null, new InputValidator(ATTRNAME_ADD, new ArrayList<String>(Arrays.asList(arrAttrName))));
            if (dialog.open() == IDialogConstants.OK_ID) {
                String attrName = dialog.getValue().trim();
                attrNameList.add(attrName);
                mapAttr.put(attrName, new ArrayList<String>());
                attrNameList.setSelection(new String[] { attrName });
                attrValList.removeAll();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrNameEdit.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrNameList.getSelectionCount() <= 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg10"));
                return;
            } else if (attrNameList.getSelectionCount() > 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg11"));
                return;
            } else {
                int selIndex = attrNameList.getSelectionIndex();
                String selVal = attrNameList.getSelection()[0];
                ArrayList<String> lstAttrVal = mapAttr.get(selVal);
                ArrayList<String> lstAttrName = new ArrayList<String>(Arrays.asList(attrNameList.getItems()));
                lstAttrName.remove(selVal);
                InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title5"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl2"), selVal, new InputValidator(ATTRNAME_ADD, lstAttrName));
                if (dialog.open() == IDialogConstants.OK_ID) {
                    String attrNameVal = dialog.getValue().trim();
                    attrNameList.remove(selIndex);
                    attrNameList.add(attrNameVal, selIndex);
                    attrNameList.select(selIndex);
                    mapAttr.remove(selVal);
                    mapAttr.put(attrNameVal, lstAttrVal);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrNameDel.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrNameList.getSelectionCount() == 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg8"));
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle1"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg1"))) {
                String[] arrSelName = attrNameList.getSelection();
                for (String attrName : arrSelName) {
                    mapAttr.remove(attrName);
                }
                attrNameList.remove(attrNameList.getSelectionIndices());
                if (attrNameList.getSelectionCount() > 0) {
                    String strSel = attrNameList.getSelection()[0];
                    ArrayList<String> lstAttrVal = mapAttr.get(strSel);
                    attrValList.removeAll();
                    attrValList.setItems(lstAttrVal.toArray(new String[lstAttrVal.size()]));
                } else {
                    attrValList.removeAll();
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrValAdd.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrNameList.getSelectionCount() != 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg9"));
                return;
            }
            String[] arrAttrVal = attrValList.getItems();
            InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title3"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl3"), null, new InputValidator(ATTRVAL_ADD, new ArrayList<String>(Arrays.asList(arrAttrVal))));
            if (dialog.open() == IDialogConstants.OK_ID) {
                String attrVal = dialog.getValue().trim();
                attrValList.add(attrVal);
                String attrName = attrNameList.getSelection()[0];
                mapAttr.get(attrName).add(attrVal);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrValEdit.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrValList.getSelectionCount() <= 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg10"));
                return;
            } else if (attrValList.getSelectionCount() > 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg11"));
                return;
            } else {
                int selIndex = attrValList.getSelectionIndex();
                String selVal = attrValList.getSelection()[0];
                String attrName = attrNameList.getSelection()[0];
                ArrayList<String> lstAttrVal = new ArrayList<String>(Arrays.asList(attrValList.getItems()));
                lstAttrVal.remove(selVal);
                InputDialog dialog = new InputDialog(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.title6"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.AddDialog.lbl3"), selVal, new InputValidator(ATTRVAL_ADD, lstAttrVal));
                if (dialog.open() == IDialogConstants.OK_ID) {
                    String attrVal = dialog.getValue().trim();
                    attrValList.remove(selIndex);
                    attrValList.add(attrVal, selIndex);
                    attrValList.select(selIndex);
                    lstAttrVal = mapAttr.get(attrName);
                    lstAttrVal.set(selIndex, attrVal);
                }
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnAttrValDel.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (attrNameList.getSelectionCount() != 1) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg9"));
                return;
            }
            if (attrValList.getSelectionCount() == 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle2"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg8"));
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msgTitle1"), Messages.getString("preferencepage.ProjectPropertiesPreferencePage.msg1"))) {
                String attrName = attrNameList.getSelection()[0];
                String[] arrSelVal = attrValList.getSelection();
                mapAttr.get(attrName).removeAll(new ArrayList<String>(Arrays.asList(arrSelVal)));
                attrValList.remove(attrValList.getSelectionIndices());
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : InputDialog(net.heartsome.cat.ts.ui.dialog.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ArrayList (java.util.ArrayList)1 InputDialog (net.heartsome.cat.ts.ui.dialog.InputDialog)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Point (org.eclipse.swt.graphics.Point)1