[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: A sensible way of registering events on TreeViewers?

Thankyou - sorry to ask the obvious followup questions, but where would you put these interfaces? Would you create new classes that implement them, or would you have the view implement them. Can I have a couple of code snippets? I'm sorry, but I'm very new to UI design in general...

Tom

Tom Schindl wrote:
I'd use a command and if a double-click occurs I'd execute this command using the ICommandServer/IHandlerService. You can then in any part of your system listen to the command and act upon it.

You'll also have to register your Viewer as a SelectionProvider in the SelectionService this way you can easily read it in any part of your RCP application.

Tom

Tom Bradshaw schrieb:
Hi, I'm (very) new to RCP applications - so please bear with me.

I've got an application with three views in it. One of the views contains a TreeView with a directory structure in it, another one contains a TableViewer listing the contents of the current directory. At the moment I'm registering a DoubleClickListener with the TreeViewer itself, and calling a static method that invokes the action itself:

----------

    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
        IStructuredSelection sel = (IStructuredSelection) event
            .getSelection();
        selectedNode = (FolderNode) sel.getFirstElement();
        System.out.println(selectedNode.getName());

        IWorkbenchWindow window = PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow();
        UpdateCollectionViewAction.run(window);

        }
    });
----------

Here's the static method.

----------

public static void run(IWorkbenchWindow window) {
    IWorkbenchPage page = window.getActivePage();
    collectionView = (CollectionView) page.findView(CollectionView.ID);
    collectionTable = collectionView.getViewer();

    navView = (NavigationView) page.findView(NavigationView.ID);
    folder = navView.getSelectedNode();

    DocumentList.getInstance().clearDocumentList();
    File parentFolder = folder.getFile();
    File[] folderContent = parentFolder.listFiles();
    for (int i = 1; i < folderContent.length; i++) {
        if (folderContent[i].isFile()) {
        Document document = new Document(folderContent[i].getName(),
            folderContent[i].getAbsolutePath());
        DocumentList.getInstance().addDocument(document);
        }
    }
    collectionTable.refresh();

    }

----------

This works, but it feels very, very dirty. Is there a more elegant way of doing this?