Esempio 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;
  }
Esempio n. 2
0
  /* (non-Javadoc)
   * Method declared in ActionGroup
   */
  @Override
  public void fillContextMenu(IMenuManager menu) {
    super.fillContextMenu(menu);
    if (!fIsTypeHiararchyViewerOwner) appendToGroup(menu, fOpenTypeHierarchy);
    if (!fIsCallHiararchyViewerOwner) appendToGroup(menu, fOpenCallHierarchy);

    if (fShowShowInMenu) {
      MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
      IWorkbenchWindow workbenchWindow = fOpenSuperImplementation.getSite().getWorkbenchWindow();
      showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(workbenchWindow));
      menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, showInSubMenu);
    }

    IStructuredSelection selection = getStructuredSelection();
    if (fShowOpenPropertiesAction
        && selection != null
        && fOpenPropertiesDialog.isApplicableForSelection())
      menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
  }