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

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

Introduction

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

Prototype

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

Source Link

Document

Convenience method to open a standard warning dialog.

Usage

From source file:com.nextep.designer.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

/**
 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen()
 *///from   w ww  .j a  va2  s .  c  om
@Override
public void postWindowOpen() {
    super.postWindowOpen();
    log.info("neXtep Designer is ready!"); //$NON-NLS-1$
    final IConnection conn = CorePlugin.getRepositoryService().getRepositoryConnection();
    RepositoryStatus status = RepositoryStatus.REPOSITORY_TOO_OLD;
    try {
        status = RepositoryPlugin.getService(IRepositoryUpdaterService.class).checkRepository(conn);
    } catch (NoRepositoryException e) {
        // Nothing, we're too old and we'll exit
    } catch (NoRepositoryConnectionException e) {
        // Nothing, we're too old and we'll exit
    }

    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    switch (status) {
    case CLIENT_TOO_OLD:
        MessageDialog.openInformation(shell, DesignerMessages.getString("windowAdvisor.softwareUpdate.title"), //$NON-NLS-1$
                DesignerMessages.getString("windowAdvisor.softwareUpdate.message")); //$NON-NLS-1$
        try {
            P2Plugin.getService(ILicenseService.class).checkForUpdates(false);
        } catch (UnavailableLicenseServerException e) {
            MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Update server unavailable",
                    "The neXtep softwares update server is unavailable at the moment, please try again later.");
        }
        break;
    case REPOSITORY_TOO_OLD:
        MessageDialog.openWarning(shell, DesignerMessages.getString("windowAdvisor.repositoryUpdate.title"), //$NON-NLS-1$
                DesignerMessages.getString("windowAdvisor.repositoryUpdate.message")); //$NON-NLS-1$
        PlatformUI.getWorkbench().close();
    }

    // Setting the Welcome page in fully visible mode if available.
    IIntroManager mgr = getWindowConfigurer().getWindow().getWorkbench().getIntroManager();
    mgr.setIntroStandby(mgr.getIntro(), false);
}

From source file:com.nextep.designer.beng.ui.services.impl.DeliveryExportUIService.java

License:Open Source License

@Override
public void exportDelivery(final IDeliveryModule module) {
    // Checking container status
    try {/*from   w w w  . j  a  v a  2s.c  om*/
        IVersionContainer c = (IVersionContainer) VersionHelper.getReferencedItem(module.getModuleRef());
        IVersionable<IVersionContainer> v = VersionHelper.getVersionable(c);
        if (v.getVersion().getStatus() != IVersionStatus.CHECKED_IN) {
            boolean confirmed = MessageDialog.openQuestion(getShell(),
                    BengUIMessages.getString("exportedModuleNotCheckedInTitle"), //$NON-NLS-1$
                    BengUIMessages.getString("exportedModuleNotCheckedIn")); //$NON-NLS-1$
            if (!confirmed) {
                throw new CancelException("Export canceled by the user.");
            }
        }
    } catch (ExternalReferenceException e) {
        // ignoring for now
    }
    // Retrieving output folder
    String folder = SQLGenUtil.getPreference(PreferenceConstants.OUTPUT_FOLDER).trim();
    char lastChar = folder.charAt(folder.length() - 1);
    if (lastChar == File.separatorChar) {
        folder = folder.substring(0, folder.length() - 1);
    }
    // Generating outputs
    String exportLoc = folder + File.separator + module.getName();
    File f = new File(exportLoc);
    boolean newFolder = f.mkdir();
    if (!newFolder) {
        boolean confirmed = MessageDialog.openQuestion(getShell(),
                BengUIMessages.getString("exportLocationExistsTitle"), //$NON-NLS-1$
                BengUIMessages.getString("exportLocationExists")); //$NON-NLS-1$
        if (!confirmed) {
            throw new CancelException("Export canceled by the user.");
        }
    }
    final String targetDirectory = folder;
    // Generating module
    Job j = new BlockingJob("Exporting delivery " + module.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                exportService.exportDelivery(targetDirectory, module, monitor);
            } catch (UndeliverableIncrementException e) {
                final IDeliveryIncrement dlvInc = e.getDeliveryIncrement();
                // Error property label
                final String titleMsg = e.isUniversal() ? "universalDeliveryNotAllowedTitle"
                        : "prerequisiteFailedTitle";
                final String errorMsg = e.isUniversal() ? "universalDeliveryNotAllowed" : "prerequisiteFailed";
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openWarning(
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                BengUIMessages.getString(titleMsg),
                                MessageFormat.format(BengUIMessages.getString(errorMsg),
                                        dlvInc.getModule().getName(),
                                        dlvInc.getFromRelease() == null ? "[Scratch]"
                                                : dlvInc.getFromRelease().getLabel(),
                                        dlvInc.getToRelease().getLabel()));
                    }
                });
            }
            return Status.OK_STATUS;
        }
    };
    j.addJobChangeListener(new JobChangeAdapter() {

        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                "Exported successfully", "Your delivery has been successfully exported to "
                                        + targetDirectory + File.separator + module.getName() + "."); //$NON-NLS-1$

                    }
                });
            }
        };
    });
    j.setUser(true);
    j.schedule();

}

From source file:com.nextep.designer.dbgm.oracle.ui.impl.TablePhysicalPropertiesEditor.java

License:Open Source License

/**
 * @see com.nextep.designer.dbgm.ui.editors.PhysicalPropertiesEditor#refreshConnector()
 *///from www.  jav  a 2  s .co m
@Override
public void refreshConnector() {
    final ICoreService coreService = CorePlugin.getService(ICoreService.class);

    IOracleTablePhysicalProperties props = (IOracleTablePhysicalProperties) getModel();
    super.refreshConnector();
    if (props.getPhysicalOrganisation() == null) {
        orgCombo.setText(PhysicalOrganisation.HEAP.getLabel());
    } else {
        orgCombo.setText(props.getPhysicalOrganisation().getLabel());
    }
    if (props.getPartitioningMethod() == null) {
        partCombo.setText(PartitioningMethod.NONE.name());
    } else {
        partCombo.setText(props.getPartitioningMethod().name());
    }
    // Partitioned column
    for (IReference r : props.getPartitionedColumnsRef()) {
        IBasicColumn c = (IBasicColumn) VersionHelper.getReferencedItem(r);
        partColCombo.setText(notNull(c.getName()));
    }

    // Enablement
    boolean locked = coreService.isLocked(props);
    final boolean b = (props.getParent() == null ? true : !locked);
    orgCombo.setEnabled(b);
    partCombo.setEnabled(b);
    partColCombo.setEnabled(b);
    partitionableEditor.refreshConnector();

    // Warning for clustered tables
    final IBasicTable parentTable = coreService.getFirstTypedParent(props, IBasicTable.class);
    IOracleClusteredTable clusterTab = DBOMHelper.getClusterFor(parentTable);
    if (clusterTab != null) {
        MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                MessageFormat.format(DBOMUIMessages.getString("warnPhysicalsOverriddenByClusterTitle"),
                        clusterTab.getCluster().getName()),
                MessageFormat.format(DBOMUIMessages.getString("warnPhysicalsOverriddenByCluster"),
                        props.getParent().getName(), clusterTab.getCluster().getName()));
    }
}

From source file:com.nextep.designer.dbgm.ui.editors.DomainEditorComponent.java

License:Open Source License

@Override
public Control create(Composite parent) {
    final Composite editor = new Composite(parent, SWT.NONE);
    GridLayout l = new GridLayout(2, false);
    l.marginBottom = l.marginHeight = l.marginLeft = l.marginRight = l.marginTop = l.marginWidth = 0;
    editor.setLayout(l);/*from   w  w w. j  av  a2s .  c  o  m*/

    Table t = DomainTable.create(editor);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2);
    gd.heightHint = 250;
    t.setLayoutData(gd);

    domainViewer = new TableViewer(t);
    final DomainContentProvider provider = new DomainContentProvider();
    domainViewer.setContentProvider(provider);
    domainViewer.setLabelProvider(new DomainLabelProvider());

    CellEditor[] editors = new CellEditor[5];
    editors[1] = new TextCellEditor(t);
    editors[2] = new TextCellEditor(t);
    editors[3] = new TextCellEditor(t);
    editors[4] = new TextCellEditor(t);
    domainViewer.setCellEditors(editors);
    domainViewer.setColumnProperties(new String[] { COL_SEL, COL_NAME, COL_DESC, COL_LENGTH, COL_PRECISION });
    domainViewer.setSorter(new ViewerSorter());
    domainViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return !COL_SEL.equals(property);
        }

        @Override
        public Object getValue(Object element, String property) {
            final IDomain d = (IDomain) element;
            if (COL_NAME.equals(property)) {
                return notNull(d.getName());
            }
            if (COL_DESC.equals(property)) {
                return notNull(d.getDescription());
            }
            if (COL_LENGTH.equals(property)) {
                return notNull(d.getLengthExpr());
            }
            if (COL_PRECISION.equals(property)) {
                return notNull(d.getPrecisionExpr());
            }
            return null;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            final IDomain d = (IDomain) ((TableItem) element).getData();
            if (COL_NAME.equals(property)) {
                d.setName((String) value);
            } else if (COL_DESC.equals(property)) {
                d.setDescription((String) value);
            } else if (COL_LENGTH.equals(property)) {
                d.setLengthExpr((String) value);
            } else if (COL_PRECISION.equals(property)) {
                d.setPrecisionExpr((String) value);
            }
        }
    });

    Button addButton = new Button(editor, SWT.PUSH);
    addButton.setText(UIMessages.getString("component.typedListBlock.add")); //$NON-NLS-1$
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IDomain d = (IDomain) UIControllerFactory.getController(IElementType.getInstance(IDomain.TYPE_ID))
                    .newInstance(null);
            provider.add(d);
            domainViewer.editElement(d, 1);
        }
    });
    Button removeButton = new Button(editor, SWT.PUSH);
    removeButton.setText(UIMessages.getString("component.typedListBlock.remove")); //$NON-NLS-1$
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection s = domainViewer.getSelection();
            if (s instanceof IStructuredSelection) {
                for (Object o : ((IStructuredSelection) s).toList()) {
                    final IDomain d = (IDomain) o;
                    // Removing vendor types
                    for (IDomainVendorType t : new ArrayList<IDomainVendorType>(d.getVendorTypes())) {
                        d.removeVendorType(t);
                    }
                    CorePlugin.getIdentifiableDao().delete(d);
                    // Removing domain
                    domainViewer.remove(d);
                }
            }
        }
    });

    final IDatatypeService datatypeService = CorePlugin.getService(IDatatypeService.class);
    datatypeService.reset();
    final Collection<IDomain> domains = datatypeService.getDomains();
    domainViewer.setInput(domains);

    // Domain vendor type section
    final Table typeTab = DomainTable.createDomainType(editor);
    final TableViewer typeViewer = new TableViewer(typeTab);
    GridData typeData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
    typeData.heightHint = 200;
    typeTab.setLayoutData(typeData);
    Button addTypeButton = new Button(editor, SWT.PUSH);
    addTypeButton.setText(UIMessages.getString("component.typedListBlock.add")); //$NON-NLS-1$
    addTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    addTypeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final IDomain domain = getSelectedDomain();
            if (domain == null) {
                MessageDialog.openWarning(editor.getShell(),
                        DBGMUIMessages.getString("domainPrefNoSelectionTitle"), //$NON-NLS-1$
                        DBGMUIMessages.getString("domainPrefNoSelection")); //$NON-NLS-1$
                return;
            }
            final Object o = UIControllerFactory
                    .getController(IElementType.getInstance(IDomainVendorType.TYPE_ID))
                    .emptyInstance(null, domain);
            typeViewer.editElement(o, 0);
        }
    });
    Button removeTypeButton = new Button(editor, SWT.PUSH);
    removeTypeButton.setText(UIMessages.getString("component.typedListBlock.remove")); //$NON-NLS-1$
    removeTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.UP, false, false));

    typeViewer.setContentProvider(new DomainTypeContentProvider());
    typeViewer.setLabelProvider(new DomainTypeLabelProvider());
    typeViewer.setColumnProperties(new String[] { COL_VENDOR, COL_TYPE, COL_LENGTH, COL_PRECISION });
    CellEditor[] typeEditors = new CellEditor[4];

    typeEditors[0] = new ComboBoxCellEditor(typeTab, sortedVendors.toArray(new String[sortedVendors.size()]),
            SWT.READ_ONLY);
    typeEditors[1] = new TextCellEditor(typeTab);
    typeEditors[2] = new TextCellEditor(typeTab);
    typeEditors[3] = new TextCellEditor(typeTab);
    typeViewer.setCellEditors(typeEditors);
    typeViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }

        @Override
        public Object getValue(Object element, String property) {
            IDomainVendorType t = (IDomainVendorType) element;
            if (COL_VENDOR.equals(property)) {
                if (t.getDBVendor() != null) {
                    return sortedVendors.indexOf(t.getDBVendor().toString());
                } else {
                    return 0;
                }
            } else if (COL_TYPE.equals(property)) {
                if (t.getDatatype() != null) {
                    return notNull(t.getDatatype().getName());
                } else {
                    return ""; //$NON-NLS-1$
                }
            } else if (COL_LENGTH.equals(property)) {
                if (t.getDatatype() != null && t.getDatatype().getLength() != null) {
                    return String.valueOf(t.getDatatype().getLength());
                } else {
                    return ""; //$NON-NLS-1$
                }
            } else if (COL_PRECISION.equals(property)) {
                if (t.getDatatype() != null && t.getDatatype().getPrecision() != null) {
                    return String.valueOf(t.getDatatype().getPrecision());
                } else {
                    return ""; //$NON-NLS-1$
                }
            }
            return null;
        }

        @Override
        public void modify(Object element, String property, Object value) {
            IDomainVendorType t = (IDomainVendorType) ((TableItem) element).getData();
            if (COL_VENDOR.equals(property)) {
                String val = sortedVendors.get((Integer) value);
                for (DBVendor v : DBVendor.values()) {
                    if (v.toString().equals(val)) {
                        t.setDBVendor(v);
                    }
                }
            } else if (COL_TYPE.equals(property)) {
                if (t.getDatatype() == null) {
                    t.setDatatype(Datatype.getDefaultDatatype());
                }
                t.getDatatype().setName((String) value);
                t.notifyListeners(ChangeEvent.MODEL_CHANGED, null);
            } else if (COL_LENGTH.equals(property)) {
                try {
                    if (value != null && !"".equals(((String) value).trim())) { //$NON-NLS-1$
                        t.getDatatype().setLength(Integer.valueOf((String) value));
                    } else {
                        t.getDatatype().setLength(null);
                    }
                } catch (NumberFormatException e) {
                    t.getDatatype().setLength(null);
                }
                t.notifyListeners(ChangeEvent.MODEL_CHANGED, null);
            } else if (COL_PRECISION.equals(property)) {
                try {
                    if (value != null && !"".equals(((String) value).trim())) { //$NON-NLS-1$
                        t.getDatatype().setPrecision(Integer.valueOf((String) value));
                    } else {
                        t.getDatatype().setPrecision(null);
                    }
                } catch (NumberFormatException e) {
                    t.getDatatype().setPrecision(null);
                }
                t.notifyListeners(ChangeEvent.MODEL_CHANGED, null);
            }
        }
    });

    domainViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof IStructuredSelection) {
                final IStructuredSelection sel = (IStructuredSelection) event.getSelection();
                if (!sel.isEmpty()) {
                    typeViewer.setInput(sel.getFirstElement());
                } else {
                    typeViewer.setInput(null);
                }
            }
        }
    });
    removeTypeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection s = typeViewer.getSelection();
            if (s instanceof IStructuredSelection) {
                final IStructuredSelection sel = (IStructuredSelection) s;
                if (!sel.isEmpty()) {
                    for (Object o : sel.toList()) {
                        if (o instanceof IDomainVendorType) {
                            final IDomainVendorType vt = (IDomainVendorType) o;
                            vt.getDomain().removeVendorType(vt);
                        }
                    }
                }
            }
        }
    });
    return editor;
}

From source file:com.nextep.designer.dbgm.ui.editors.ForeignKeyFormEditor.java

License:Open Source License

/**
 * Creates an enforcing index for the current fk
 *//*from   w  ww.  j av  a2 s  .  c om*/
private void createEnforcingIndex() {
    final ForeignKeyConstraint fk = getModel();
    try {
        fk.checkConsistency();
    } catch (InconsistentObjectException e) {
        MessageDialog.openWarning(createEnforcingIndexButton.getShell(),
                "Fix " + fk.getName() + " problems first", "Foreign key '" + fk.getName()
                        + "' has problems. You need to fix those problems before you can create its enforcing index.");
        return;
    }
    IIndex i = (IIndex) UIControllerFactory.getController(IElementType.getInstance(IIndex.INDEX_TYPE))
            .emptyInstance(fk.getName(), fk.getConstrainedTable());
    // i.setIndexedTableRef(c.getConstrainedTable().getReference());
    for (IReference colRef : fk.getConstrainedColumnsRef()) {
        i.addColumnRef(colRef);
    }
    refresh();
}

From source file:com.nextep.designer.dbgm.ui.services.DBGMUIHelper.java

License:Open Source License

private static IConnection doGetConnection(TargetType t) {
    IConnection connection = null;//from   w  w  w . jav  a 2 s. c  om

    Collection<IConnection> connections = null;
    if (t != null) {
        connections = VCSPlugin.getViewService().getCurrentViewTargets().getTarget(t);
    } else {
        connections = VCSPlugin.getViewService().getCurrentViewTargets().getConnections();
    }
    if (connections.isEmpty()) {
        MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                DBGMUIMessages.getString("noExistingTargetConnectionTitle"), //$NON-NLS-1$
                MessageFormat.format(DBGMUIMessages.getString("noExistingTargetConnection"), //$NON-NLS-1$
                        t == null ? DBGMUIMessages.getString("helper.all") : t.getLabel())); //$NON-NLS-1$
        connection = (IConnection) UIControllerFactory
                .getController(IElementType.getInstance(IConnection.TYPE_ID))
                .newInstance(VCSPlugin.getViewService().getCurrentViewTargets());
        if (connection == null) {
            throw new ErrorException(DBGMUIMessages.getString("helper.connection.noTarget") + t.getLabel()); //$NON-NLS-1$
        }
    } else if (connections.size() == 1) {
        connection = connections.iterator().next();
    } else {
        ConnectionSelector selector = new ConnectionSelector(t);
        final IPreferenceStore store = DbgmUIPlugin.getDefault().getPreferenceStore();
        String lastConnection = store.getString(PREF_LAST_CONNECTION);
        if (lastConnection != null) {
            selector.setDefaultConnection(lastConnection);
        }
        final GUIWrapper w = new GUIWrapper(selector, DBGMUIMessages.getString("chooseConnectionTitle"), 520, //$NON-NLS-1$
                130);
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                w.invoke();
            }
        });
        if (!w.isCancelled()) {
            connection = selector.getSelection();
            store.putValue(PREF_LAST_CONNECTION, connection.getName());
        } else {
            throw new CancelException(DBGMUIMessages.getString("helper.cancelled")); //$NON-NLS-1$
        }
    }
    checkConnectionPassword(connection);
    return connection;
}

From source file:com.nextep.designer.p2.handlers.UpdateHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ILicenseService licenseService = P2Plugin.getService(ILicenseService.class);
    try {//www.j  a v a2 s .c om
        final IProxyService proxyService = CorePlugin.getService(IProxyService.class);
        if (proxyService.isProxiesEnabled()) {
            proxyService.getProxyData();
        }
    } catch (RuntimeException e) {
        LOGGER.error("Unable to initialize proxy service : " + e.getMessage(), e);
    }

    try {
        licenseService.checkForUpdates(false);
    } catch (UnavailableLicenseServerException e) {
        MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                P2Messages.getString("handler.update.serverUnavailableTitle"), //$NON-NLS-1$
                P2Messages.getString("handler.update.serverUnavailable") //$NON-NLS-1$
                        + e.getMessage());
    }
    return null;
}

From source file:com.nextep.designer.p2.services.impl.LicenseService.java

License:Open Source License

private ILicenseInformation getLicenseFromUrl(String licenseKey, String uri)
        throws UnavailableLicenseServerException {

    // As we don't have CXF WebClient here for connect & parse, we use the
    // old doc builder way
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {//from  w  ww .  ja va2s .c o  m
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(uri);
        Element elt = doc.getDocumentElement();
        NodeList list = elt.getElementsByTagName("license"); //$NON-NLS-1$
        Element license = (Element) list.item(0);
        if (license != null) {
            NodeList urls = license.getElementsByTagName("updateUrl"); //$NON-NLS-1$
            Element updateUrlElt = (Element) urls.item(0);
            String updateUrl = updateUrlElt.getTextContent();

            NodeList organizations = license.getElementsByTagName("organization"); //$NON-NLS-1$
            String organization = ((Element) organizations.item(0)).getTextContent();

            NodeList contactEmails = license.getElementsByTagName("contactEmail"); //$NON-NLS-1$
            String contactEmail = "unknown";
            if (contactEmails != null && contactEmails.getLength() > 0) {
                contactEmail = ((Element) contactEmails.item(0)).getTextContent();
            }

            NodeList contactNames = license.getElementsByTagName("contactName"); //$NON-NLS-1$
            String contactName = null;
            if (contactNames != null && contactNames.getLength() > 0) {
                contactName = ((Element) contactNames.item(0)).getTextContent();
            }

            //            NodeList validFromNode = license.getElementsByTagName("validFrom"); //$NON-NLS-1$
            // long validFrom = Long.parseLong(((Element)
            // validFromNode.item(0)).getTextContent());
            // Date validFromDate = new Date(validFrom);

            NodeList validUntilNode = license.getElementsByTagName("validUntil"); //$NON-NLS-1$
            long validUntil = Long.parseLong(((Element) validUntilNode.item(0)).getTextContent());
            Date validUntilDate = new Date(validUntil);

            NodeList permissions = license.getElementsByTagName(PERMISSION);
            if (permissions != null && permissions.getLength() > 0) {
                String val = permissions.item(0).getTextContent();
                if (PERMISSION_WARN.equals(val)) {
                    String msgKey = "preferences.license.licenseExpiredMsg"; //$NON-NLS-1$
                    if (validUntil > System.currentTimeMillis()) {
                        msgKey = "preferences.license.licenseQuotaMsg"; //$NON-NLS-1$
                    }
                    // Injecting contact email and name into warning message
                    final String dlgMsg = MessageFormat.format(P2Messages.getString(msgKey), contactName,
                            contactEmail);

                    // Popping our dialog
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openWarning(null,
                                    P2Messages.getString("preferences.license.licenseExpiredTitle"), //$NON-NLS-1$
                                    dlgMsg);

                        }
                    });
                } else if (PERMISSION_ERROR.equals(val)) {
                    String msgKey = "preferences.license.licenseExpiredError"; //$NON-NLS-1$
                    if (validUntil > System.currentTimeMillis()) {
                        msgKey = "preferences.license.licenseQuotaError"; //$NON-NLS-1$
                    }
                    // Injecting contact email and name into warning message
                    final String dlgMsg = MessageFormat.format(P2Messages.getString(msgKey), contactName,
                            contactEmail);
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openWarning(null,
                                    P2Messages.getString("preferences.license.licenseExpiredTitle"), //$NON-NLS-1$
                                    dlgMsg);
                            System.exit(-1);
                        }
                    });
                }
            }
            LicenseInformation info = new LicenseInformation();
            info.setUpdateSiteLocation(updateUrl);
            info.setLicenseKey(licenseKey);
            info.setOrganization(organization);
            info.setExpirationDate(validUntilDate);
            return info;
        }
    } catch (RuntimeException e) {
        throw new UnavailableLicenseServerException(
                P2Messages.getString("service.license.unexpectedException") + e.getMessage(), e); //$NON-NLS-1$
    } catch (Exception e) {
        throw new UnavailableLicenseServerException(
                P2Messages.getString("service.license.serverProblemException") + e.getMessage(), e); //$NON-NLS-1$
    }
    throw new UnavailableLicenseServerException(
            MessageFormat.format(P2Messages.getString("service.license.unregisteredLicense"), //$NON-NLS-1$
                    licenseKey));
}

From source file:com.nextep.designer.p2.services.impl.LicenseService.java

License:Open Source License

@Override
public void checkForUpdates(final boolean isSilent) {
    final RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();

    // Checking whether the update site is available
    Job j = new Job("Checking for updates...") {

        @Override/*from   w ww.j  a va 2s. c  o m*/
        protected IStatus run(org.eclipse.core.runtime.IProgressMonitor monitor) {
            if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
                if (!isSilent) {
                    MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            P2Messages.getString("service.license.serverUnavailableTitle"), //$NON-NLS-1$
                            P2Messages.getString("service.license.serverUnavailableMsg")); //$NON-NLS-1$
                } else {
                    log.info(P2Messages.getString("service.license.serverUnavailableSilent")); //$NON-NLS-1$
                }
                return Status.CANCEL_STATUS;
            }

            // We are clear for update check
            Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
            final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
            loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));

            loadJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (PlatformUI.isWorkbenchRunning())
                        if (event.getResult().isOK()) {

                            performUpdateCheck(loadJob, isSilent);
                        }
                }
            });
            loadJob.setUser(!isSilent);
            loadJob.schedule();
            return Status.OK_STATUS;
        }
    };
    j.schedule();
}

From source file:com.nextep.designer.sqlclient.ui.handlers.RollbackHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IEditorPart editor = HandlerUtil.getActiveEditor(event);
    final IEditorInput input = editor.getEditorInput();
    if (input instanceof IConnectable) {
        final Connection connection = ((IConnectable) input).getSqlConnection();
        if (connection != null) {
            try {
                if (!connection.getAutoCommit()) {
                    connection.rollback();
                    MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Rollback success",
                            "Your current transaction has been rollbacked successfully. You may need to refresh any SQL result view which may contain rollbacked changes.");
                } else {
                    MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
                            "Cannot rollback in auto-commit",
                            "You cannot rollback anything in auto-commit mode. Toggle the autocommit mode in the toolbar to be able to control your transaction through commit / rollback.");
                }// w  w w.  j a va  2  s .c  o m
            } catch (SQLException e) {
                throw new ErrorException("Cannot rollback current connection: " + e.getMessage(), e);
            }
        }
    }
    return null;
}