Search in sources :

Example 26 with IDoubleClickListener

use of org.eclipse.jface.viewers.IDoubleClickListener in project bndtools by bndtools.

the class RepositoriesView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    // CREATE CONTROLS
    final StackLayout stackLayout = new StackLayout();
    parent.setLayout(stackLayout);
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    Composite defaultParent = toolkit.createComposite(parent, SWT.NONE);
    FillLayout fill = new FillLayout();
    fill.marginHeight = 5;
    fill.marginWidth = 5;
    defaultParent.setLayout(fill);
    if (!Central.hasWorkspaceDirectory()) {
        FormText form = toolkit.createFormText(defaultParent, true);
        form.setText("<form><p>No workspace configuration found. <a>Create a new Bnd workspace...</a></p></form>", true, false);
        form.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
                wizard.init(workbench, StructuredSelection.EMPTY);
                WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
                dialog.open();
            }
        });
    } else {
        toolkit.createLabel(defaultParent, "Repositories are loading, please wait...");
    }
    stackLayout.topControl = defaultParent;
    parent.layout();
    final Composite mainPanel = new Composite(parent, SWT.NONE);
    filterPanel = filterPart.createControl(mainPanel, 5, 5);
    Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI);
    filterPanel.setBackground(tree.getBackground());
    viewer = new TreeViewer(tree);
    contentProvider = new SearchableRepositoryTreeContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            super.inputChanged(viewer, oldInput, newInput);
            if (newInput != null) {
                stackLayout.topControl = mainPanel;
                advancedSearchAction.setEnabled(true);
                refreshAction.setEnabled(true);
                collapseAllAction.setEnabled(true);
                configureOfflineAction();
                parent.layout();
            }
        }
    };
    viewer.setContentProvider(contentProvider);
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
    getViewSite().setSelectionProvider(viewer);
    Central.addRepositoriesViewer(viewer, RepositoriesView.this);
    JpmPreferences jpmPrefs = new JpmPreferences();
    final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL;
    // LISTENERS
    filterPart.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String filter = (String) event.getNewValue();
            updatedFilter(filter);
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (target == null)
                return false;
            if (canDrop(target, transferType))
                return true;
            boolean valid = false;
            if (target instanceof RepositoryPlugin) {
                if (((RepositoryPlugin) target).canWrite()) {
                    if (URLTransfer.getInstance().isSupportedType(transferType))
                        return true;
                    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
                        ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                        if (selection instanceof IStructuredSelection) {
                            for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                                Object element = iter.next();
                                if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IFile) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IAdaptable) {
                                    IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
                                    if (file != null) {
                                        valid = true;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        valid = true;
                    }
                }
            }
            return valid;
        }

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean performDrop(Object data) {
            if (RepositoriesView.this.performDrop(getCurrentTarget(), getCurrentEvent().currentDataType, data)) {
                viewer.refresh(getCurrentTarget(), true);
                return true;
            }
            boolean copied = false;
            if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) {
                try {
                    URL url = new URL((String) URLTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType));
                    if (!url.getPath().endsWith(".jar")) {
                        String uris = url.toString();
                        if (uris.contains("#!/p/sha/")) {
                            MessageDialog.openWarning(null, "Dropped URL is a JPM Revision Identifier, not a JAR", "The dropped URL is a JPM identifier, can only be dropped on a JPM repository. You can also select the revision on JPM and drag the 'jar' link of the revision to any of the other repositories.");
                            return false;
                        }
                    }
                    File tmp = File.createTempFile("dwnl", ".jar");
                    try (HttpClient client = new HttpClient()) {
                        IO.copy(client.connect(url), tmp);
                    }
                    if (isJarFile(tmp)) {
                        copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] { tmp });
                    } else {
                        tmp.delete();
                        MessageDialog.openWarning(null, "Unrecognized Artifact", "The dropped URL is not recognized as a remote JAR file: " + url.toString());
                    }
                } catch (Exception e) {
                    return false;
                }
            } else if (data instanceof String[]) {
                String[] paths = (String[]) data;
                File[] files = new File[paths.length];
                for (int i = 0; i < paths.length; i++) {
                    files[i] = new File(paths[i]);
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IResource[]) {
                IResource[] resources = (IResource[]) data;
                File[] files = new File[resources.length];
                for (int i = 0; i < resources.length; i++) {
                    files[i] = resources[i].getLocation().toFile();
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IStructuredSelection) {
                File[] files = convertSelectionToFiles((IStructuredSelection) data);
                if (files != null && files.length > 0)
                    copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            }
            return copied;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter);
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean writableRepoSelected = false;
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                writableRepoSelected = repo.canWrite();
            }
            addBundlesAction.setEnabled(writableRepoSelected);
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent ev) {
            Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (element instanceof ContinueSearchElement) {
                try {
                    getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE);
                } catch (PartInitException e) {
                    Plugin.getDefault().getLog().log(e.getStatus());
                }
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (!event.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                final Object element = selection.getFirstElement();
                if (element instanceof IAdaptable) {
                    final URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class);
                    if (uri == null && element instanceof RepositoryEntry) {
                        boolean download = MessageDialog.openQuestion(getSite().getShell(), "Repositories", "This repository entry is unable to be opened because it has not been downloaded. Download and open it now?");
                        if (download) {
                            final RepositoryEntry entry = (RepositoryEntry) element;
                            Job downloadJob = new Job("Downloading repository entry " + entry.getBsn()) {

                                @Override
                                protected IStatus run(IProgressMonitor monitor) {
                                    final File repoFile = entry.getFile(true);
                                    if (repoFile != null && repoFile.exists()) {
                                        getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                openURI(repoFile.toURI());
                                            }
                                        });
                                    }
                                    return Status.OK_STATUS;
                                }
                            };
                            downloadJob.setUser(true);
                            downloadJob.schedule();
                        }
                    } else if (uri != null) {
                        openURI(uri);
                    }
                } else if (element instanceof ContinueSearchElement) {
                    ContinueSearchElement searchElement = (ContinueSearchElement) element;
                    try {
                        JpmPreferences jpmPrefs = new JpmPreferences();
                        if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
                            URI browseUrl = searchElement.browse();
                            getViewSite().getWorkbenchWindow().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(browseUrl.toURL());
                        } else
                            getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
                    } catch (PartInitException e) {
                        Plugin.getDefault().getLog().log(e.getStatus());
                    } catch (Exception e) {
                        Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load repository browser view", e));
                    }
                } else if (element instanceof RepositoryPlugin) {
                    viewer.setExpandedState(element, !viewer.getExpandedState(element));
                }
            }
        }
    });
    createContextMenu();
    // LAYOUT
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mainPanel.setLayout(layout);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Toolbar
    createActions();
    fillToolBar(getViewSite().getActionBars().getToolBarManager());
    prefs.addPropertyChangeListener(workspaceOfflineListener);
    // synthenic call to "refresh" so that we can get the repositories to show up in the UI
    new WorkspaceJob("Load repositories") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                Central.refreshPlugins();
            } catch (Exception e) {
            // ignore errors there may be no workspace yet
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) IAdaptable(org.eclipse.core.runtime.IAdaptable) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) ContinueSearchElement(bndtools.model.repo.ContinueSearchElement) Tree(org.eclipse.swt.widgets.Tree) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeEvent(java.beans.PropertyChangeEvent) JpmPreferences(bndtools.preferences.JpmPreferences) FormText(org.eclipse.ui.forms.widgets.FormText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) SelectionDragAdapter(bndtools.utils.SelectionDragAdapter) IStatus(org.eclipse.core.runtime.IStatus) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) IFile(org.eclipse.core.resources.IFile) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) PropertyChangeListener(java.beans.PropertyChangeListener) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) URI(java.net.URI) URL(java.net.URL) SearchableRepositoryTreeContentProvider(bndtools.model.repo.SearchableRepositoryTreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) StackLayout(org.eclipse.swt.custom.StackLayout) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IActionBars(org.eclipse.ui.IActionBars) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) IWorkbench(org.eclipse.ui.IWorkbench) WorkspaceSetupWizard(bndtools.wizards.workspace.WorkspaceSetupWizard) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) HttpClient(aQute.bnd.http.HttpClient) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 27 with IDoubleClickListener

use of org.eclipse.jface.viewers.IDoubleClickListener in project translationstudio8 by heartsome.

the class ElementTreeSelectionDialog method createTreeViewer.

/**
     * Creates and initializes the tree viewer.
     *
     * @param parent the parent composite
     * @return the tree viewer
     * @see #doCreateTreeViewer(Composite, int)
     */
protected TreeViewer createTreeViewer(Composite parent) {
    int style = SWT.BORDER | (fAllowMultiple ? SWT.MULTI : SWT.SINGLE);
    fViewer = doCreateTreeViewer(parent, style);
    fViewer.setContentProvider(fContentProvider);
    fViewer.setLabelProvider(fLabelProvider);
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            access$setResult(((IStructuredSelection) event.getSelection()).toList());
            updateOKStatus();
        }
    });
    fViewer.setComparator(fComparator);
    if (fFilters != null) {
        for (int i = 0; i != fFilters.size(); i++) {
            fViewer.addFilter((ViewerFilter) fFilters.get(i));
        }
    }
    if (fDoubleClickSelects) {
        Tree tree = fViewer.getTree();
        tree.addSelectionListener(new SelectionAdapter() {

            public void widgetDefaultSelected(SelectionEvent e) {
                updateOKStatus();
                if (fCurrStatus.isOK()) {
                    access$superButtonPressed(IDialogConstants.OK_ID);
                }
            }
        });
    }
    fViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            updateOKStatus();
            //select then expand
            if (!(fDoubleClickSelects && fCurrStatus.isOK())) {
                ISelection selection = event.getSelection();
                if (selection instanceof IStructuredSelection) {
                    Object item = ((IStructuredSelection) selection).getFirstElement();
                    if (fViewer.getExpandedState(item)) {
                        fViewer.collapseToLevel(item, 1);
                    } else {
                        fViewer.expandToLevel(item, 1);
                    }
                }
            }
        }
    });
    fViewer.setInput(fInput);
    return fViewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 28 with IDoubleClickListener

use of org.eclipse.jface.viewers.IDoubleClickListener in project translationstudio8 by heartsome.

the class TmDbManagerDialog method createPageContainer.

/**
	 * 创建右侧页面内容
	 * @param parent
	 *            页面容器
	 * @return ;
	 */
protected Composite createPageContainer(Composite parent) {
    Composite outer = new Composite(parent, SWT.NONE);
    GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
    outer.setLayout(new GridLayout());
    outer.setLayoutData(outerData);
    // Create an outer composite for spacing
    ScrolledComposite scrolled = new ScrolledComposite(outer, SWT.V_SCROLL | SWT.H_SCROLL);
    // always show the focus control
    scrolled.setShowFocusedControl(true);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    GridLayout gld = new GridLayout(1, false);
    gld.marginWidth = 0;
    gld.marginHeight = 0;
    scrolled.setLayout(gld);
    Composite result = new Composite(scrolled, SWT.NONE);
    GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    result.setLayoutData(resultData);
    GridLayout gl_result = new GridLayout(1, false);
    gl_result.marginWidth = 0;
    gl_result.marginHeight = 0;
    result.setLayout(gl_result);
    Group parameterGroup = new Group(result, SWT.NONE);
    parameterGroup.setText(Messages.getString("dialog.TmDbManagerDialog.parameterGroup"));
    GridLayout parameterLayout = new GridLayout(4, false);
    parameterGroup.setLayout(parameterLayout);
    GridData parameterGridData = new GridData(GridData.FILL_HORIZONTAL);
    parameterGroup.setLayoutData(parameterGridData);
    Label label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblHost"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    hostText = new Text(parameterGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblPort"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    portText = new Text(parameterGroup, SWT.BORDER);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblInstance"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    instanceText = new Text(parameterGroup, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(parameterGroup, SWT.NONE);
    new Label(parameterGroup, SWT.NONE);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblLocation"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    locationText = new Text(parameterGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    borwserBtn = new Button(parameterGroup, SWT.NONE);
    borwserBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    borwserBtn.setText(Messages.getString("dialog.TmDbManagerDialog.borwserBtn"));
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblUsername"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    usernameText = new Text(parameterGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblPwd"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    passwordText = new Text(parameterGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Composite btnComposite = new Composite(parameterGroup, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
    GridLayout btnCompositeLayout = new GridLayout(1, false);
    btnCompositeLayout.marginHeight = 0;
    btnCompositeLayout.marginWidth = 0;
    btnComposite.setLayout(btnCompositeLayout);
    // remenmberBtn = new Button(btnComposite, SWT.CHECK|SWT.BORDER);
    // remenmberBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    // remenmberBtn.setText("将本次连接信息添加到数据库类型的快捷连接方式(&R)");
    // remenmberBtn.setSelection(true);
    searchBtn = new Button(btnComposite, SWT.NONE);
    searchBtn.setText(Messages.getString("dialog.TmDbManagerDialog.searchBtn"));
    searchBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    // 输入合法性检查
                    IStatus status = validator();
                    if (status.getSeverity() != IStatus.OK) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), status.getMessage());
                        return;
                    }
                    SystemDBOperator sysDbOp = getCurrSysDbOp();
                    if (sysDbOp == null) {
                        return;
                    }
                    // 连接检查
                    if (!sysDbOp.checkDbConnection()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg1"));
                        return;
                    }
                    // if (remenmberBtn.getSelection() == true) {
                    // 当前数据库类型下的所有服务器
                    List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(getCurrDbType());
                    if (currServer.getId().equals("")) {
                        addServerWithExistCheck(currServer, currDbTypeServers);
                        getTreeViewer().refresh();
                        // 在树上选择当前操作的节点
                        selectSaveItem();
                    }
                    // ISelection selection = getTreeViewer().getSelection();
                    // if (selection.isEmpty()) {
                    // return;
                    // }
                    // } else { // 不记住信息
                    executeSearch(sysDbOp);
                // }
                }
            });
        }
    });
    Group tableComposite = new Group(result, SWT.NONE);
    tableComposite.setText(Messages.getString("dialog.TmDbManagerDialog.tableComposite"));
    tableComposite.setLayout(new GridLayout(1, false));
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    dbTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table = dbTableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    tableGd.heightHint = 180;
    table.setLayoutData(tableGd);
    createColumn(dbTableViewer);
    if (getDialogUseFor() == TYPE_DBSELECTED) {
        dbTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }
        });
    }
    dbTableViewer.setContentProvider(new ArrayContentProvider());
    currServerdbListInput = new WritableList(currServerdbList, DatabaseManagerDbListBean.class);
    dbTableViewer.setInput(currServerdbListInput);
    Composite composite = new Composite(tableComposite, SWT.NONE);
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.marginHeight = 0;
    gl_composite.marginWidth = 0;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    Button btnc = new Button(composite, SWT.NONE);
    btnc.setText(Messages.getString("dialog.TmDbManagerDialog.btnc"));
    btnc.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createNewDatabase();
        }
    });
    Button btnd_1 = new Button(composite, SWT.NONE);
    btnd_1.setText(Messages.getString("dialog.TmDbManagerDialog.btnd_1"));
    btnd_1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    ISelection selection = getDbTableViewer().getSelection();
                    if (selection.isEmpty()) {
                        return;
                    }
                    if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg2"))) {
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                        @SuppressWarnings("unchecked") List<DatabaseManagerDbListBean> needDeletes = structuredSelection.toList();
                        SystemDBOperator dbop = getCurrSysDbOp();
                        for (int i = 0; i < needDeletes.size(); i++) {
                            try {
                                String dbName = needDeletes.get(i).getDbName();
                                dbop.dropDb(dbName);
                                dbop.removeSysDb(dbName);
                            } catch (Exception e1) {
                                logger.error(Messages.getString("dialog.TmDbManagerDialog.logger1"), e1);
                                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg3") + e1.getMessage());
                                break;
                            }
                            currServerdbListInput.remove(needDeletes.get(i));
                        }
                    }
                }
            });
        }
    });
    Button importBtn = new Button(composite, SWT.NONE);
    importBtn.setText(Messages.getString("dialog.TmDbManagerDialog.importBtn"));
    importBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = getDbTableViewer().getSelection();
            if (selection.isEmpty()) {
                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg4"));
                return;
            }
            IStructuredSelection stcSel = (IStructuredSelection) selection;
            DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) stcSel.getFirstElement();
            DatabaseModelBean dbModelBean = new DatabaseModelBean();
            currServer.copyToOtherIntance(dbModelBean);
            dbModelBean.setDbName(dbBean.getDbName());
            ImportTmxWizard wizard = new ImportTmxWizard(dbModelBean);
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard) {

                // robert help 2012-09-06
                @Override
                protected Control createHelpControl(Composite parent) {
                    // ROBERTHELP 记忆库管理-导入TMX
                    String language = CommonFunction.getSystemLanguage();
                    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#create-tm-wizard-import-tmx", language);
                    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
                    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
                    ((GridLayout) parent.getLayout()).numColumns++;
                    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
                    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
                    toolBar.setCursor(cursor);
                    toolBar.addDisposeListener(new DisposeListener() {

                        public void widgetDisposed(DisposeEvent e) {
                            cursor.dispose();
                        }
                    });
                    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
                    helpItem.setImage(helpImage);
                    //$NON-NLS-1$
                    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
                    helpItem.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                        }
                    });
                    return toolBar;
                }
            };
            dlg.setHelpAvailable(true);
            if (dlg.open() == 0) {
                // 重新加载内容
                executeSearch(getCurrSysDbOp());
            }
        }
    });
    Point searchPoint = searchBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = btnc.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = btnd_1.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(searchPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    btnc.setLayoutData(btnData);
    btnd_1.setLayoutData(btnData);
    importBtn.setLayoutData(btnData);
    searchBtn.getLayoutData();
    GridData searchData = new GridData(SWT.RIGHT, SWT.CENTER, true, true, 4, 1);
    searchData.widthHint = width + 10;
    searchBtn.setLayoutData(searchData);
    scrolled.setContent(result);
    scrolled.setMinSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
    return result;
}
Also used : Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) IStatus(org.eclipse.core.runtime.IStatus) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ToolItem(org.eclipse.swt.widgets.ToolItem) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 29 with IDoubleClickListener

use of org.eclipse.jface.viewers.IDoubleClickListener in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createPageContainer.

/**
	 * 创建右侧页面内容
	 * @param parent
	 *            页面容器
	 * @return ;
	 */
protected Composite createPageContainer(Composite parent) {
    Composite outer = new Composite(parent, SWT.NONE);
    GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
    outer.setLayout(new GridLayout());
    outer.setLayoutData(outerData);
    // Create an outer composite for spacing
    ScrolledComposite scrolled = new ScrolledComposite(outer, SWT.V_SCROLL | SWT.H_SCROLL);
    // always show the focus control
    scrolled.setShowFocusedControl(true);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    GridLayout gld = new GridLayout(1, false);
    gld.marginWidth = 0;
    gld.marginHeight = 0;
    scrolled.setLayout(gld);
    Composite result = new Composite(scrolled, SWT.NONE);
    GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    result.setLayoutData(resultData);
    GridLayout gl_result = new GridLayout(1, false);
    gl_result.marginWidth = 0;
    gl_result.marginHeight = 0;
    result.setLayout(gl_result);
    Group parameterGroup = new Group(result, SWT.NONE);
    parameterGroup.setText(Messages.getString("dialog.TermDbManagerDialog.parameterGroup"));
    GridLayout parameterLayout = new GridLayout(4, false);
    parameterGroup.setLayout(parameterLayout);
    GridData parameterGridData = new GridData(GridData.FILL_HORIZONTAL);
    parameterGroup.setLayoutData(parameterGridData);
    Label label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblHost"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    hostText = new Text(parameterGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblPort"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    portText = new Text(parameterGroup, SWT.BORDER);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblInstance"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    instanceText = new Text(parameterGroup, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(parameterGroup, SWT.NONE);
    new Label(parameterGroup, SWT.NONE);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblLocation"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    locationText = new Text(parameterGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    borwserBtn = new Button(parameterGroup, SWT.NONE);
    borwserBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    borwserBtn.setText(Messages.getString("dialog.TermDbManagerDialog.borwserBtn"));
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblUsername"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    usernameText = new Text(parameterGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblPwd"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    passwordText = new Text(parameterGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Composite btnComposite = new Composite(parameterGroup, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
    GridLayout btnCompositeLayout = new GridLayout(1, false);
    btnCompositeLayout.marginHeight = 0;
    btnCompositeLayout.marginWidth = 0;
    btnComposite.setLayout(btnCompositeLayout);
    // remenmberBtn = new Button(btnComposite, SWT.CHECK|SWT.BORDER);
    // remenmberBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    // remenmberBtn.setText("将本次连接信息添加到数据库类型的快捷连接方式(&R)");
    // remenmberBtn.setSelection(true);
    searchBtn = new Button(btnComposite, SWT.NONE);
    searchBtn.setText(Messages.getString("dialog.TermDbManagerDialog.searchBtn"));
    searchBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    // 输入合法性检查
                    IStatus status = validator();
                    if (status.getSeverity() != IStatus.OK) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), status.getMessage());
                        return;
                    }
                    SystemDBOperator sysDbOp = getCurrSysDbOp();
                    if (sysDbOp == null) {
                        return;
                    }
                    // 连接检查
                    if (!sysDbOp.checkDbConnection()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg1"));
                        return;
                    }
                    // if (remenmberBtn.getSelection() == true) {
                    // 当前数据库类型下的所有服务器
                    List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(getCurrDbType());
                    if (currServer.getId().equals("")) {
                        addServerWithExistCheck(currServer, currDbTypeServers);
                        getTreeViewer().refresh();
                        // 在树上选择当前操作的节点
                        selectSaveItem();
                    }
                    // ISelection selection = getTreeViewer().getSelection();
                    // if (selection.isEmpty()) {
                    // return;
                    // }
                    // } else { // 不记住信息
                    executeSearch(sysDbOp);
                // }
                }
            });
        }
    });
    Group tableComposite = new Group(result, SWT.NONE);
    tableComposite.setText(Messages.getString("dialog.TermDbManagerDialog.tableComposite"));
    tableComposite.setLayout(new GridLayout(1, false));
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    dbTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table = dbTableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    tableGd.heightHint = 180;
    table.setLayoutData(tableGd);
    createColumn(dbTableViewer);
    if (getDialogUseFor() == TYPE_DBSELECTED) {
        dbTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }
        });
    }
    dbTableViewer.setContentProvider(new ArrayContentProvider());
    currServerdbListInput = new WritableList(currServerdbList, DatabaseManagerDbListBean.class);
    dbTableViewer.setInput(currServerdbListInput);
    Composite composite = new Composite(tableComposite, SWT.NONE);
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.marginHeight = 0;
    gl_composite.marginWidth = 0;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    Button btnc = new Button(composite, SWT.NONE);
    btnc.setText(Messages.getString("dialog.TermDbManagerDialog.btnc"));
    btnc.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createNewDatabase();
        }
    });
    Button btnd_1 = new Button(composite, SWT.NONE);
    btnd_1.setText(Messages.getString("dialog.TermDbManagerDialog.btnd_1"));
    btnd_1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    ISelection selection = getDbTableViewer().getSelection();
                    if (selection.isEmpty()) {
                        return;
                    }
                    if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg2"))) {
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                        @SuppressWarnings("unchecked") List<DatabaseManagerDbListBean> needDeletes = structuredSelection.toList();
                        SystemDBOperator dbop = getCurrSysDbOp();
                        for (int i = 0; i < needDeletes.size(); i++) {
                            try {
                                String dbName = needDeletes.get(i).getDbName();
                                dbop.dropDb(dbName);
                                dbop.removeSysDb(dbName);
                            } catch (Exception e1) {
                                logger.error(Messages.getString("dialog.TermDbManagerDialog.logger1"), e1);
                                MessageDialog.openError(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg3") + e1.getMessage());
                                break;
                            }
                            currServerdbListInput.remove(needDeletes.get(i));
                        }
                    }
                }
            });
        }
    });
    Button importBtn = new Button(composite, SWT.NONE);
    importBtn.setText(Messages.getString("dialog.TermDbManagerDialog.importBtn"));
    importBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = getDbTableViewer().getSelection();
            if (selection.isEmpty()) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg4"));
                return;
            }
            IStructuredSelection stcSel = (IStructuredSelection) selection;
            DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) stcSel.getFirstElement();
            DatabaseModelBean dbModelBean = new DatabaseModelBean();
            currServer.copyToOtherIntance(dbModelBean);
            dbModelBean.setDbName(dbBean.getDbName());
            TbxImportWizard wizard = new TbxImportWizard(dbModelBean);
            TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                // 重新加载内容
                executeSearch(getCurrSysDbOp());
            }
        }
    });
    Point searchPoint = searchBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = btnc.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = btnd_1.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(searchPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    btnc.setLayoutData(btnData);
    btnd_1.setLayoutData(btnData);
    importBtn.setLayoutData(btnData);
    searchBtn.getLayoutData();
    GridData searchData = new GridData(SWT.RIGHT, SWT.CENTER, true, true, 4, 1);
    searchData.widthHint = width + 10;
    searchBtn.setLayoutData(searchData);
    scrolled.setContent(result);
    scrolled.setMinSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
    return result;
}
Also used : Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TbxImportWizard(net.heartsome.cat.database.ui.tb.wizard.TbxImportWizard) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 30 with IDoubleClickListener

use of org.eclipse.jface.viewers.IDoubleClickListener in project translationstudio8 by heartsome.

the class AddOrEditSrxConfigDialog method createLanguageGroup.

/**
	 * 创建语言规则配置
	 * @param tparent
	 *            ;
	 */
private void createLanguageGroup(Composite tparent, GridData groupData, GridLayout groupLayout) {
    Group group = new Group(tparent, SWT.BORDER);
    group.setLayoutData(groupData);
    group.setLayout(groupLayout);
    group.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.groupLang"));
    langTableViewer = new TableViewer(group, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    langTable = langTableViewer.getTable();
    langTable.setLinesVisible(true);
    langTable.setHeaderVisible(true);
    GridDataFactory.fillDefaults().span(4, SWT.DEFAULT).grab(true, true).applyTo(langTable);
    langTableViewer.setLabelProvider(new TableViewerLabelProvider());
    langTableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("srx.AddOrEditSrxConfigDialog.langColumnNames1"), Messages.getString("srx.AddOrEditSrxConfigDialog.langColumnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(langTable, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    refreshTableWidth(langTable);
    langAddBtn = new Button(group, SWT.NONE);
    langAddBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.langAddBtn"));
    setButtonLayoutData(langAddBtn);
    langEditBtn = new Button(group, SWT.NONE);
    langEditBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.langEditBtn"));
    setButtonLayoutData(langEditBtn);
    langDeleteBtn = new Button(group, SWT.NONE);
    langDeleteBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.langDeleteBtn"));
    setButtonLayoutData(langDeleteBtn);
    new Label(group, SWT.NONE);
    langTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editLangRules();
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) Button(org.eclipse.swt.widgets.Button) TableViewerLabelProvider(net.heartsome.cat.ts.ui.advanced.TableViewerLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)49 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)49 TableViewer (org.eclipse.jface.viewers.TableViewer)33 SelectionEvent (org.eclipse.swt.events.SelectionEvent)29 GridData (org.eclipse.swt.layout.GridData)28 Composite (org.eclipse.swt.widgets.Composite)28 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)16 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)16 GridLayout (org.eclipse.swt.layout.GridLayout)16 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)14 Table (org.eclipse.swt.widgets.Table)13 TableColumn (org.eclipse.swt.widgets.TableColumn)12 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)11 Label (org.eclipse.swt.widgets.Label)11 Button (org.eclipse.swt.widgets.Button)10 ISelection (org.eclipse.jface.viewers.ISelection)8 FillLayout (org.eclipse.swt.layout.FillLayout)8 Event (org.eclipse.swt.widgets.Event)8