Exemplo n.º 1
0
  /**
   * Opens the introduction componenet.
   *
   * <p>Clients must not call this method directly (although super calls are okay). The default
   * implementation opens the intro in the first window provided if the preference
   * IWorkbenchPreferences.SHOW_INTRO is <code>true</code>. If an intro is shown then this
   * preference will be set to <code>false</code>. Subsequently, and intro will be shown only if
   * <code>WorkbenchConfigurer.getSaveAndRestore()</code> returns <code>true</code> and the
   * introduction was visible on last shutdown. Subclasses may override.
   */
  public void openIntro() {
    // TODO: Refactor this into an IIntroManager.openIntro(IWorkbenchWindow) call

    // introOpened flag needs to be global
    IWorkbenchConfigurer wbConfig = getWindowConfigurer().getWorkbenchConfigurer();
    final String key = "introOpened"; // $NON-NLS-1$
    Boolean introOpened = (Boolean) wbConfig.getData(key);
    if (introOpened != null && introOpened.booleanValue()) {
      return;
    }

    wbConfig.setData(key, Boolean.TRUE);

    boolean showIntro =
        PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_INTRO);

    IIntroManager introManager = wbConfig.getWorkbench().getIntroManager();

    boolean hasIntro = introManager.hasIntro();
    boolean isNewIntroContentAvailable = introManager.isNewContentAvailable();

    if (hasIntro && (showIntro || isNewIntroContentAvailable)) {
      PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_INTRO, false);
      PrefUtil.saveAPIPrefs();

      introManager.showIntro(getWindowConfigurer().getWindow(), false);
    }
  }
 /** Create a new instance of the receiver. */
 private ProgressViewUpdater() {
   createUpdateJob();
   collectors = new IProgressUpdateCollector[0];
   ProgressManager.getInstance().addListener(this);
   debug =
       PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS);
 }
Exemplo n.º 3
0
  private static boolean confirmPerspectiveSwitch(
      IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) {
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();

    String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) {
      // Return whether or not we should always switch
      return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm);
    }

    String desc = finalPersp.getDescription();
    String message;

    if (desc == null || desc.length() == 0) {
      message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel());
    } else {
      message =
          NLS.bind(
              ResourceMessages.NewProject_perspSwitchMessageWithDesc,
              new String[] {finalPersp.getLabel(), desc});
    }

    MessageDialogWithToggle dialog =
        MessageDialogWithToggle.openYesNoQuestion(
            window.getShell(),
            ResourceMessages.NewProject_perspSwitchTitle,
            message,
            null,
            false,
            store,
            IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    int result = dialog.getReturnCode();

    // If we are not going to prompt anymore propogate the choice.
    if (dialog.getToggleState()) {
      String preferenceValue;

      if (result == IDialogConstants.YES_ID) {
        // Doesn't matter if it is replace or new window
        // as we are going to use the open perspective setting
        preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE;
      } else {
        preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE;
      }

      // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond
      PrefUtil.getAPIPreferenceStore()
          .setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue);
    }

    return result == IDialogConstants.YES_ID;
  }
 private void updateToolItem(ToolItem ti, String attName, Object newValue) {
   boolean showText =
       PrefUtil.getAPIPreferenceStore()
           .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR);
   if (showText && UIEvents.UILabel.LABEL.equals(attName)) {
     String newName = (String) newValue;
     ti.setText(newName);
   } else if (UIEvents.UILabel.TOOLTIP.equals(attName)) {
     String newTTip = (String) newValue;
     ti.setToolTipText(newTTip);
   }
 }
  /**
   * maximum display CheatSheetView.
   *
   * @param view
   */
  public void maxDisplayCheatSheetView(CheatSheetView view) {
    // ADD msjian TDQ-7407 2013-8-23: Only display the Cheat Sheet view on new startup of the studio
    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    activePage.setEditorAreaVisible(true);
    // activePage.resetPerspective();
    for (IViewReference ref : activePage.getViewReferences()) {
      if (view.equals(ref.getView(false))) {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MAXIMIZED);
        activePage.bringToTop(ref.getView(false));
      } else {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
      }
    }
    for (IEditorReference ref : activePage.getEditorReferences()) {
      activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
    }

    PrefUtil.getAPIPreferenceStore().setValue(this.getClass().getSimpleName(), true);
    setFirstTime(!PrefUtil.getAPIPreferenceStore().getBoolean(this.getClass().getSimpleName()));
    // TDQ-7407~
  }
  @PreDestroy
  void cleanUp() {
    if (perspectiveImage != null) {
      perspectiveImage.dispose();
      perspectiveImage = null;
    }

    eventBroker.unsubscribe(toBeRenderedHandler);
    eventBroker.unsubscribe(childrenHandler);
    eventBroker.unsubscribe(selectionHandler);
    eventBroker.unsubscribe(labelHandler);

    PrefUtil.getAPIPreferenceStore().removePropertyChangeListener(propertyChangeListener);
  }
  private void setPropertyChangeListener() {
    propertyChangeListener =
        new IPropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            if (IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR.equals(
                propertyChangeEvent.getProperty())) {
              Object newValue = propertyChangeEvent.getNewValue();
              boolean showText = true; // default
              if (newValue instanceof Boolean) showText = ((Boolean) newValue).booleanValue();
              else if ("false".equals(newValue)) // $NON-NLS-1$
              showText = false;
              changeShowText(showText);
            }
          }
        };
    PrefUtil.getAPIPreferenceStore().addPropertyChangeListener(propertyChangeListener);
  }
Exemplo n.º 8
0
  public static void switchToLiferayPerspective() {
    // Retrieve the new project open perspective preference setting
    String perspSetting =
        PrefUtil.getAPIPreferenceStore().getString(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE);

    String promptSetting =
        IDEWorkbenchPlugin.getDefault()
            .getPreferenceStore()
            .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    // Return if do not switch perspective setting and are not prompting
    if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT))
        && perspSetting.equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) {
      return;
    }

    // Map perspective id to descriptor.
    IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();

    IPerspectiveDescriptor finalPersp = reg.findPerspectiveWithId(LiferayPerspectiveFactory.ID);

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

    if (window != null) {
      IWorkbenchPage page = window.getActivePage();

      if (page != null) {
        IPerspectiveDescriptor currentPersp = page.getPerspective();

        // don't switch if the current perspective is the Liferay perspective
        if (finalPersp.equals(currentPersp)) {
          return;
        }
      }

      // prompt the user to switch
      if (!confirmPerspectiveSwitch(window, finalPersp)) {
        return;
      }
    }

    // replace active perspective setting otherwise
    replaceCurrentPerspective(finalPersp);
  }
 private void addShowTextItem(final Menu menu) {
   final MenuItem showtextMenuItem = new MenuItem(menu, SWT.CHECK);
   showtextMenuItem.setText(WorkbenchMessages.PerspectiveBar_showText);
   showtextMenuItem.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           boolean preference = showtextMenuItem.getSelection();
           if (preference
               != PrefUtil.getAPIPreferenceStore()
                   .getDefaultBoolean(
                       IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)) {
             PrefUtil.getInternalPreferenceStore()
                 .setValue(IPreferenceConstants.OVERRIDE_PRESENTATION, true);
           }
           PrefUtil.getAPIPreferenceStore()
               .setValue(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR, preference);
           changeShowText(preference);
         }
       });
   showtextMenuItem.setSelection(
       PrefUtil.getAPIPreferenceStore()
           .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR));
 }
/** this class is used for cheatsheet view display. */
@SuppressWarnings("restriction")
public class CheatSheetUtils {

  private static CheatSheetUtils instance;

  /**
   * this flag means the first time when studio start. only when this value is true, when close the
   * welcome page, we will display and maximum display cheatsheet view, else do nothing.
   */
  private boolean isFirstTime =
      !PrefUtil.getAPIPreferenceStore().getBoolean(this.getClass().getSimpleName());

  /**
   * Sets the isFirstTime.
   *
   * @param isFirstTime the isFirstTime to set
   */
  public void setFirstTime(boolean isFirstTime) {
    this.isFirstTime = isFirstTime;
  }

  /**
   * Getter for isFirstTime.
   *
   * @return the isFirstTime
   */
  public boolean isFirstTime() {
    return this.isFirstTime;
  }

  public static final String DQ_PERSPECTIVE_ID =
      "org.talend.dataprofiler.DataProfilingPerspective"; //$NON-NLS-1$

  private static Logger log = Logger.getLogger(CheatSheetUtils.class);

  public static CheatSheetUtils getInstance() {
    if (instance == null) {
      instance = new CheatSheetUtils();
    }
    return instance;
  }

  /**
   * maximum display CheatSheetView.
   *
   * @param view
   */
  public void maxDisplayCheatSheetView(CheatSheetView view) {
    // ADD msjian TDQ-7407 2013-8-23: Only display the Cheat Sheet view on new startup of the studio
    IWorkbenchPage activePage =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    activePage.setEditorAreaVisible(true);
    // activePage.resetPerspective();
    for (IViewReference ref : activePage.getViewReferences()) {
      if (view.equals(ref.getView(false))) {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MAXIMIZED);
        activePage.bringToTop(ref.getView(false));
      } else {
        activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
      }
    }
    for (IEditorReference ref : activePage.getEditorReferences()) {
      activePage.setPartState(ref, IWorkbenchPage.STATE_MINIMIZED);
    }

    PrefUtil.getAPIPreferenceStore().setValue(this.getClass().getSimpleName(), true);
    setFirstTime(!PrefUtil.getAPIPreferenceStore().getBoolean(this.getClass().getSimpleName()));
    // TDQ-7407~
  }

  /** find And maximum Display CheatSheet. */
  public void findAndmaxDisplayCheatSheet() {
    CheatSheetView findCheetSheet = findCheetSheet();
    if (findCheetSheet != null) {
      maxDisplayCheatSheetView(findCheetSheet);
    }
  }

  /**
   * get the cheet sheet view.
   *
   * @return CheatSheetView
   */
  public CheatSheetView findCheetSheet() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    return (CheatSheetView) page.findView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID);
  }

  /**
   * hide the cheet sheet view.
   *
   * @param cheetSheet
   */
  public void hideCheetSheet(CheatSheetView cheetSheet) {
    try {
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(cheetSheet);
    } catch (Throwable t) {
      log.warn(t, t);
    }
  }
}
  private ToolItem addPerspectiveItem(MPerspective persp) {
    int perspIndex = persp.getParent().getChildren().indexOf(persp);

    int index = perspIndex + 2; // HACK !! accounts for the 'open' and the
    // separator
    final ToolItem psItem =
        index < psTB.getItemCount()
            ? new ToolItem(psTB, SWT.RADIO, index)
            : new ToolItem(psTB, SWT.RADIO);
    psItem.setData(persp);
    IPerspectiveDescriptor descriptor = getDescriptorFor(persp.getElementId());
    boolean foundImage = false;
    if (descriptor != null) {
      ImageDescriptor desc = descriptor.getImageDescriptor();
      if (desc != null) {
        final Image image = desc.createImage(false);
        if (image != null) {
          psItem.setImage(image);

          psItem.addListener(
              SWT.Dispose,
              new Listener() {
                public void handleEvent(org.eclipse.swt.widgets.Event event) {
                  image.dispose();
                }
              });
          foundImage = true;
          psItem.setToolTipText(persp.getLocalizedLabel());
        }
      }
    }
    if (!foundImage
        || PrefUtil.getAPIPreferenceStore()
            .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)) {
      psItem.setText(persp.getLocalizedLabel());
      psItem.setToolTipText(persp.getLocalizedTooltip());
    }

    psItem.setSelection(persp == persp.getParent().getSelectedElement());

    psItem.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            MPerspective persp = (MPerspective) e.widget.getData();
            persp.getParent().setSelectedElement(persp);
          }

          public void widgetDefaultSelected(SelectionEvent e) {
            MPerspective persp = (MPerspective) e.widget.getData();
            persp.getParent().setSelectedElement(persp);
          }
        });

    psItem.addListener(
        SWT.MenuDetect,
        new Listener() {
          public void handleEvent(org.eclipse.swt.widgets.Event event) {
            MPerspective persp = (MPerspective) event.widget.getData();
            openMenuFor(psItem, persp);
          }
        });

    // update the size
    fixSize();

    return psItem;
  }