Search in sources :

Example 31 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class ToolsContextMenuHandler method getLocationFromControl.

@Nullable
private Point getLocationFromControl(Shell activeShell, Control focusControl) {
    Point location = null;
    final Display display = activeShell.getDisplay();
    if (focusControl instanceof Table) {
        final Table table = (Table) focusControl;
        final int selectionIndex = table.getSelectionIndex();
        if (selectionIndex < 0) {
            location = display.map(focusControl, null, table.getLocation());
        } else {
            Rectangle absBounds = display.map(focusControl, null, table.getItem(selectionIndex).getBounds());
            location = new Point(absBounds.x, absBounds.y + table.getItemHeight());
        }
    } else if (focusControl instanceof Tree) {
        final Tree tree = (Tree) focusControl;
        final TreeItem[] selection = tree.getSelection();
        if (ArrayUtils.isEmpty(selection)) {
            location = display.map(focusControl, null, tree.getLocation());
        } else {
            Rectangle absBounds = display.map(focusControl, null, selection[0].getBounds());
            location = new Point(absBounds.x, absBounds.y + tree.getItemHeight());
        }
    } else if (focusControl instanceof StyledText) {
        final StyledText styledText = (StyledText) focusControl;
        final int caretOffset = styledText.getCaretOffset();
        location = styledText.getLocationAtOffset(caretOffset);
        location = display.map(styledText, null, location);
        location.y += styledText.getLineHeight();
    }
    return location;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Nullable(org.jkiss.code.Nullable)

Example 32 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class UIUtils method getSelectionProvider.

@Nullable
public static ISelectionProvider getSelectionProvider(IServiceLocator serviceLocator) {
    ISelectionProvider selectionProvider = serviceLocator.getService(ISelectionProvider.class);
    if (selectionProvider != null) {
        return selectionProvider;
    }
    IWorkbenchPartSite partSite = getWorkbenchPartSite(serviceLocator);
    if (partSite == null) {
        IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
        if (activePart == null) {
            IWorkbenchWindow activeWindow = DBeaverUI.getActiveWorkbenchWindow();
            if (activeWindow != null) {
                activePart = activeWindow.getActivePage().getActivePart();
            }
        }
        if (activePart != null) {
            partSite = activePart.getSite();
        }
    }
    if (partSite != null) {
        return partSite.getSelectionProvider();
    } else {
        return null;
    }
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Nullable(org.jkiss.code.Nullable)

Example 33 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class AttributeEditPage method createPageContents.

@Override
protected Control createPageContents(Composite parent) {
    Composite propsGroup = new Composite(parent, SWT.NONE);
    propsGroup.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    propsGroup.setLayoutData(gd);
    //$NON-NLS-2$
    final Text nameText = UIUtils.createLabelText(propsGroup, "Name", attribute.getName());
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (attribute instanceof DBPNamedObject2) {
                ((DBPNamedObject2) attribute).setName(nameText.getText());
            }
        }
    });
    UIUtils.createControlLabel(propsGroup, "Properties").setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    propertyViewer.getControl().setLayoutData(gd);
    propertyViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return true;
        }
    });
    PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute) {

        @Override
        public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
            super.setPropertyValue(monitor, editableValue, prop, newValue);
        /*
                if (prop.getId().equals("dataType")) {
                    newValue = getPropertyValue(monitor, editableValue, prop);
                    if (newValue instanceof DBSDataType) {
                        DBPPropertyDescriptor lengthProp = getProperty("maxLength");
                        if (lengthProp instanceof ObjectPropertyDescriptor) {
                            DBPDataKind dataKind = ((DBSDataType) newValue).getDataKind();
                            if (dataKind == DBPDataKind.STRING) {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, 100);
                            } else {
                                setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, null);
                            }
                            propertyViewer.update(lengthProp, null);
                        }
                    }
                }
*/
        }
    };
    pc.collectProperties();
    for (DBPPropertyDescriptor prop : pc.getProperties()) {
        if (prop instanceof ObjectPropertyDescriptor) {
            if (((ObjectPropertyDescriptor) prop).isEditPossible() && !((ObjectPropertyDescriptor) prop).isNameProperty()) {
                continue;
            }
        }
        pc.removeProperty(prop);
    }
    propertyViewer.loadProperties(pc);
    return propsGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) GridData(org.eclipse.swt.layout.GridData) PropertySourceAbstract(org.jkiss.dbeaver.runtime.properties.PropertySourceAbstract) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) Nullable(org.jkiss.code.Nullable)

Example 34 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class ContentEditor method getContent.

@Nullable
DBDContent getContent() {
    IValueController valueController = getValueController();
    Object value = valueController == null ? null : valueController.getValue();
    if (value instanceof DBDContent) {
        return (DBDContent) value;
    } else {
        return null;
    }
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) IValueController(org.jkiss.dbeaver.ui.data.IValueController) Nullable(org.jkiss.code.Nullable)

Example 35 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class MySQLDataSource method getErrorPosition.

@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
    String message = error.getMessage();
    if (!CommonUtils.isEmpty(message)) {
        Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
        if (matcher.find()) {
            DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
            pos.line = Integer.parseInt(matcher.group(1)) - 1;
            return new ErrorPosition[] { pos };
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) DBPErrorAssistant(org.jkiss.dbeaver.model.DBPErrorAssistant) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2