Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4aef5ec9270c063ec1eac7e95ebc140060e652c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package org.eclipse.emf.cdo.internal.ui.wizards.old;

import org.eclipse.emf.cdo.CDOSession;

import org.eclipse.net4j.transport.ConnectorException;

import org.eclipse.core.internal.resources.Container;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import java.lang.reflect.InvocationTargetException;

public class NewEditorWizard extends Wizard implements INewWizard
{
  private NewSessionWizardPage sessionPage;

  private NewEditorWizardPage editorPage;

  private ISelection selection;

  public NewEditorWizard()
  {
    setNeedsProgressMonitor(true);
  }

  public void addPages()
  {
    CDOSession session = null;
    if (selection instanceof IStructuredSelection)
    {
      Object element = ((IStructuredSelection)selection).getFirstElement();
      if (element instanceof CDOSession)
      {
        session = (CDOSession)element;
      }
    }

    if (session == null)
    {
      addPage(sessionPage = new NewSessionWizardPage(selection));
    }

    addPage(editorPage = new NewEditorWizardPage());
    editorPage.setSession(session);
  }

  public boolean performFinish()
  {
    final String connectorDescription = sessionPage.getConnectorDescription();
    final String repositoryName = sessionPage.getRepositoryName();
    IRunnableWithProgress op = new IRunnableWithProgress()
    {
      public void run(IProgressMonitor monitor) throws InvocationTargetException
      {
        try
        {
          doFinish(connectorDescription, repositoryName, monitor);
        }
        catch (Exception e)
        {
          throw new InvocationTargetException(e);
        }
        finally
        {
          monitor.done();
        }
      }
    };

    try
    {
      getContainer().run(true, false, op);
    }
    catch (InterruptedException e)
    {
      return false;
    }
    catch (InvocationTargetException e)
    {
      Throwable realException = e.getTargetException();
      MessageDialog.openError(getShell(), "Error", realException.getMessage());
      return false;
    }

    return true;
  }

  private void doFinish(String connectorDescription, String repositoryName, IProgressMonitor monitor)
      throws ConnectorException
  {
    String description = repositoryName + "@" + connectorDescription;
    monitor.beginTask("Opening " + description, 1);
    Container container = ContainerManager.INSTANCE.getContainer();
    CDOContainerAdapter adapter = (CDOContainerAdapter)container.getAdapter("cdoclient");
    adapter.getSession(description);
    monitor.worked(1);

    // monitor.setTaskName("Opening file for editing...");
    // getShell().getDisplay().asyncExec(new Runnable()
    // {
    // public void run()
    // {
    // IWorkbenchPage page =
    // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    // try
    // {
    // IDE.openEditor(page, file, true);
    // }
    // catch (PartInitException e)
    // {
    // }
    // }
    // });
    // monitor.worked(1);
  }

  public void init(IWorkbench workbench, IStructuredSelection selection)
  {
    this.selection = selection;
  }
}

Back to the top