Example usage for org.eclipse.jface.dialogs MessageDialog openInformation

List of usage examples for org.eclipse.jface.dialogs MessageDialog openInformation

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openInformation.

Prototype

public static void openInformation(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard information dialog.

Usage

From source file:com.amalto.workbench.actions.XSDDeleteTypeDefinition.java

License:Open Source License

@Override
public IStatus doAction() {
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    ArrayList<Object> objList = new ArrayList<Object>();
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getSchemaContentProvider());
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getTypeContentProvider());

    XSDTypeDefinition usingElement = findUsingElement(selection, objList);
    if (usingElement != null) {
        String message = getInfoDialogMessage(usingElement);
        MessageDialog.openInformation(page.getSite().getShell(), Messages.XSDDeleteTypeDefinition_ConfirmDel,
                message);/*from w w w  .  j av  a2  s . c  o m*/
        return Status.CANCEL_STATUS;
    }
    // edit by ymli; fix the bug:0012228. Made the multiple types can be deleted.
    for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext();) {
        XSDTypeDefinition type = iter.next();
        if (type instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
            if (xsdSimpType != null) {
                simpleType = xsdSimpType;
            }
            schema.getContents().remove(simpleType);
        } else {
            XSDComplexTypeDefinition complxType = (XSDComplexTypeDefinition) type;
            if (xsdCmpexType != null) {
                complxType = xsdCmpexType;
            }
            schema.getContents().remove(complxType);
        }
    }
    xsdSimpType = null;
    xsdCmpexType = null;
    page.refresh();
    page.markDirty();
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDPasteConceptAction.java

License:Open Source License

public void addAnnotationForXSDElementDeclaration(XSDElementDeclaration fromElem,
        XSDElementDeclaration toElem) {//from ww  w. ja  v a 2  s.  com
    if (fromElem.getAnnotation() != null) {
        // toElem.setAnnotation(cloneXSDAnnotation(toElem.getAnnotation(),fromElem.getAnnotation()));
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(toElem);
        addAnnotion(struc, fromElem.getAnnotation());
    }
    if (fromElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) fromElem.getTypeDefinition())
                .getContent();
        // if the concept is a complex type itself. copy the complex type also,
        // in this situation,if not copy the complex type, the type change to simple type
        if (this.typeList.containsKey(toElem.getTypeDefinition().getName())) {
            this.copyTypeSet.add(this.typeList.get(toElem.getTypeDefinition().getName()));
        }

        if (toElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent tocomplexType = ((XSDComplexTypeDefinition) toElem.getTypeDefinition())
                    .getContent();
            if (fromcomplexType instanceof XSDParticle) {

                XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
                XSDParticle toxsdParticle = (XSDParticle) tocomplexType;

                if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {

                    XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
                    XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());

                    EList<XSDParticle> fromlist = frommodelGroup.getContents();
                    EList<XSDParticle> tolist = tomodelGroup.getContents();

                    Iterator<XSDParticle> toIt = tolist.iterator();

                    for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                        XSDParticle toel = toIt.next();
                        XSDTerm totm = toel.getTerm();
                        XSDTerm fromtm = fromel.getTerm();
                        if (fromtm instanceof XSDElementDeclaration) {
                            XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                            if (fromannotation != null) {
                                // ((XSDElementDeclaration)
                                // totm).setAnnotation(cloneXSDAnnotation(((XSDElementDeclaration)
                                // totm).getAnnotation(),fromannotation));
                                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                                if (((XSDElementDeclaration) totm).getType() != null) {
                                    addAnnotion(struc, fromannotation);
                                } else {
                                    MessageDialog.openInformation(page.getSite().getShell(), Messages.Warning,
                                            Messages.bind(Messages.XSDPasteConceptAction_Information,
                                                    fromElem.getName()));
                                    return;
                                }

                            }
                            if (((XSDElementDeclaration) totm).getType() != null && this.typeList
                                    .containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                                this.copyTypeSet.add(
                                        this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                            }
                            addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm,
                                    (XSDElementDeclaration) totm);
                        }
                    }
                }
            }
        }
    } else {
        String simpleType = fromElem.getTypeDefinition().getName();
        if (this.typeList.containsKey(simpleType)) {
            this.copyTypeSet.add(fromElem.getTypeDefinition());
        }
    }
}

From source file:com.amalto.workbench.actions.XSDSkipToFKAction.java

License:Open Source License

@Override
public void run() {
    TreeViewer treeViewer = page.getTreeViewer();
    ISelection selection = treeViewer.getSelection();

    Object selObj = ((IStructuredSelection) selection).getFirstElement();
    if (selObj instanceof XSDParticle) {
        XSDTerm term = ((XSDParticle) selObj).getTerm();
        if (term instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) term;

            String fkPath = getFKInfo(element);
            if (fkPath == null) {
                MessageDialog.openInformation(null, Messages.XSDSkipToFKAction_actionTitle,
                        Messages.XSDSkipToFKAction_NotFoundFkInfo);
                return;
            }/*from  w  ww.j a v a  2  s  .c  o  m*/
            String entityName = getEntityName(fkPath);

            EList<XSDElementDeclaration> elementDeclarations = page.getXSDSchema().getElementDeclarations();
            for (XSDElementDeclaration elementDeclaration : elementDeclarations) {
                String name = elementDeclaration.getName();
                if (entityName.equals(name)) {
                    StructuredSelection fkSelection = new StructuredSelection(elementDeclaration);
                    page.getElementsViewer().setSelection(fkSelection);
                    break;
                }
            }

        }
    }

}

From source file:com.amalto.workbench.detailtabs.sections.providers.LanguageInfoModifier.java

License:Open Source License

private void onModfiyColumnLanguage(LanguageInfo modifiedElement, Integer newSelectedIndex) {

    if (isNewLanguageExistedAlready(modifiedElement, allLanguages.get(newSelectedIndex))) {
        MessageDialog.openInformation(null, Messages.LanguageInfoModifier_Warnning,
                Messages.bind(Messages.LanguageInfoModifier_InfoContent, allLanguages.get(newSelectedIndex)));
        return;// w  w w  . j  a v  a2s. co m
    }

    modifiedElement.setLanguage(allLanguages.get(newSelectedIndex));
}

From source file:com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {

    // Should not really be here but well,....
    parent.getShell().setText(this.title);

    Composite composite = (Composite) super.createDialogArea(parent);

    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 3;/*from www.  j a  va 2  s.c o m*/
    // layout.verticalSpacing = 10;

    languagesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
    Set<String> languages = Util.lang2iso.keySet();
    for (Iterator iter = languages.iterator(); iter.hasNext();) {
        String language = (String) iter.next();
        languagesCombo.add(language);
    }
    languagesCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
        }
    });
    languagesCombo.select(0);

    labelText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    ((GridData) labelText.getLayoutData()).minimumWidth = 150;
    labelText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                String isoCode = Util.lang2iso.get(languagesCombo.getText());
                descriptionsMap.put(isoCode, labelText.getText());
                descriptionsViewer.refresh();
            }
        }
    });

    Button addLabelButton = new Button(composite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String code = Util.lang2iso.get(languagesCombo.getText());
            descriptionsMap.put(code, labelText.getText());
            descriptionsViewer.refresh();
        };
    });

    final String LANGUAGE = Messages.AnnotationLanguageLabelsDialog_Language;
    final String LABEL = Messages.AnnotationLanguageLabelsDialog_Label;

    descriptionsViewer = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = descriptionsViewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
    new TableColumn(table, SWT.CENTER).setText(LABEL);
    table.getColumn(0).setWidth(150);
    table.getColumn(1).setWidth(150);
    for (int i = 2, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    Button delLabelButton = new Button(composite, SWT.PUSH);
    delLabelButton.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false, 1, 1));
    delLabelButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    delLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Del);
    delLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            deleteItem();
        };
    });
    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new ComboBoxCellEditor(table, Util.lang2iso.keySet().toArray(new String[] {}), SWT.READ_ONLY);
    editors[1] = new TextCellEditor(table);
    descriptionsViewer.setCellEditors(editors);

    // set the content provider
    descriptionsViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            // System.out.println("getElements() ");
            LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
            Set<String> languages = descs.keySet();
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (Iterator iter = languages.iterator(); iter.hasNext();) {
                String language = ((String) iter.next());
                DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
                lines.add(line);
            }
            // we return an instance line made of a Sring and a boolean
            return lines.toArray(new DescriptionLine[lines.size()]);
        }
    });

    // set the label provider
    descriptionsViewer.setLabelProvider(new ITableLabelProvider() {

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            // System.out.println("getColumnText() "+columnIndex);
            DescriptionLine line = (DescriptionLine) element;
            switch (columnIndex) {
            case 0:
                return line.getLanguage();
            case 1:
                return line.getLabel();
            }
            return "";//$NON-NLS-1$
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    // Set the column properties
    descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });

    // set the Cell Modifier
    descriptionsViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
            return true;
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) item.getData();
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                int orgIndx = Arrays.asList(attrs).indexOf(line.getLanguage());
                if (orgIndx != Integer.parseInt(value.toString())) {
                    String newLang = attrs[Integer.parseInt(value.toString())];
                    if (descriptionsMap.containsKey(Util.lang2iso.get(newLang))) {
                        MessageDialog.openInformation(null, Messages.Warnning,
                                Messages.AnnotationLanguageLabelsDialog_InforContent);
                        return;
                    }
                    descriptionsMap.remove(Util.lang2iso.get(line.getLanguage()));
                    line.setLanguage(newLang);
                    descriptionsMap.put(Util.lang2iso.get(newLang), line.getLabel());
                }
            } else // column label
            {
                line.setLabel(value.toString());
                descriptionsMap.put(Util.lang2iso.get(line.getLanguage()), line.getLabel());
            }

            descriptionsViewer.update(line, null);
        }

        public Object getValue(Object element, String property) {
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) element;
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                return Arrays.asList(attrs).indexOf(line.getLanguage());
            } else {
                if (LANGUAGE.equals(property)) {
                    return line.getLanguage();
                }
                if (LABEL.equals(property)) {
                    return line.getLabel();
                }
            }

            return null;
        }
    });

    // Listen for changes in the selection of the viewer to display additional parameters
    descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });

    // display for Delete Key events to delete an instance
    descriptionsViewer.getTable().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            // System.out.println("Table keyReleased() ");
            if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) {
                deleteItem();
            }
        }
    });

    descriptionsViewer.setInput(descriptionsMap);
    descriptionsViewer.refresh();

    labelText.setFocus();

    return composite;
}

From source file:com.amalto.workbench.dialogs.AnnotationOrderedListsDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    // Should not really be here but well,....

    parent.getShell().setText(this.title);

    Composite composite = (Composite) super.createDialogArea(parent);

    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 3;/*from w w  w.j  a  va2  s  .c o  m*/
    layout.makeColumnsEqualWidth = false;
    // layout.verticalSpacing = 10;

    if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType) {
        textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);

        // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
        roles = getAllRolesStr();
        ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));

    } else if (actionType == AnnotationLookupField_ActionType
            || actionType == AnnotationPrimaKeyInfo_ActionType) {
        textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);

        // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
        roles = getConceptElements();
        ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));

    } else {
        if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
            textControl = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        } else {
            textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
        }
    }

    if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
        textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    } else {
        if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
            textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 7));
        } else {
            textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        }
    }

    ((GridData) textControl.getLayoutData()).minimumWidth = 400;

    textControl.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                xPaths.add(AnnotationOrderedListsDialog.getControlText(textControl));
                viewer.refresh();
                fireXPathsChanges();
            }
        }
    });

    if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
        Button xpathButton = new Button(composite, SWT.PUSH | SWT.CENTER);
        xpathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
        xpathButton.setText("...");//$NON-NLS-1$
        xpathButton.setToolTipText(Messages.AnnotationOrderedListsDialog_SelectXpath);
        xpathButton.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {

            }

            public void widgetSelected(SelectionEvent e) {
                XpathSelectDialog dlg = getNewXpathSelectDialog(parentPage, dataModelName);

                dlg.setLock(lock);

                dlg.setBlockOnOpen(true);

                dlg.open();

                if (dlg.getReturnCode() == Window.OK) {
                    ((Text) textControl).setText(dlg.getXpath());
                    dlg.close();
                }

            }

        });

    }

    Button addLabelButton = new Button(composite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    // addLabelButton.setText("Set");
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.AnnotationOrderedListsDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            boolean exist = false;
            for (String string : xPaths) {
                if (string.equals(getControlText(textControl))) {
                    exist = true;
                }
            }
            if (!exist && getControlText(textControl) != null && getControlText(textControl) != "") {
                xPaths.add(getControlText(textControl));
            }
            viewer.refresh();
            fireXPathsChanges();
        };
    });

    final String COLUMN = columnName;

    viewer = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) viewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = viewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.CENTER).setText(COLUMN);
    table.getColumn(0).setWidth(500);
    for (int i = 1, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[1];
    if (actionType == AnnotationOrderedListsDialog.AnnotationWrite_ActionType
            || actionType == AnnotationOrderedListsDialog.AnnotationHidden_ActionType
            || actionType == AnnotationLookupField_ActionType
            || actionType == AnnotationPrimaKeyInfo_ActionType) {
        editors[0] = new ComboBoxCellEditor(table, roles.toArray(new String[] {}), SWT.READ_ONLY);
    } else {
        editors[0] = new TextCellEditor(table);
    }

    viewer.setCellEditors(editors);

    // set the content provider
    viewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            @SuppressWarnings("unchecked")
            ArrayList<String> xPaths = (ArrayList<String>) inputElement;
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (String xPath : xPaths) {
                DescriptionLine line = new DescriptionLine(xPath);
                lines.add(line);
            }
            // we return an instance line made of a Sring and a boolean
            return lines.toArray(new DescriptionLine[lines.size()]);
        }
    });

    // set the label provider
    viewer.setLabelProvider(new ITableLabelProvider() {

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            // System.out.println("getColumnText() "+columnIndex);
            DescriptionLine line = (DescriptionLine) element;
            switch (columnIndex) {
            case 0:
                return line.getLabel();
            }
            return "";//$NON-NLS-1$
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    // Set the column properties
    viewer.setColumnProperties(new String[] { COLUMN });

    // set the Cell Modifier
    viewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
            return true;
            // return false;
        }

        public void modify(Object element, String property, Object value) {

            TableItem item = (TableItem) element;
            DescriptionLine line = (DescriptionLine) item.getData();
            String orgValue = line.getLabel();
            if (actionType != AnnotationWrite_ActionType && actionType != AnnotationHidden_ActionType
                    && actionType != AnnotationLookupField_ActionType
                    && actionType != AnnotationPrimaKeyInfo_ActionType) {
                int targetPos = xPaths.indexOf(value.toString());
                if (targetPos < 0) {
                    line.setLabel(value.toString());
                    int index = xPaths.indexOf(orgValue);
                    xPaths.remove(index);
                    xPaths.add(index, value.toString());
                    viewer.update(line, null);
                } else if (targetPos >= 0 && !value.toString().equals(orgValue)) {
                    MessageDialog.openInformation(null, Messages.Warning,
                            Messages.AnnotationOrderedListsDialog_ValueAlreadyExists);
                }
            } else {

                String[] attrs = roles.toArray(new String[] {});
                int index = Integer.parseInt(value.toString());
                if (index == -1) {
                    return;
                }
                value = attrs[index];
                int pos = xPaths.indexOf(value.toString());
                if (pos >= 0 && !(orgValue.equals(value))) {
                    MessageDialog.openInformation(null, Messages.Warning,
                            Messages.AnnotationOrderedListsDialog_);
                    return;
                } else if (pos < 0) {
                    line.setLabel(value.toString());
                    xPaths.set(index, value.toString());
                    viewer.update(line, null);
                }
            }

            fireXPathsChanges();
        }

        public Object getValue(Object element, String property) {
            DescriptionLine line = (DescriptionLine) element;
            String value = line.getLabel();

            if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType
                    || actionType == AnnotationLookupField_ActionType
                    || actionType == AnnotationPrimaKeyInfo_ActionType) {
                String[] attrs = roles.toArray(new String[] {});
                return Arrays.asList(attrs).indexOf(value);
            } else {
                return value;
            }

        }
    });

    // Listen for changes in the selection of the viewer to display additional parameters
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection())
                    .getFirstElement();
            if (line != null) {
                if (textControl instanceof CCombo) {
                    ((CCombo) textControl).setText(line.getLabel());
                }
                if (textControl instanceof Text) {
                    ((Text) textControl).setText(line.getLabel());
                }
            }
        }
    });

    // display for Delete Key events to delete an instance
    viewer.getTable().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            // System.out.println("Table keyReleased() ");
            if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) {
                DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection())
                        .getFirstElement();
                @SuppressWarnings("unchecked")
                ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
                xPaths.remove(line.getLabel());
                viewer.refresh();
            }
        }
    });

    viewer.setInput(xPaths);
    viewer.refresh();

    Composite rightButtonsComposite = new Composite(composite, SWT.NULL);
    rightButtonsComposite.setLayout(new GridLayout(1, true));
    rightButtonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));

    Button upButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath()));
    upButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveUpTheItem);
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection())
                    .getFirstElement();
            if (line == null) {
                return;
            }
            int i = 0;
            for (String xPath : xPaths) {
                if (xPath.equals(line.getLabel())) {
                    if (i > 0) {
                        xPaths.remove(i);
                        xPaths.add(i - 1, xPath);
                        viewer.refresh();
                        viewer.getTable().setSelection(i - 1);
                        viewer.getTable().showSelection();
                        fireXPathsChanges();
                    }
                    return;
                }
                i++;
            }
        };
    });
    Button downButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath()));
    downButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveDownTheItem);
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection())
                    .getFirstElement();
            if (line == null) {
                return;
            }
            int i = 0;
            for (String xPath : xPaths) {
                if (xPath.equals(line.getLabel())) {
                    if (i < xPaths.size() - 1) {
                        xPaths.remove(i);
                        xPaths.add(i + 1, xPath);
                        viewer.refresh();
                        viewer.getTable().setSelection(i + 1);
                        viewer.getTable().showSelection();
                        fireXPathsChanges();
                    }
                    return;
                }
                i++;
            }
        };
    });
    Button delButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    delButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    delButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    delButton.setToolTipText(Messages.AnnotationOrderedListsDialog_DelTheItem);

    delButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection())
                    .getFirstElement();
            if (line != null) {
                @SuppressWarnings("unchecked")
                ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
                xPaths.remove(line.getLabel());
                viewer.refresh();
                fireXPathsChanges();
            }
        };
    });

    textControl.setFocus();
    if (actionType != AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType
            && actionType != AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType
            && actionType != AnnotationOrderedListsDialog.AnnotationSchematron_ActionType
            && actionType != AnnotationOrderedListsDialog.AnnotationLookupField_ActionType
            && actionType != AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType) {
        checkBox = new Button(composite, SWT.CHECK);
        checkBox.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 2, 1));
        checkBox.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            };

            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                recursive = checkBox.getSelection();
            };
        });
        checkBox.setSelection(recursive);
        checkBox.setText(Messages.AnnotationOrderedListsDialog_SetRoleRecursively);
        // Label label = new Label(composite, SWT.LEFT);
        // label.setText("set role recursively");
        // label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true,
        // 1, 1));
    }

    if (actionType == AnnotationForeignKeyInfo_ActionType) {
        createFKInfoFormatComp(composite);
        addDoubleClickListener();
    }

    return composite;
}

From source file:com.amalto.workbench.editors.DataClusterComposite.java

License:Open Source License

protected LineItem[] getResults(boolean showResultInfo) {

    Cursor waitCursor = null;//from  w  w  w. jav a2 s.  c om

    try {

        waitCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT);
        getSite().getShell().setCursor(waitCursor);

        TMDMService service = Util.getMDMService(getXObject());

        long from = -1;
        long to = -1;

        Pattern pattern = Pattern.compile("^\\d{4}\\d{2}\\d{2} \\d{2}:\\d{2}:\\d{2}$");//$NON-NLS-1$

        if (!"".equals(fromText.getText())) {//$NON-NLS-1$

            String dateTimeText = fromText.getText().trim();
            Matcher matcher = pattern.matcher(dateTimeText);
            if (!matcher.matches()) {
                MessageDialog.openWarning(this.getSite().getShell(), Messages.Warning,
                        Messages.DataClusterBrowserMainPage_21);
                return new LineItem[0];
            }

            try {
                Date d = sdf.parse(fromText.getText());
                from = d.getTime();
            } catch (ParseException pe) {
            }
        }

        if (!"".equals(toText.getText())) { //$NON-NLS-1$
            String dateTimeText = toText.getText().trim();
            Matcher matcher = pattern.matcher(dateTimeText);
            if (!matcher.matches()) {
                MessageDialog.openWarning(this.getSite().getShell(), Messages.Warning,
                        Messages.DataClusterBrowserMainPage_23);
                return new LineItem[0];
            }

            try {
                Date d = sdf.parse(toText.getText());
                to = d.getTime();
            } catch (ParseException pe) {
            }
        }

        String concept = conceptCombo.getText();
        if ("*".equals(concept) | "".equals(concept)) { //$NON-NLS-1$ //$NON-NLS-2$
            concept = null;
        }
        if (concept != null) {
            concept = concept.replaceAll("\\[.*\\]", "").trim();//$NON-NLS-1$//$NON-NLS-2$
        }
        String keys = keyText.getText();
        if ("*".equals(keys) | "".equals(keys)) { //$NON-NLS-1$ //$NON-NLS-2$
            keys = null;
        }

        boolean useFTSearch = isMaster ? checkFTSearchButton.getSelection() : false;
        String search = searchText.getText();
        if ("*".equals(search) | "".equals(search)) { //$NON-NLS-1$ //$NON-NLS-2$
            search = null;
        }

        int start = pageToolBar.getStart();
        int limit = pageToolBar.getLimit();
        // see 0015909
        String clusterName = URLEncoder.encode(getXObject().toString(), "utf-8");//$NON-NLS-1$
        WSDataClusterPK clusterPk = new WSDataClusterPK(clusterName + getPkAddition());

        // @temp yguo, get item with taskid or get taskid by specify wsitempk.
        List<WSItemPKsByCriteriaResponseResults> results = service.getItemPKsByFullCriteria(
                new WSGetItemPKsByFullCriteria(useFTSearch, new WSGetItemPKsByCriteria(concept, search, from,
                        null, keys, limit, start, to, clusterPk)))
                .getResults();

        if (showResultInfo && (results.size() == 1)) {
            MessageDialog.openInformation(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_24,
                    Messages.DataClusterBrowserMainPage_25);
            return new LineItem[0];
        }
        if (results.size() == 1) {
            return new LineItem[0];
        }
        int totalSize = 0;
        List<LineItem> ress = new ArrayList<LineItem>();
        for (int i = 0; i < results.size(); i++) {
            WSItemPKsByCriteriaResponseResults result = results.get(i);
            if (i == 0) {
                totalSize = Integer.parseInt(Util.parse(result.getWsItemPK().getConceptName())
                        .getDocumentElement().getTextContent());

                continue;
            }

            ress.add(new LineItem(result.getDate(), result.getWsItemPK().getConceptName(),
                    result.getWsItemPK().getIds().toArray(new String[0]), result.getTaskId()));
        }
        pageToolBar.setTotalsize(totalSize);
        pageToolBar.refreshUI();
        return ress.toArray(new LineItem[ress.size()]);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if ((e.getLocalizedMessage() != null) && e.getLocalizedMessage().contains("10000")) { //$NON-NLS-1$
            MessageDialog.openError(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_26,
                    Messages.DataClusterBrowserMainPage_27);
        } else if (!Util.handleConnectionException(this.getSite().getShell(), e,
                Messages.DataClusterBrowserMainPage_28)) {
            MessageDialog.openError(this.getSite().getShell(), Messages.DataClusterBrowserMainPage_28,
                    e.getLocalizedMessage());
        }

        return null;
    } finally {
        try {
            this.getSite().getShell().setCursor(null);
            waitCursor.dispose();
        } catch (Exception e) {
        }
    }
}

From source file:com.amalto.workbench.editors.DataModelMainPage.java

License:Open Source License

protected void doImportSchema(final Collection<XSDSchemaContent> addtional) {
    if (null == addtional || addtional.isEmpty()) {
        return;/*  w  ww .  ja  v  a 2  s. co m*/
    }
    try {
        int flag = ConflictDialog.NONE;
        boolean dialogPopup = false;
        List<XSDSchemaContent> contents = xsdSchema.getContents();
        List<XSDSchemaContent> exists = new ArrayList<XSDSchemaContent>(contents);

        for (XSDSchemaContent content : addtional) {
            XSDSchemaContent exist = getContainedSchemaContent(exists, content);
            if (null == exist) {
                Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
                xsdSchema.getElement().appendChild(importElement);
            } else {
                if (!dialogPopup) {
                    String type = null;
                    if (exist instanceof XSDElementDeclaration) {
                        type = Messages.DataModelMainPage_entity;
                    } else if (exist instanceof XSDTypeDefinition) {
                        type = Messages.DataModelMainPage_type;
                    } else {
                        continue;
                    }
                    LabelProvider provider = getContentLabelProvider(exist);
                    String message = Messages.bind(Messages.conflict_messages, type, provider.getText(exist));
                    ConflictDialog dialog = new ConflictDialog(getSite().getShell(), message);
                    if (dialog.open() == Dialog.OK) {
                        flag = dialog.getStatus();
                        dialogPopup = dialog.applyAll;
                    } else {
                        popupImportDialog();
                        return;
                    }
                }
                if (flag == ConflictDialog.OVERWRITE) {
                    contents.remove(exist);
                    Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
                    xsdSchema.getElement().appendChild(importElement);
                }
            }
        }

        //
        validateSchema();
        markDirtyWithoutCommit();
        setXsdSchema(xsdSchema);
        getSchemaRoleFilterFromSchemaTree().setDataModelFilter(dataModelFilter);

        // refresh types
        viewer.setInput(getSite());
        typesViewer.setInput(getSite());
        MessageDialog.openInformation(getSite().getShell(), Messages.ImportXSDSche,
                Messages.ImportingXSDSchemaCompleted);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        String detail = "";//$NON-NLS-1$
        if (ex.getMessage() != null && !ex.getMessage().equals("")) {//$NON-NLS-1$
            detail += " , " + Messages.bind(Messages.Dueto, ex.getMessage()); //$NON-NLS-1$
        }
        MessageDialog.openError(getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ImportingXSDSchemaFailed, detail));
    }
}

From source file:com.amalto.workbench.editors.DataModelMainPage.java

License:Open Source License

private void createToolBar(Composite parent) {
    Composite toolBarComp = new Composite(parent, SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
    gd.heightHint = 25;//  w  ww  .  j  av  a2  s . co  m
    toolBarComp.setLayoutData(gd);
    final GridLayout glToolBarBackground = new GridLayout();
    glToolBarBackground.verticalSpacing = 0;
    glToolBarBackground.marginWidth = 0;
    glToolBarBackground.marginHeight = 0;
    glToolBarBackground.horizontalSpacing = 0;
    toolBarComp.setLayout(glToolBarBackground);
    ToolBar resultToolBar = new ToolBar(toolBarComp, SWT.FLAT | SWT.HORIZONTAL);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    resultToolBar.setLayoutData(gd);
    ToolItem importToolItem = new ToolItem(resultToolBar, SWT.PUSH);
    importToolItem.setImage(ImageCache.getCreatedImage(EImage.IMPORT.getPath()));
    importToolItem.setToolTipText(Messages.ImportText);
    importToolItem.setEnabled(!isReadOnly());

    ToolItem exportToolItem = new ToolItem(resultToolBar, SWT.PUSH);
    exportToolItem.setImage(ImageCache.getCreatedImage(EImage.EXPORT.getPath()));
    exportToolItem.setToolTipText(Messages.ExportText);
    exportToolItem.setEnabled(!isReadOnly());

    ToolItem importSchemalItem = new ToolItem(resultToolBar, SWT.PUSH);
    importSchemalItem.setImage(ImageCache.getCreatedImage(EImage.CHECKIN_ACTION.getPath()));
    importSchemalItem.setToolTipText(Messages.ImportIncludeSchema);
    importSchemalItem.setEnabled(!isReadOnly());

    importToolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
            fd.setFilterExtensions(new String[] { "*.xsd", "*.dtd", "*.xml" });//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            // set the default path to the workspace.
            fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
            fd.setText(Messages.SelectXMLDefinition);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            xsdSchema = null;
            inferXsdFromXml(filename);
        }

        private void inferXsdFromXml(String xmlFile) {
            int infer = 0;
            String xsd = "";//$NON-NLS-1$
            try {
                String inputType = xmlFile.substring(xmlFile.lastIndexOf("."));//$NON-NLS-1$
                if (inputType.equals(".xsd")) {//$NON-NLS-1$
                    xsd = Util.getXML(xmlFile);
                    xsdSchema = Util.createXsdSchema(xsd, xobject);
                    xsd = Util.nodeToString(xsdSchema.getDocument());
                } else {
                    XSDDriver d = new XSDDriver();
                    infer = d.doMain(new String[] { xmlFile, "out.xsd" });//$NON-NLS-1$
                    if (infer == 0) {
                        xsd = d.outputXSD();
                    }
                }

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                infer = 2;
            } finally {
                if (infer == 0 && !xsd.equals("")) {//$NON-NLS-1$
                    WSDataModel wsObj = (WSDataModel) (xobject.getWsObject());
                    wsObj.setXsdSchema(xsd);
                    validateSchema(xsd);
                    refreshData();
                    markDirtyWithoutCommit();
                } else if (infer != 0) {
                    MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.XsdSchemaInferred);
                }
            }
        }

        void validateSchema(String xsd) {
            try {
                boolean elem = false;
                XSDSchema schema = getXSDSchema(xsd);
                NodeList nodeList = schema.getDocument().getDocumentElement().getChildNodes();
                for (int idx = 0; idx < nodeList.getLength(); idx++) {
                    Node node = nodeList.item(idx);
                    if (node instanceof Element && node.getLocalName().indexOf("element") >= 0) {//$NON-NLS-1$
                        elem = true;
                        break;
                    }
                }
                if (!elem) {
                    MessageDialog.openWarning(getSite().getShell(), Messages.Warning, Messages.NoElementNode);
                }
            } catch (Exception e) {

                log.error(e.getMessage(), e);
            }
        }
    });

    exportToolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getSite().getShell(), SWT.SAVE);
            fd.setFilterExtensions(new String[] { "*.xsd" });//$NON-NLS-1$
            fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
            fd.setText(Messages.SaveDataModuleXSDSchema);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            inferXsdFromDataModule(filename);
        }

        private void inferXsdFromDataModule(String xmlFile) {
            WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
            XSDDriver d = new XSDDriver();
            if (d.outputXSD_UTF_8(wsObject.getXsdSchema(), xmlFile) != null) {
                MessageDialog.openInformation(getSite().getShell(), Messages.ExportXSD,
                        Messages.OperationExportingXsd);
            } else {
                MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.FailedExportXSD);
            }
        }
    });

    importSchemalItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            popupImportDialog();
        }

    });

}

From source file:com.amalto.workbench.editors.ItemsTrashBrowserMainPage.java

License:Open Source License

protected LineItem[] getResults(boolean showResultInfo) {

    Cursor waitCursor = null;/*from   www.  j a v a  2s. c  om*/

    try {

        Display display = getEditor().getSite().getPage().getWorkbenchWindow().getWorkbench().getDisplay();
        waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
        this.getSite().getShell().setCursor(waitCursor);

        TMDMService service = Util.getMDMService(getXObject());

        String search = searchText.getText();

        List<WSDroppedItemPK> results = null;
        if (search != null && search.length() > 0) {
            results = service.findAllDroppedItemsPKs(new WSFindAllDroppedItemsPKs(search)).getWsDroppedItemPK();
        }

        if ((results == null) || (results.isEmpty())) {
            if (showResultInfo) {
                MessageDialog.openInformation(this.getSite().getShell(), Messages.ItemsTrashBrowserMainPage_15,
                        Messages.ItemsTrashBrowserMainPage_16);
                return new LineItem[0];
            }
        } else {
            LineItem[] res = new LineItem[results.size()];
            for (int i = 0; i < results.size(); i++) {
                WSDroppedItemPK wsDroppedItemPK = results.get(i);
                WSItemPK refWSItemPK = wsDroppedItemPK.getWsItemPK();

                // if(revison==null||revison.equals(""))revison="head";

                res[i] = new LineItem(refWSItemPK.getWsDataClusterPK().getPk(), refWSItemPK.getConceptName(),
                        refWSItemPK.getIds().toArray(new String[0]), null, wsDroppedItemPK.getPartPath());
            }
            return res;
        }

        return new LineItem[0];
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if ((e.getLocalizedMessage() != null) && e.getLocalizedMessage().contains("10000")) {
            MessageDialog.openError(this.getSite().getShell(), Messages.ItemsTrashBrowserMainPage_17,
                    Messages.ItemsTrashBrowserMainPage_18);
        } else {
            if (!Util.handleConnectionException(this, e, null)) {
                MessageDialog.openError(this.getSite().getShell(), Messages.ItemsTrashBrowserMainPage_19,
                        e.getLocalizedMessage());
            }
        }
        return null;
    } finally {
        try {
            this.getSite().getShell().setCursor(null);
            waitCursor.dispose();
        } catch (Exception e) {
        }
    }

}