Пример #1
0
 /**
  * Prompts to shutdown studio and if user accepts, then Studio is shutdown immediately.
  *
  * @param title
  * @param message
  * @param productId
  */
 public static void closeStudio(String title, String message, String productId) {
   MessageDialog.openError(UIUtils.getActiveShell(), title, message);
   // not to use EclipseUtil.isStandalone() directly since it checks the existance of Aptana Studio
   // RCP instead
   // TODO fix EclipseUtil.isStandalone() to maybe read from a preference key on what plugin id to
   // check.
   if (EclipseUtil.getPluginVersion(productId) != null && !EclipseUtil.isTesting()) {
     PlatformUI.getWorkbench().close();
   }
 }
Пример #2
0
  /**
   * Schedules a message dialog to be displayed safely in the UI thread
   *
   * @param runnable Something that gets run if the message dialog return code is Window.OK
   * @param runnableCondition The return code from SafeMessageDialogRunnable.openMessageDialog()
   *     that would trigger SafeMessageDialogRunnable.run()
   */
  public static void showMessageDialogFromBgThread(
      final SafeMessageDialogRunnable runnable, final int runnableCondition) {
    UIJob job = new UIJob("Modal Message Dialog Job") // $NON-NLS-1$
        {

          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            // If the system dialog is shown, then the active shell would be null
            if (Display.getDefault().getActiveShell() == null) {
              if (!monitor.isCanceled()) {
                schedule(1000);
              }
            } else if (!monitor.isCanceled()) {
              if (runnable.openMessageDialog() == runnableCondition) {
                try {
                  runnable.run();
                } catch (Exception e) {
                  IdeLog.logError(UIPlugin.getDefault(), e);
                }
              }
            }
            return Status.OK_STATUS;
          }
        };
    EclipseUtil.setSystemForJob(job);
    job.schedule();
  }
Пример #3
0
 @Override
 protected void tearDown() throws Exception {
   try {
     EclipseUtil.instanceScope()
         .getNode(CSSPlugin.PLUGIN_ID)
         .remove(IPreferenceConstants.INITIALLY_FOLD_COMMENTS);
   } finally {
     super.tearDown();
   }
 }
Пример #4
0
  /**
   * Update the current metadata index version number so that it matches the value returned by
   * getIndexVersion. This is called once the metadata index has been updated
   */
  protected void updateVersionPreference() {
    IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(this.getPluginId());

    prefs.putDouble(this.getIndexVersionKey(), this.getIndexVersion());

    try {
      prefs.flush();
    } catch (BackingStoreException e) {
    }
  }
  /*
   * (non-Javadoc)
   * @see com.aptana.usage.IAnalyticsEventHandler#sendEvent(com.aptana.usage.AnalyticsEvent)
   */
  public void sendEvent(final AnalyticsEvent event) {
    Job job = new Job("Sending Analytics Ping ...") // $NON-NLS-1$
        {

          @Override
          protected IStatus run(IProgressMonitor monitor) {
            IAnalyticsUserManager userManager = AnalyticsEvent.getUserManager();
            if (userManager == null) {
              // send as anonymous user
              if (!isValidResponse(responseCode = sendPing(event, null))) {
                // log the event to the database
                AnalyticsLogger.getInstance().logEvent(event);
              }
              return Status.OK_STATUS;
            }

            IAnalyticsUser user = userManager.getUser();
            // Only send ping if user is logged in. Otherwise, we log it to the database
            if (user == null
                || !user.isOnline()
                || !isValidResponse(responseCode = sendPing(event, user))) {
              // log the event to the database
              AnalyticsLogger.getInstance().logEvent(event);
            } else {
              // Send out all previous events from the db
              synchronized (lock) {
                List<AnalyticsEvent> events = AnalyticsLogger.getInstance().getEvents();
                // Sort the events. We want all project.create events to be first, and all
                // project.delete events
                // to be last
                Collections.sort(events, new AnalyticsEventComparator());
                for (AnalyticsEvent aEvent : events) {
                  if (!isValidResponse(responseCode = sendPing(aEvent, user))) {
                    return Status.OK_STATUS;
                  }
                  // Remove the event after it has been sent
                  AnalyticsLogger.getInstance().clearEvent(aEvent);
                }
              }
            }
            return Status.OK_STATUS;
          }
        };
    job.setSystem(true);
    job.setPriority(Job.BUILD);
    job.schedule();

    // Make this a blocking job for unit tests
    if (EclipseUtil.isTesting()) {
      try {
        job.join();
      } catch (InterruptedException e) {
      }
    }
  }
Пример #6
0
  @Override
  public void initializeDefaultPreferences() {
    IEclipsePreferences prefs = EclipseUtil.defaultScope().getNode(YAMLPlugin.PLUGIN_ID);
    prefs.putBoolean(IPreferenceConstants.EDITOR_AUTO_INDENT, true);
    prefs.putBoolean(IPreferenceConstants.EDITOR_ENABLE_FOLDING, true);
    prefs.putBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, true);
    prefs.putInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 2);

    // mark occurrences
    prefs.putBoolean(
        com.aptana.editor.common.preferences.IPreferenceConstants.EDITOR_MARK_OCCURRENCES, true);
  }
Пример #7
0
  private void readExtensionRegistry() {
    EclipseUtil.processConfigurationElements(
        SamplesPlugin.PLUGIN_ID,
        EXTENSION_POINT,
        new IConfigurationElementProcessor() {

          public void processElement(IConfigurationElement element) {
            readElement(element);
          }
        },
        ELEMENT_CATEGORY,
        ELEMENT_SAMPLESINFO);
  }
 @Override
 public void initializeDefaultPreferences() {
   IEclipsePreferences prefs = EclipseUtil.defaultScope().getNode(CoreIOPlugin.PLUGIN_ID);
   prefs.putBoolean(IPreferenceConstants.UPLOAD_UPDATE_PERMISSIONS, true);
   prefs.putBoolean(IPreferenceConstants.UPLOAD_SPECIFIC_PERMISSIONS, true);
   prefs.putLong(IPreferenceConstants.UPLOAD_FILE_PERMISSION, DEFAULT_FILE_PERMISSIONS);
   prefs.putLong(IPreferenceConstants.UPLOAD_FOLDER_PERMISSION, DEFAULT_DIRECTORY_PERMISSIONS);
   prefs.putBoolean(IPreferenceConstants.DOWNLOAD_UPDATE_PERMISSIONS, true);
   prefs.putBoolean(IPreferenceConstants.DOWNLOAD_SPECIFIC_PERMISSIONS, true);
   prefs.putLong(IPreferenceConstants.DOWNLOAD_FILE_PERMISSION, DEFAULT_FILE_PERMISSIONS);
   prefs.putLong(IPreferenceConstants.DOWNLOAD_FOLDER_PERMISSION, DEFAULT_DIRECTORY_PERMISSIONS);
   prefs.put(IPreferenceConstants.GLOBAL_CLOAKING_EXTENSIONS, DEFAULT_CLOAK_EXPRESSIONS);
 }
Пример #9
0
  public void testCSSCommentInitiallyFolded() throws Exception {
    String src = "/*\n * This is a comment.\n */\n";

    // Turn on initially folding comments
    EclipseUtil.instanceScope()
        .getNode(CSSPlugin.PLUGIN_ID)
        .putBoolean(IPreferenceConstants.INITIALLY_FOLD_COMMENTS, true);

    Map<ProjectionAnnotation, Position> annotations =
        emitFoldingRegions(true, new NullProgressMonitor(), src);
    assertTrue(annotations.keySet().iterator().next().isCollapsed());

    // After initial reconcile, don't mark any collapsed
    annotations = emitFoldingRegions(false, new NullProgressMonitor(), src);
    assertFalse(annotations.keySet().iterator().next().isCollapsed());
  }
Пример #10
0
 private void updateEnablement() {
   boolean enableOverride = overridePrefs.getSelection();
   suspendOnFirstLine.setEnabled(enableOverride);
   suspendOnExceptions.setEnabled(enableOverride);
   suspendOnErrors.setEnabled(enableOverride);
   suspendOnDebuggerKeyword.setEnabled(enableOverride);
   try {
     if (enableOverride) {
       setValuesFrom(launchConfiguration);
     } else {
       setValuesFrom(
           new ScopedPreferenceStore(EclipseUtil.instanceScope(), JSDebugPlugin.PLUGIN_ID));
     }
   } catch (CoreException ignore) {
   }
 }
Пример #11
0
  protected Control createDialogArea(Composite parent) {
    dialogArea = new Composite(parent, SWT.NONE);
    dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    dialogArea.setLayout(layout);
    dialogArea.addMouseListener(clickListener);

    // The "click to update" label
    Label infoLabel = new Label(dialogArea, SWT.NONE);
    infoLabel.setText(
        MessageFormat.format(
            EplMessages.TitaniumUpdatePopup_update_detail, EclipseUtil.getStudioPrefix()));
    infoLabel.setLayoutData(new GridData(GridData.FILL_BOTH));
    infoLabel.addMouseListener(clickListener);

    return dialogArea;
  }
Пример #12
0
  /*
   * (non-Javadoc)
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context)
      throws Exception // $codepro.audit.disable declaredExceptions
      {
    super.start(context);
    plugin = this;

    Job startupJob = new Job("Start Ruble bundle manager") // $NON-NLS-1$
        {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            ExecutionListenerRegistrant.getInstance();

            // install key binding Manager
            KeybindingsManager.install();

            return Status.OK_STATUS;
          }
        };
    EclipseUtil.setSystemForJob(startupJob);
    startupJob.schedule();
  }
Пример #13
0
  public TitaniumUpdatePopup(Shell parentShell, final Runnable updateAction) {
    super(
        parentShell,
        PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE | SWT.MODELESS,
        false,
        true,
        true,
        false,
        false,
        MessageFormat.format(
            EplMessages.TitaniumUpdatePopup_update_title, EclipseUtil.getStudioPrefix()),
        null);

    clickListener =
        new MouseAdapter() {
          public void mouseDown(MouseEvent e) {
            updateAction.run();
            close();
          }
        };
  }
 static {
   String url = EclipseUtil.getSystemProperty(IUsageSystemProperties.ANALYTICS_URL);
   ANALYTICS_URL =
       (url == null) ? "https://api.appcelerator.net/p/v1/app-track" : url; // $NON-NLS-1$
 }
  /*
   * (non-Javadoc)
   * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;

    Job job = new Job("Initializing Syncing plugin") // $NON-NLS-1$
        {
          protected IStatus run(IProgressMonitor monitor) {

            try {
              ISavedState lastState =
                  ResourcesPlugin.getWorkspace()
                      .addSaveParticipant(getDefault(), new WorkspaceSaveParticipant());
              if (lastState != null) {
                IPath location = lastState.lookup(new Path(SiteConnectionManager.STATE_FILENAME));
                if (location != null) {
                  SiteConnectionManager.getInstance()
                      .loadState(getStateLocation().append(location));
                }
                location = lastState.lookup(new Path(DefaultSiteConnection.STATE_FILENAME));
                if (location != null) {
                  DefaultSiteConnection.getInstance()
                      .loadState(getStateLocation().append(location));
                }
              }

              // For 1.5 compatibility
              lastState =
                  ResourcesPlugin.getWorkspace()
                      .addSaveParticipant(
                          CorePlugin.getDefault(),
                          new ISaveParticipant() {

                            public void doneSaving(ISaveContext context) {}

                            public void prepareToSave(ISaveContext context) throws CoreException {}

                            public void rollback(ISaveContext context) {}

                            public void saving(ISaveContext context) throws CoreException {}
                          });
              if (lastState != null) {
                IPath location = lastState.lookup(new Path("save")); // $NON-NLS-1$
                if (location != null) {
                  IPath absoluteLocation =
                      CorePlugin.getDefault().getStateLocation().append(location);
                  // only loads it once
                  SiteConnectionManager.getInstance().loadState(absoluteLocation);
                  File file = absoluteLocation.toFile();
                  if (!file.renameTo(
                      new File(absoluteLocation.toOSString() + ".bak"))) { // $NON-NLS-1$
                    file.delete();
                  }
                }
              }
            } catch (IllegalStateException e) {
              IdeLog.logError(getDefault(), e);
            } catch (CoreException e) {
              IdeLog.logError(getDefault(), e);
            }

            return Status.OK_STATUS;
          }
        };
    EclipseUtil.setSystemForJob(job);
    job.schedule();
  }
Пример #16
0
  private void loadExtension() {
    EclipseUtil.processConfigurationElements(
        UsagePlugin.PLUGIN_ID,
        EXTENSION_POINT_ID,
        new IConfigurationElementProcessor() {

          public void processElement(IConfigurationElement element) {
            String name = element.getName();
            if (ELEMENT_INFO.equals(name)) {
              String appId = element.getAttribute(ATTR_APP_ID);
              if (StringUtil.isEmpty(appId)) {
                return;
              }
              String appName = element.getAttribute(ATTR_APP_NAME);
              if (StringUtil.isEmpty(appName)) {
                return;
              }
              String appGuid = element.getAttribute(ATTR_APP_GUID);
              if (StringUtil.isEmpty(appGuid)) {
                return;
              }
              String versionPluginId = element.getAttribute(ATTR_VERSION_PLUGIN_ID);
              if (StringUtil.isEmpty(versionPluginId)) {
                return;
              }
              String userAgent = element.getAttribute(ATTR_USER_AGENT);
              if (StringUtil.isEmpty(userAgent)) {
                return;
              }
              IAnalyticsUserManager userManager = null;
              String userManagerClass = element.getAttribute(ATTR_USER_MANAGER);
              if (!StringUtil.isEmpty(userManagerClass)) {
                try {
                  Object clazz = element.createExecutableExtension(ATTR_USER_MANAGER);
                  if (clazz instanceof IAnalyticsUserManager) {
                    userManager = (IAnalyticsUserManager) clazz;
                  }
                } catch (CoreException e) {
                  IdeLog.logError(UsagePlugin.getDefault(), e);
                }
              }
              analyticsInfoMap.put(
                  appId,
                  new AnalyticsInfo(
                      appId, appName, appGuid, versionPluginId, userAgent, userManager));
            } else if (ELEMENT_ANALYTICS.equals(name)) {
              String id = element.getAttribute(ATTR_ID);
              if (StringUtil.isEmpty(id)) {
                return;
              }
              String infoId = element.getAttribute(ATTR_INFO);
              if (StringUtil.isEmpty(infoId)) {
                return;
              }
              AnalyticsInfo info = analyticsInfoMap.get(infoId);
              if (info == null) {
                return;
              }
              String overridesId = element.getAttribute(ATTR_OVERRIDES);
              analyticsMap.put(id, new Analytics(info, overridesId));
            }
          }
        },
        ELEMENT_INFO,
        ELEMENT_ANALYTICS);

    Set<String> keys = analyticsMap.keySet();
    Analytics analytics;
    for (String key : keys) {
      analytics = analyticsMap.get(key);
      if (analytics.overridesId != null && analyticsMap.containsKey(analytics.overridesId)) {
        // replaces the overridden analytics info
        analyticsMap.put(analytics.overridesId, analytics);
      }
    }
  }