Ejemplo n.º 1
0
  public static IStatus connectWithPromptIfNeeded(IConnectionProfile profile, boolean reprompt) {
    String profileName = profile.getName();

    Shell shell = Display.getCurrent().getActiveShell();
    IStatus connectionStatus = null;
    ConnectionInfo info = null;
    if (profile != null) {
      if (shell == null) {
        connectionStatus = profile.connect();
      } else {
        connectionStatus = profile.connectWithoutJob();
        if (reprompt
            && profile.getConnectionState() != IConnectionProfile.CONNECTED_STATE
            && connectionStatus.getCode()
                != IStatus.OK) // could be marked OK if the profile can't be found for some reason
        {
          String title = NLS.bind(SQLNlsStrings.SQL_CONNECTION_FAILURE_MSG, profile.getName());
          MessageDialog.openInformation(
              shell, title, connectionStatus.getChildren()[0].getException().getLocalizedMessage());

          // Prompt to fix properties
          PropertyDialogAction propertyDialogAction =
              new PropertyDialogAction(
                  new SameShellProvider(shell),
                  new ConnectionPropertiesWizardSelectionProvider(profile));

          StructuredSelection selection = new StructuredSelection(profile);
          propertyDialogAction.selectionChanged(selection);
          if (!profile.arePropertiesComplete() && propertyDialogAction.isApplicableForSelection()) {
            // something in createDialog is failing to initialize the properties correctly the first
            // time
            // around. I can't debug it because it crashes the debugger when I set a breakpoint, so
            // I'll
            // call twice for now to get the initialization to happen until I figure it out.
            PreferenceDialog dialog = propertyDialogAction.createDialog();
            dialog = propertyDialogAction.createDialog();
            String shellText =
                NLS.bind(SQLNlsStrings.SQL_CONNECTION_PROPERTIES_FOR, profile.getName());
            dialog.getShell().setText(shellText);
            IConnectionProfileProvider provider = profile.getProvider();
            IPropertiesPersistenceHook hook =
                ((ConnectionProfileProvider) provider).getPropertiesPersistenceHook();
            String initialPage = hook.getConnectionPropertiesPageID();
            if (initialPage != null) {
              ((IWorkbenchPreferenceContainer) dialog).openPage(initialPage, null);
            }
            if (dialog.open() == Dialog.CANCEL) {
              reprompt = false;
            }
          }
          if (reprompt) {
            connectionStatus = profile.connectWithoutJob();
          }
        }
      }
    }

    return connectionStatus;
  }
Ejemplo n.º 2
0
 private void initialize(ISelectionProvider provider) {
   fSelectionProvider = provider;
   ISelection selection = provider.getSelection();
   fOpenImplementation.update(selection);
   fOpenSuperImplementation.update(selection);
   fOpenAttachedJavadoc.update(selection);
   fOpenTypeHierarchy.update(selection);
   fOpenCallHierarchy.update(selection);
   if (!fEditorIsOwner) {
     if (fShowOpenPropertiesAction) {
       if (selection instanceof IStructuredSelection) {
         fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection);
       } else {
         fOpenPropertiesDialog.selectionChanged(selection);
       }
     }
     provider.addSelectionChangedListener(fOpenImplementation);
     provider.addSelectionChangedListener(fOpenSuperImplementation);
     provider.addSelectionChangedListener(fOpenAttachedJavadoc);
     provider.addSelectionChangedListener(fOpenTypeHierarchy);
     provider.addSelectionChangedListener(fOpenCallHierarchy);
     // no need to register the open properties dialog action since it registers itself
   }
 }