Search in sources :

Example 1 with GuiResource

use of org.apache.hop.ui.core.gui.GuiResource in project hop by apache.

the class GitGuiPlugin method filePainted.

/**
 * If we have a git project we can take a look and see if a file is changed.
 *
 * @param tree
 * @param treeItem
 * @param path
 * @param name
 */
@Override
public void filePainted(Tree tree, TreeItem treeItem, String path, String name) {
    GuiResource guiResource = GuiResource.getInstance();
    UIFile file = null;
    // Changed git file colored blue
    try {
        file = changedFiles.get(HopVfs.getFileObject(path).getName().getPath());
    } catch (HopFileException e) {
    // do nothing
    }
    if (file != null) {
        switch(file.getChangeType()) {
            case DELETE:
            case MODIFY:
            case RENAME:
            case COPY:
                treeItem.setForeground(colorStaged);
                break;
            case ADD:
                if (file.getIsStaged()) {
                    treeItem.setForeground(colorStaged);
                } else {
                    treeItem.setForeground(colorUnstaged);
                }
                break;
        }
    }
    String ignored = ignoredFiles.get(path);
    if (ignored != null) {
        treeItem.setForeground(colorIgnored);
    }
}
Also used : UIFile(org.apache.hop.git.model.UIFile) HopFileException(org.apache.hop.core.exception.HopFileException) GuiResource(org.apache.hop.ui.core.gui.GuiResource)

Example 2 with GuiResource

use of org.apache.hop.ui.core.gui.GuiResource in project hop by apache.

the class PropsUi method setLook.

public void setLook(final Control control, int style) {
    final GuiResource gui = GuiResource.getInstance();
    Font font = null;
    Color background = null;
    Color foreground = null;
    switch(style) {
        case WIDGET_STYLE_DEFAULT:
            background = gui.getColorWhite();
            foreground = gui.getColorBlack();
            font = null;
            if (control instanceof Group && OS.contains("mac")) {
                control.addPaintListener(paintEvent -> {
                    paintEvent.gc.setForeground(gui.getColorBlack());
                    paintEvent.gc.setBackground(gui.getColorBackground());
                    paintEvent.gc.fillRectangle(2, 0, control.getBounds().width - 8, control.getBounds().height - 20);
                });
            } else if (control instanceof Combo) {
                if (Const.isWindows() && isDarkMode()) {
                    background = gui.getColorBackground();
                } else {
                    // Just keep the default
                    return;
                }
            }
            break;
        case WIDGET_STYLE_FIXED:
            foreground = gui.getColorBlack();
            background = gui.getColorWhite();
            font = gui.getFontFixed();
            break;
        case WIDGET_STYLE_TABLE:
            foreground = gui.getColorBlack();
            background = gui.getColorWhite();
            font = null;
            break;
        case WIDGET_STYLE_NOTEPAD:
            foreground = gui.getColorBlack();
            background = gui.getColorWhite();
            font = gui.getFontNote();
            break;
        case WIDGET_STYLE_GRAPH:
            foreground = gui.getColorBlack();
            background = gui.getColorWhite();
            font = gui.getFontGraph();
            break;
        case WIDGET_STYLE_TOOLBAR:
            foreground = gui.getColorBlack();
            if (isDarkMode()) {
                background = gui.getColorLightGray();
            } else {
                background = gui.getColorDemoGray();
            }
            break;
        case WIDGET_STYLE_TAB:
            background = gui.getColorWhite();
            foreground = gui.getColorBlack();
            CTabFolder tabFolder = (CTabFolder) control;
            tabFolder.setBorderVisible(true);
            // need to make a copy of the tab selection background color to get around bug
            Color c = gui.getColorTab();
            Color tabColor = new Color(c.getDevice(), c.getRed(), c.getGreen(), c.getBlue());
            tabFolder.setSelectionBackground(tabColor);
            break;
        default:
            background = gui.getColorBackground();
            font = null;
            break;
    }
    if (font != null && !font.isDisposed()) {
        control.setFont(font);
    }
    if (background != null && !background.isDisposed()) {
        boolean setBackground = true;
        if (control instanceof Button) {
            Button b = (Button) control;
            if ((b.getStyle() & SWT.PUSH) != 0) {
                setBackground = false;
            }
        }
        if (setBackground) {
            control.setBackground(background);
        }
    }
    if (foreground != null && !foreground.isDisposed()) {
        boolean setForeground = true;
        if (control instanceof Button) {
            Button b = (Button) control;
            if ((b.getStyle() & SWT.PUSH) != 0) {
                setForeground = false;
            }
        }
        if (setForeground) {
            control.setForeground(foreground);
        }
    }
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) GuiResource(org.apache.hop.ui.core.gui.GuiResource)

Example 3 with GuiResource

use of org.apache.hop.ui.core.gui.GuiResource in project hop by apache.

the class ContextDialog method open.

public GuiAction open() {
    shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
    shell.setText(getText());
    shell.setMinimumSize(200, 180);
    shell.setImage(GuiResource.getInstance().getImageHop());
    shell.setLayout(new FormLayout());
    Display display = shell.getDisplay();
    xMargin = 3 * margin;
    yMargin = 2 * margin;
    // Let's take a look at the list of actions and see if we've got categories to use...
    // 
    categories = new ArrayList<>();
    for (GuiAction action : actions) {
        if (StringUtils.isNotEmpty(action.getCategory())) {
            CategoryAndOrder categoryAndOrder = new CategoryAndOrder(action.getCategory(), Const.NVL(action.getCategoryOrder(), "0"), false);
            if (!categories.contains(categoryAndOrder)) {
                categories.add(categoryAndOrder);
            }
        } else {
            // Add an "Other" category
            CategoryAndOrder categoryAndOrder = new CategoryAndOrder(CATEGORY_OTHER, "9999", false);
            if (!categories.contains(categoryAndOrder)) {
                categories.add(categoryAndOrder);
            }
        }
    }
    categories.sort(Comparator.comparing(o -> o.order));
    // Correct the icon size which is multiplied in GuiResource...
    // 
    int correctedIconSize = (int) (iconSize / props.getZoomFactor());
    // Load the action images
    // 
    items.clear();
    for (GuiAction action : actions) {
        ClassLoader classLoader = action.getClassLoader();
        if (classLoader == null) {
            classLoader = ClassLoader.getSystemClassLoader();
        }
        // Load or get from the image cache...
        // 
        Image image = GuiResource.getInstance().getImage(action.getImage(), classLoader, correctedIconSize, correctedIconSize);
        items.add(new Item(action, image));
    }
    // Add a search bar at the top...
    // 
    Composite searchComposite = new Composite(shell, SWT.NONE);
    searchComposite.setLayout(new GridLayout(3, false));
    props.setLook(searchComposite, Props.WIDGET_STYLE_TOOLBAR);
    FormData fdlSearchComposite = new FormData();
    fdlSearchComposite.top = new FormAttachment(0, 0);
    fdlSearchComposite.left = new FormAttachment(0, 0);
    fdlSearchComposite.right = new FormAttachment(100, 0);
    searchComposite.setLayoutData(fdlSearchComposite);
    Label wlSearch = new Label(searchComposite, SWT.LEFT);
    wlSearch.setText(BaseMessages.getString(PKG, "ContextDialog.Search.Label.Text"));
    props.setLook(wlSearch, Props.WIDGET_STYLE_TOOLBAR);
    wSearch = new Text(searchComposite, SWT.LEFT | SWT.BORDER | SWT.SINGLE | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    wSearch.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Create a toolbar at the right of the search bar...
    // 
    ToolBar toolBar = new ToolBar(searchComposite, SWT.WRAP | SWT.LEFT | SWT.HORIZONTAL);
    toolBarWidgets = new GuiToolbarWidgets();
    toolBarWidgets.registerGuiPluginObject(this);
    toolBarWidgets.createToolbarWidgets(toolBar, GUI_PLUGIN_TOOLBAR_PARENT_ID);
    toolBar.pack();
    props.setLook(toolBar, Props.WIDGET_STYLE_TOOLBAR);
    recallToolbarSettings();
    // Add a description label at the bottom...
    // 
    Composite wTooltipComposite = new Composite(shell, SWT.NONE);
    GridLayout gdlTooltipComposite = new GridLayout(1, false);
    gdlTooltipComposite.marginLeft = Const.FORM_MARGIN;
    gdlTooltipComposite.marginRight = Const.FORM_MARGIN;
    gdlTooltipComposite.marginTop = Const.FORM_MARGIN;
    gdlTooltipComposite.marginBottom = Const.FORM_MARGIN;
    wTooltipComposite.setLayout(new GridLayout(1, false));
    props.setLook(wTooltipComposite, Props.WIDGET_STYLE_TOOLBAR);
    FormData fdlTooltip = new FormData();
    fdlTooltip.left = new FormAttachment(0, 0);
    fdlTooltip.right = new FormAttachment(100, 0);
    fdlTooltip.top = new FormAttachment(100, -(int) (props.getZoomFactor() * 50));
    fdlTooltip.bottom = new FormAttachment(100, 0);
    wTooltipComposite.setLayoutData(fdlTooltip);
    wlTooltip = new Label(wTooltipComposite, SWT.LEFT);
    wlTooltip.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    props.setLook(wlTooltip, Props.WIDGET_STYLE_TOOLBAR);
    // The rest of the dialog is used to draw the actions...
    // 
    wScrolledComposite = new ScrolledComposite(shell, SWT.V_SCROLL);
    wCanvas = new Canvas(wScrolledComposite, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
    wScrolledComposite.setContent(wCanvas);
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(0, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.top = new FormAttachment(searchComposite, 0);
    fdCanvas.bottom = new FormAttachment(wTooltipComposite, 0);
    wScrolledComposite.setLayoutData(fdCanvas);
    wScrolledComposite.setExpandHorizontal(true);
    itemsFont = wCanvas.getFont();
    int fontHeight = wCanvas.getFont().getFontData()[0].getHeight() + 1;
    headerFont = new Font(getParent().getDisplay(), props.getDefaultFont().getName(), fontHeight, props.getGraphFont().getStyle() | SWT.BOLD | SWT.ITALIC);
    // TODO: Calculate a more dynamic size based on number of actions, screen size
    // and so on
    // 
    int width = (int) Math.round(800 * props.getZoomFactor());
    int height = (int) Math.round(600 * props.getZoomFactor());
    // 
    if (location != null) {
        /*Adapt to the monitor */
        Monitor monitor = shell.getMonitor();
        org.eclipse.swt.graphics.Rectangle displayPosition = monitor.getBounds();
        if ((location.x - displayPosition.x) > monitor.getClientArea().width - width)
            location.x = (monitor.getClientArea().width + displayPosition.x) - width;
        if (location.y - displayPosition.y > monitor.getClientArea().height - height)
            location.y = (monitor.getClientArea().height + displayPosition.y) - height;
        shell.setSize(width, height);
        shell.setLocation(location.x, location.y);
    } else {
        BaseTransformDialog.setSize(shell, width, height, false);
    }
    // Add all the listeners
    // 
    // If the shell is re-sized we need to recalculate things...
    // 
    shell.addListener(SWT.Resize, event -> onResize(event));
    shell.addListener(SWT.Deactivate, event -> onFocusLost());
    shell.addListener(SWT.Close, event -> storeDialogSettings());
    wSearch.addListener(SWT.KeyDown, event -> onKeyPressed(event));
    wSearch.addListener(SWT.Modify, event -> onModifySearch());
    wSearch.addListener(SWT.DefaultSelection, event -> {
        // 
        if (event.detail == SWT.ICON_SEARCH || event.detail == SWT.ICON_CANCEL) {
            return;
        }
        // 
        if (selectedItem != null) {
            selectedAction = selectedItem.getAction();
        }
        dispose();
    });
    wCanvas.addListener(SWT.KeyDown, event -> onKeyPressed(event));
    wCanvas.addListener(SWT.Paint, event -> onPaint(event));
    wCanvas.addListener(SWT.MouseUp, event -> onMouseUp(event));
    if (!EnvironmentUtils.getInstance().isWeb()) {
        wCanvas.addListener(SWT.MouseMove, event -> onMouseMove(event));
    }
    // 
    if (OsHelper.isMac()) {
        wCanvas.addListener(SWT.MouseVerticalWheel, event -> {
            org.eclipse.swt.graphics.Point origin = wScrolledComposite.getOrigin();
            origin.y -= event.count;
            wScrolledComposite.setOrigin(origin);
        });
    }
    // Layout all the widgets in the shell.
    // 
    shell.layout();
    // Set the active instance.
    // 
    activeInstance = this;
    // Manually set canvas size otherwise canvas never gets drawn.
    wCanvas.setSize(10, 10);
    // Show the dialog now
    // 
    shell.open();
    // Filter all actions by default
    // 
    this.filter(null);
    // Force focus on the search bar
    // 
    wSearch.setFocus();
    // 
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    activeInstance = null;
    return selectedAction;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Props(org.apache.hop.core.Props) Image(org.eclipse.swt.graphics.Image) AreaOwner(org.apache.hop.core.gui.AreaOwner) GuiPlugin(org.apache.hop.core.gui.plugin.GuiPlugin) GC(org.eclipse.swt.graphics.GC) GuiAction(org.apache.hop.core.gui.plugin.action.GuiAction) WindowProperty(org.apache.hop.ui.core.gui.WindowProperty) Font(org.eclipse.swt.graphics.Font) HopConfig(org.apache.hop.core.config.HopConfig) OsHelper(org.apache.hop.ui.core.widget.OsHelper) Rectangle(org.apache.hop.core.gui.Rectangle) AuditState(org.apache.hop.history.AuditState) BaseMessages(org.apache.hop.i18n.BaseMessages) org.eclipse.swt.layout(org.eclipse.swt.layout) GuiResource(org.apache.hop.ui.core.gui.GuiResource) EnvironmentUtils(org.apache.hop.ui.util.EnvironmentUtils) HopNamespace(org.apache.hop.ui.core.gui.HopNamespace) org.eclipse.swt.widgets(org.eclipse.swt.widgets) Const(org.apache.hop.core.Const) GuiToolbarElementType(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElementType) PropsUi(org.apache.hop.ui.core.PropsUi) LogChannel(org.apache.hop.core.logging.LogChannel) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement) List(java.util.List) Color(org.eclipse.swt.graphics.Color) AuditManager(org.apache.hop.history.AuditManager) Point(org.apache.hop.core.gui.Point) SWT(org.eclipse.swt.SWT) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) GuiToolbarWidgets(org.apache.hop.ui.core.gui.GuiToolbarWidgets) BaseTransformDialog(org.apache.hop.ui.pipeline.transform.BaseTransformDialog) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) GuiAction(org.apache.hop.core.gui.plugin.action.GuiAction) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) GuiToolbarWidgets(org.apache.hop.ui.core.gui.GuiToolbarWidgets) Point(org.apache.hop.core.gui.Point)

Example 4 with GuiResource

use of org.apache.hop.ui.core.gui.GuiResource in project hop by apache.

the class PipelineDebugDialog method refreshTransformList.

private void refreshTransformList() {
    GuiResource resource = GuiResource.getInstance();
    // Add the list of transforms...
    // 
    int maxIconSize = 0;
    int indexSelected = -1;
    wTransforms.table.removeAll();
    for (int i = 0; i < pipelineDebugMeta.getPipelineMeta().getTransforms().size(); i++) {
        TransformMeta transformMeta = pipelineDebugMeta.getPipelineMeta().getTransform(i);
        TableItem item = new TableItem(wTransforms.table, SWT.NONE);
        Image image = resource.getImagesTransforms().get(transformMeta.getTransformPluginId()).getAsBitmapForSize(display, ConstUi.ICON_SIZE, ConstUi.ICON_SIZE);
        item.setImage(0, image);
        item.setText(0, "");
        item.setText(1, transformMeta.getName());
        if (image.getBounds().width > maxIconSize) {
            maxIconSize = image.getBounds().width;
        }
        TransformDebugMeta transformDebugMeta = transformDebugMetaMap.get(transformMeta);
        if (transformDebugMeta != null) {
            // We have debugging information so we mark the row
            // 
            item.setBackground(resource.getColorLight());
            if (indexSelected < 0) {
                indexSelected = i;
            }
        }
    }
    wTransforms.removeEmptyRows();
    wTransforms.optWidth(false);
    wTransforms.table.getColumn(0).setWidth(maxIconSize + 10);
    wTransforms.table.getColumn(0).setAlignment(SWT.CENTER);
    // 
    if (indexSelected >= 0) {
        wTransforms.table.setSelection(indexSelected);
        showTransformDebugInformation();
    }
}
Also used : TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) TransformDebugMeta(org.apache.hop.pipeline.debug.TransformDebugMeta) GuiResource(org.apache.hop.ui.core.gui.GuiResource) Image(org.eclipse.swt.graphics.Image)

Aggregations

GuiResource (org.apache.hop.ui.core.gui.GuiResource)4 Image (org.eclipse.swt.graphics.Image)2 java.util (java.util)1 List (java.util.List)1 StringUtils (org.apache.commons.lang.StringUtils)1 Const (org.apache.hop.core.Const)1 Props (org.apache.hop.core.Props)1 HopConfig (org.apache.hop.core.config.HopConfig)1 HopFileException (org.apache.hop.core.exception.HopFileException)1 AreaOwner (org.apache.hop.core.gui.AreaOwner)1 Point (org.apache.hop.core.gui.Point)1 Rectangle (org.apache.hop.core.gui.Rectangle)1 GuiPlugin (org.apache.hop.core.gui.plugin.GuiPlugin)1 GuiAction (org.apache.hop.core.gui.plugin.action.GuiAction)1 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)1 GuiToolbarElementType (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElementType)1 LogChannel (org.apache.hop.core.logging.LogChannel)1 UIFile (org.apache.hop.git.model.UIFile)1 AuditManager (org.apache.hop.history.AuditManager)1 AuditState (org.apache.hop.history.AuditState)1