Search in sources :

Example 1 with Program

use of org.eclipse.swt.program.Program in project dbeaver by serge-rider.

the class ProgramInfo method getProgram.

public static ProgramInfo getProgram(IResource resource) {
    if (resource instanceof IFile) {
        final String fileExtension = CommonUtils.notEmpty(resource.getFileExtension());
        ProgramInfo programInfo = programMap.get(fileExtension);
        if (programInfo == null) {
            Program program = Program.findProgram(fileExtension);
            programInfo = new ProgramInfo(program);
            if (program != null) {
                final ImageData imageData = program.getImageData();
                if (imageData != null) {
                    programInfo.image = new DBIconBinary(program.getName(), imageData);
                }
            }
            programMap.put(fileExtension, programInfo);
        }
        return programInfo.program == null ? null : programInfo;
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) Program(org.eclipse.swt.program.Program) ImageData(org.eclipse.swt.graphics.ImageData)

Example 2 with Program

use of org.eclipse.swt.program.Program in project cubrid-manager by CUBRID.

the class BLOBCellPopupDialog method loadProgramMenu.

/**
	 *
	 * Load the program menus
	 *
	 */
private void loadProgramMenu() {
    if (programMenu != null) {
        programMenu.dispose();
    }
    programMenu = new Menu(getShell(), SWT.POP_UP);
    String fileType = getFileType();
    // Load the default application
    if (fileType != null && fileType.trim().length() > 0) {
        final Program program = Program.findProgram(fileType);
        if (program != null && program.getName() != null && program.getName().trim().length() > 0) {
            programMenuItem = new MenuItem(programMenu, SWT.NONE);
            programMenuItem.setText(program.getName());
            ImageData imageData = program.getImageData();
            if (imageData != null) {
                final Image image = new Image(getShell().getDisplay(), imageData);
                programMenuItem.setImage(image);
                programMenu.addDisposeListener(new DisposeListener() {

                    public void widgetDisposed(DisposeEvent e) {
                        image.dispose();
                    }
                });
            }
            programMenuItem.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent event) {
                    openByExternalProgram(program);
                }
            });
            new MenuItem(programMenu, SWT.SEPARATOR);
        }
    }
    // Load the other applications
    Program[] programs = Program.getPrograms();
    if (programs != null) {
        for (final Program program : programs) {
            String name = program.getName();
            if (name == null || name.trim().length() == 0) {
                continue;
            }
            if (programMenuItem != null && programMenuItem.getText().equals(name.trim())) {
                continue;
            }
            final MenuItem selectProgramMenuItem = new MenuItem(programMenu, SWT.NONE);
            selectProgramMenuItem.setText(name);
            ImageData imageData = program.getImageData();
            if (imageData != null) {
                final Image image = new Image(getShell().getDisplay(), imageData);
                selectProgramMenuItem.setImage(image);
                selectProgramMenuItem.addDisposeListener(new DisposeListener() {

                    public void widgetDisposed(DisposeEvent e) {
                        image.dispose();
                    }
                });
            }
            selectProgramMenuItem.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent event) {
                    openByExternalProgram(program);
                }
            });
        }
    }
    Rectangle rect = openByExternalBtn.getBounds();
    Point pt = new Point(rect.x, rect.y + rect.height);
    pt = openByExternalBtn.getParent().toDisplay(pt);
    programMenu.setLocation(pt);
    programMenu.setVisible(true);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Program(org.eclipse.swt.program.Program) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ImageData(org.eclipse.swt.graphics.ImageData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with Program

use of org.eclipse.swt.program.Program in project cubrid-manager by CUBRID.

the class BLOBCellPopupDialog method openByExternalProgram.

/**
	 *
	 * Open the external program
	 *
	 */
private void openByExternalProgram() {
    if (setNullBtn.getSelection() || currValue == null) {
        return;
    }
    String fileType = getFileType();
    if (fileType != null && fileType.trim().length() > 0) {
        final Program program = Program.findProgram(fileType);
        if (program != null) {
            openByExternalProgram(program);
            return;
        }
    }
    loadProgramMenu();
}
Also used : Program(org.eclipse.swt.program.Program)

Aggregations

Program (org.eclipse.swt.program.Program)3 ImageData (org.eclipse.swt.graphics.ImageData)2 IFile (org.eclipse.core.resources.IFile)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1