/** @generated NOT */
  @Override
  public void initializeDefaultPreferences() {
    IPreferenceStore store = getPreferenceStore();

    PrintingPreferencePage.initDefaults(store);
    DiagramsPreferencePage.initDefaults(store);
    AppearancePreferencePage.initDefaults(store);
    ConnectionsPreferencePage.initDefaults(store);
    RulerGridPreferencePage.initDefaults(store);
    AudioDevicesPrefPage.initDefaults(store);
    AudioControlsPrefPage.initDefaults(store);
    store.setDefault(IPreferenceConstants.PREF_SHOW_POPUP_BARS, true);
    store.setDefault(IPreferenceConstants.PREF_SHOW_CONNECTION_HANDLES, true);
    store.setDefault(IPreferenceConstants.PREF_LINE_STYLE, Routing.RECTILINEAR);

    store.setDefault(IPreferenceConstants.PREF_SHOW_GRID, false);
    store.setDefault(IPreferenceConstants.PREF_SHOW_RULERS, false);
    store.setDefault(IPreferenceConstants.PREF_GRID_SPACING, 0.1);
    store.setDefault(IPreferenceConstants.PREF_RULER_UNITS, RulerProvider.UNIT_CENTIMETERS);
    store.setDefault(IPreferenceConstants.PREF_DEFAULT_FONT, "Tahoma");
    store.setDefault(IConstants.SQL_ASSIST, true);
    store.setDefault(IConstants.SQL_PARAMS, "5,150,5");
    store.setDefault(PreferenceConstants.PREF_ACTIONSTEPS_MINIMIZED, false);

    Preferences pref = UpdateSchedulerPlugin.getDefault().getPluginPreferences();
    pref.setDefault(UpdateSchedulerPlugin.P_ENABLED, true);
    pref.setDefault(UpdateSchedulerPlugin.P_SCHEDULE, UpdateSchedulerPlugin.VALUE_ON_STARTUP);
  }
  /**
   * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
   *
   * @throws Exception
   */
  public void testClassicPlugins() throws Exception {
    // extract the 3.0.2 skeleton
    IPath location = extractClassicPlugins();

    // the new way
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString());
    definition.setTargetLocations(new ITargetLocation[] {container});
    Set urls = getAllBundleURLs(definition);
    assertTrue("Must be bundles", urls.size() > 0);

    Preferences store = PDECore.getDefault().getPluginPreferences();
    boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
    try {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
      // the old way
      URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
      for (int i = 0; i < pluginPaths.length; i++) {
        URL url = pluginPaths[i];
        if (!urls.contains(url)) {
          System.err.println(url.toString());
        }
      }
      assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
    } finally {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
    }
  }
  protected void appendSpaceBefore(ICSSNode node, String toAppend, StringBuffer source) {
    if (node == null || source == null) return;
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
      return; // for not formatting case on cleanup action

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (toAppend != null
        && toAppend.startsWith("{")
        && preferences.getBoolean(
            CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) { // $NON-NLS-1$
      source.append(getLineDelimiter(node));
      source.append(getIndent(node));
      return;
    } else if (
    /* ! mgr.isOnePropertyPerLine() && */ preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0
        && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR)
            || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
      int n = getLastLineLength(node, source);
      int append =
          (toAppend != null)
              ? TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, toAppend, 0)[0]
              : 0;
      if (toAppend != null) append = (append < 0) ? toAppend.length() : append;
      if (n + append + 1 > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
        source.append(getLineDelimiter(node));
        source.append(getIndent(node));
        source.append(getIndentString());
        return;
      }
    }
    source.append(" "); // $NON-NLS-1$
  }
Esempio n. 4
0
 /**
  * Checks for changes to the PREF_AUTO_UPDATE property.
  *
  * @see Preferences.IPropertyChangeListener#propertyChange(Preferences.PropertyChangeEvent)
  */
 public void propertyChange(PropertyChangeEvent event) {
   String property = event.getProperty();
   if (ResourcesPlugin.PREF_AUTO_REFRESH.equals(property)) {
     Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
     boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH);
     manageAutoRefresh(autoRefresh);
   }
 }
Esempio n. 5
0
  /**
   * Initializes the refresh manager. This does a minimal amount of work if auto-refresh is turned
   * off.
   */
  public void startup(IProgressMonitor monitor) {
    Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
    preferences.addPropertyChangeListener(this);

    refreshJob = new RefreshJob();
    monitors = new MonitorManager(workspace, this);
    boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH);
    if (autoRefresh) manageAutoRefresh(autoRefresh);
  }
Esempio n. 6
0
 /**
  * Method createMISession.
  *
  * @param Process
  * @param PTY
  * @param type
  * @throws MIException
  * @return MISession
  * @deprecated
  */
 @Deprecated
 public MISession createMISession(
     MIProcess process, IMITTY pty, int type, String miVersion, IProgressMonitor monitor)
     throws MIException {
   MIPlugin miPlugin = getDefault();
   Preferences prefs = miPlugin.getPluginPreferences();
   int timeout = prefs.getInt(IMIConstants.PREF_REQUEST_TIMEOUT);
   int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
   return createMISession(process, pty, timeout, type, launchTimeout, miVersion, monitor);
 }
 private void upgradeVersion(String oldVersion) {
   if (oldVersion.length() == 0) {
     // only need to convert the build order if we are not using the default order
     if (!preferences.getBoolean(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER)) {
       String oldOrder = preferences.getString(ResourcesPlugin.PREF_BUILD_ORDER);
       setBuildOrder(convertStringToStringArray(oldOrder, ":")); // $NON-NLS-1$
     }
   }
   preferences.setValue(ICoreConstants.PREF_VERSION_KEY, ICoreConstants.PREF_VERSION);
 }
 protected void synchronizeWithPreferences(String property) {
   // do not use the value in the event - may be a string instead
   // of the expected type. Retrieve it from the preferences store
   // using the type-specific method
   if (property.equals(ResourcesPlugin.PREF_AUTO_BUILDING))
     super.setAutoBuilding(preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING));
   else if (property.equals(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL))
     super.setSnapshotInterval(preferences.getLong(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL));
   else if (property.equals(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS))
     super.setMaxBuildIterations(preferences.getInt(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS));
   else if (property.equals(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY))
     super.setApplyFileStatePolicy(
         preferences.getBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY));
   else if (property.equals(ResourcesPlugin.PREF_MAX_FILE_STATES))
     super.setMaxFileStates(preferences.getInt(ResourcesPlugin.PREF_MAX_FILE_STATES));
   else if (property.equals(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE))
     super.setMaxFileStateSize(preferences.getLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE));
   else if (property.equals(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY))
     super.setFileStateLongevity(preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
   else if (property.equals(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT))
     super.setOperationsPerSnapshot(
         preferences.getInt(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT));
   else if (property.equals(PreferenceInitializer.PREF_DELTA_EXPIRATION))
     super.setDeltaExpiration(preferences.getLong(PreferenceInitializer.PREF_DELTA_EXPIRATION));
 }
Esempio n. 9
0
  /**
   * Gets the object that manages the content assist information read from the Web-CAT server.
   *
   * @return the content assist manager
   */
  public ContentAssistManager getContentAssistManager() {
    if (contentAssistManager == null) {
      Preferences prefs = DesignerActivator.getDefault().getPluginPreferences();
      String url = prefs.getString(IPreferencesConstants.SERVER_URL_KEY);
      String username = prefs.getString(IPreferencesConstants.USERNAME_KEY);
      String password = prefs.getString(IPreferencesConstants.PASSWORD_KEY);

      contentAssistManager = new ContentAssistManager();
      contentAssistManager.setServerCredentials(url, username, password);
    }

    return contentAssistManager;
  }
Esempio n. 10
0
  public void dispose() {
    // remove all renderings
    fRenderings.clear();

    String secondaryId = getViewSiteSecondaryId();
    if (secondaryId != null) {
      // do not save renderings if this is not the primary rendering view
      String prefid = getPrefId();
      Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
      prefs.setToDefault(prefid);
    }

    DebugPlugin.getDefault().removeDebugEventListener(this);
  }
Esempio n. 11
0
 /**
  * Loads a history from an XML encoded preference value.
  *
  * @param preferences the preferences to retrieve the history from
  * @param key the key under which the history is stored
  * @return the deserialized history, or <code>null</code> if there is nothing stored under the
  *     given key
  * @throws CoreException if deserialization fails
  * @see #store(ContentAssistHistory, Preferences, String) on how to store a history such that it
  *     can be read by this method
  */
 public static ContentAssistHistory load(Preferences preferences, String key)
     throws CoreException {
   String value = preferences.getString(key);
   if (value != null && value.length() > 0) {
     return new ReaderWriter().load(new InputSource(new StringReader(value)));
   }
   return null;
 }
Esempio n. 12
0
 /** {@inheritDoc} */
 public void putValue(String name, String value) {
   try {
     fSilent = true;
     fPreferences.setValue(name, value);
   } finally {
     fSilent = false;
   }
 }
Esempio n. 13
0
  /**
   * Store renderings as preferences. If renderings are stored, renderings can be persisted even
   * after the memory view is closed.
   */
  private void storeRenderings() {
    Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
    String renderingsStr = IInternalDebugCoreConstants.EMPTY_STRING;
    try {
      renderingsStr = getRenderingsAsXML();
    } catch (IOException e) {
      DebugUIPlugin.log(e);
    } catch (ParserConfigurationException e) {
      DebugUIPlugin.log(e);
    } catch (TransformerException e) {
      DebugUIPlugin.log(e);
    }

    String prefid = getPrefId();

    if (renderingsStr != null) prefs.setValue(prefid, renderingsStr);
    else prefs.setToDefault(prefid);
  }
  private String getIndentString() {
    StringBuffer indent = new StringBuffer();

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (preferences != null) {
      char indentChar = ' ';
      String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
      if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
        indentChar = '\t';
      }
      int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);

      for (int i = 0; i < indentationWidth; i++) {
        indent.append(indentChar);
      }
    }
    return indent.toString();
  }
  public void loadKnownHosts() {
    Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
    String ssh_home = preferences.getString(IConstants.KEY_SSH2HOME);

    if (ssh_home.length() == 0) ssh_home = PreferenceInitializer.SSH_HOME_DEFAULT;

    java.io.File file = new java.io.File(ssh_home, "known_hosts"); // $NON-NLS-1$
    try {
      getJSch().setKnownHosts(file.getPath());
    } catch (JSchException e) {
      JSchCorePlugin.log(
          IStatus.ERROR,
          NLS.bind(
              "An error occurred while loading the know hosts file {0}",
              file //$NON-NLS-1$
                  .getAbsolutePath()),
          e);
    }
    needToLoadKnownHosts = false;
  }
  /**
   * Tests that a bundle directory container is equivalent to scanning locations when it uses a
   * variable to specify its location.
   *
   * @throws Exception
   */
  public void testVariableDirectoryBundleContainer() throws Exception {
    // the new way
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container = getTargetService().newDirectoryLocation("${eclipse_home}/plugins");
    definition.setTargetLocations(new ITargetLocation[] {container});
    Set urls = getAllBundleURLs(definition);

    Preferences store = PDECore.getDefault().getPluginPreferences();
    boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
    try {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
      // the old way
      URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
      assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
      for (int i = 0; i < pluginPaths.length; i++) {
        URL url = pluginPaths[i];
        assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
      }
    } finally {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
    }
  }
  protected String decoratedPropNameRegion(CompoundRegion region, CSSCleanupStrategy stgy) {
    if (isFormat()) return region.getText();

    String text = null;
    if (!stgy.isFormatSource()) text = region.getFullText();
    else text = region.getText();

    if (region.getType() == CSSRegionContexts.CSS_STRING
        || region.getType() == CSSRegionContexts.CSS_URI) return decoratedRegion(region, 1, stgy);
    if (isCleanup()) {
      if (stgy.getPropNameCase() == CSSCleanupStrategy.ASIS
          || region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY) return text;
      else if (stgy.getPropNameCase() == CSSCleanupStrategy.UPPER) return text.toUpperCase();
      else return text.toLowerCase();
    }
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();

    if (region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY) return text;
    else if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME)
        == CSSCorePreferenceNames.UPPER) return text.toUpperCase();
    else return text.toLowerCase();
  }
Esempio n. 18
0
  /**
   * Gets the in-memory cache that stores the results of a preview query operation.
   *
   * @return the previewing result cache
   */
  public PreviewingResultCache getPreviewCache() {
    if (previewCache == null) {
      Preferences prefs = DesignerActivator.getDefault().getPluginPreferences();

      // Try to construct a previewing result set provider based on the
      // current preferences settings.
      String url = prefs.getString(IPreferencesConstants.SERVER_URL_KEY);
      String username = prefs.getString(IPreferencesConstants.USERNAME_KEY);
      String password = prefs.getString(IPreferencesConstants.PASSWORD_KEY);
      int maxRecords = 0;
      int timeout = 0;

      try {
        maxRecords = Integer.parseInt(prefs.getString(IPreferencesConstants.MAX_RECORDS_KEY));

        timeout = Integer.parseInt(prefs.getString(IPreferencesConstants.CONNECTION_TIMEOUT_KEY));
      } catch (NumberFormatException e) {
        // Do nothing; keep default value of 0.
      }

      if (url == null || url.trim().length() == 0) {
        MessageBox box =
            new MessageBox(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                SWT.OK | SWT.ICON_WARNING);

        box.setMessage(Messages.ACTIVATOR_SERVER_URL_NOT_SET);
        box.open();
      } else {
        previewCache = new PreviewingResultCache();
        previewCache.setServerCredentials(url, username, password);
        previewCache.setMaxRecords(maxRecords);
        previewCache.setTimeout(timeout);
      }
    }

    return previewCache;
  }
  protected String decoratedIdentRegion(CompoundRegion region, CSSCleanupStrategy stgy) {
    if (isFormat()) return region.getText();

    String text = null;
    if (!stgy.isFormatSource()) text = region.getFullText();
    else text = region.getText();

    if (region.getType() == CSSRegionContexts.CSS_STRING
        || region.getType() == CSSRegionContexts.CSS_URI) return decoratedRegion(region, 0, stgy);

    if (isCleanup()) {
      if (stgy.getIdentCase() == CSSCleanupStrategy.ASIS
          || region.getType() == CSSRegionContexts.CSS_COMMENT) return text;
      else if (stgy.getIdentCase() == CSSCleanupStrategy.UPPER) return text.toUpperCase();
      else return text.toLowerCase();
    }

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (region.getType() == CSSRegionContexts.CSS_COMMENT) return text;
    else if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER)
        == CSSCorePreferenceNames.UPPER) return text.toUpperCase();
    else return text.toLowerCase();
  }
  public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
    Vector vector = new Vector();

    // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference
    Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences();
    int indentationWidth = preferences.getInt(HTMLCorePreferenceNames.INDENTATION_SIZE);
    String indentCharPref = preferences.getString(HTMLCorePreferenceNames.INDENTATION_CHAR);
    boolean useSpaces = HTMLCorePreferenceNames.SPACE.equals(indentCharPref);

    for (int i = 0; i <= indentationWidth; i++) {
      StringBuffer prefix = new StringBuffer();
      boolean appendTab = false;

      if (useSpaces) {
        for (int j = 0; j + i < indentationWidth; j++) prefix.append(' ');

        if (i != 0) appendTab = true;
      } else {
        for (int j = 0; j < i; j++) prefix.append(' ');

        if (i != indentationWidth) appendTab = true;
      }

      if (appendTab) {
        prefix.append('\t');
        vector.add(prefix.toString());
        // remove the tab so that indentation - tab is also an indent
        // prefix
        prefix.deleteCharAt(prefix.length() - 1);
      }
      vector.add(prefix.toString());
    }

    vector.add(""); // $NON-NLS-1$

    return (String[]) vector.toArray(new String[vector.size()]);
  }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#setMaxFileStates(int) */
 public void setMaxFileStates(int number) {
   preferences.setValue(ResourcesPlugin.PREF_MAX_FILE_STATES, number);
 }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#setMaxBuildIterations(int) */
 public void setMaxBuildIterations(int number) {
   preferences.setValue(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS, number);
 }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#setFileStateLongevity(long) */
 public void setFileStateLongevity(long time) {
   preferences.setValue(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY, time);
 }
Esempio n. 24
0
 /** Read preferences */
 protected void readPreferences() {
   Preferences pref = CommonPlugin.getDefault().getPluginPreferences();
   forceEcho = pref.getBoolean(IDs.P_ECHO_FORCE);
 }
/**
 * qzhang class global comment. Detailled comment <br>
 * $Id: talend-code-templates.xml 1 2007-2-9 下午01:06:55 (星期五, 29 九月 2006) qzhang $
 */
public class GUIModificationQueryAction extends AbstractEditorAction {

  private Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();

  private String queryDelimiter = prefs.getString(IConstants.QUERY_DELIMITER);

  private String alternateDelimiter = prefs.getString(IConstants.ALTERNATE_DELIMITER);

  private String commentDelimiter = prefs.getString(IConstants.COMMENT_DELIMITER);

  private RepositoryNode currentNode;

  private ISQLBuilderDialog dialog;

  private ImageDescriptor image = ImageUtil.getDescriptor("Images.OpenSQLIcon"); // $NON-NLS-1$

  private String currentSql;

  private boolean isDesigner;

  /** qzhang GUIModificationQuery constructor comment. */
  public GUIModificationQueryAction(
      RepositoryNode node, ConnectionParameters parameters, ISQLBuilderDialog dialog) {
    this.currentNode = node;
    this.dialog = dialog;
  }

  /*
   * (non-Javadoc)
   *
   * @see org.talend.sqlbuilder.actions.AbstractEditorAction#getToolTipText()
   */
  @Override
  public String getToolTipText() {
    if (isDesigner) {
      return Messages.getString("GUIModificationQueryAction.TextDialog.TitleText"); // $NON-NLS-1$
    }
    return Messages.getString("GUIModificationQueryAction.ButtonText"); // $NON-NLS-1$
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.action.Action#getImageDescriptor()
   */
  @Override
  public ImageDescriptor getImageDescriptor() {
    return image;
  }

  /*
   * (non-Java)
   *
   * @see org.talend.sqlbuilder.actions.AbstractEditorAction#getText()
   */
  @Override
  public String getText() {
    if (isDesigner) {
      return Messages.getString("GUIModificationQueryAction.TextDialog.TitleText"); // $NON-NLS-1$
    }
    return Messages.getString("GUIModificationQueryAction.ButtonText"); // $NON-NLS-1$
  }

  /*
   * (non-Java)
   *
   * @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
   */
  @Override
  public void run() {
    currentSql = getEditor().getSQLToBeExecuted();
    // QueryTokenizer qt = new QueryTokenizer(currentSql, queryDelimiter, alternateDelimiter,
    // commentDelimiter);
    // List<String> queryStrings = new ArrayList<String>();
    // while (qt.hasQuery()) {
    // String querySql = qt.nextQuery();
    // // ignore commented lines.
    // if (!querySql.startsWith("--")) { //$NON-NLS-1$
    // queryStrings.add(querySql);
    // }
    // }
    // if (queryStrings.size() < 1) {
    // MessageDialog.openError(new Shell(), "Notice", "You must input one Sql Statement!");
    // return;
    // }
    // if (queryStrings.size() > 1) {
    // isForce = MessageDialog.openQuestion(new Shell(), "Notice",
    // "You only modify first Sql Statement by GUI, Would you like to continue?");
    // }
    // String string = queryStrings.get(0).toLowerCase().replaceAll("\n", " ");
    // string.replaceAll("\t", " ");
    // if (!string.startsWith("select ")) {
    // MessageDialog.openError(new Shell(), "Notice", "GUI Sql Editor only use for 'select'
    // Statement !");
    // return;
    // }
    // if (isForce != null && !isForce.booleanValue()) {
    // return;
    // }
    if (dialog instanceof SQLBuilderDialog) {
      SQLBuilderDialog d = (SQLBuilderDialog) dialog;
      final CTabItem selection = d.getEditorComposite().getTabFolder().getSelection();
      if (selection.getData("KEY") instanceof MultiPageSqlBuilderEditor) { // $NON-NLS-1$
        MultiPageSqlBuilderEditor editor =
            (MultiPageSqlBuilderEditor) selection.getData("KEY"); // $NON-NLS-1$
        switch (editor.getActivePage()) {
          case 1:
            isDesigner = true;
            break;
          default:
            isDesigner = false;
            break;
        }
      }
    }

    String query = null;
    if (isDesigner) {
      SqlEditDialog textDialog =
          new SqlEditDialog(
              dialog.getShell(),
              Messages.getString("GUIModificationQueryAction.TextDialog.TitleText"),
              currentSql,
              currentNode); //$NON-NLS-1$
      if (Window.OK == textDialog.open()) {
        query = textDialog.getSql();
      }
    } else {
      List<IRepositoryNode> selectedNodes = null;
      try {
        selectedNodes =
            EMFRepositoryNodeManager.getInstance().parseSqlStatement(currentSql, currentNode);
      } catch (Exception e) {
        MessageDialog.openError(
            new Shell(),
            Messages.getString("GUIModificationQueryAction.Error.Notice"),
            Messages.getString(
                "GUIModificationQueryAction.SqlStatement.ErrorMsg")); //$NON-NLS-1$ //$NON-NLS-2$
      }
      if (selectedNodes == null) {
        return;
      }

      // String info = Messages.getString("MultiPageSqlBuilderEditor.Notice.InformationNotFull");
      // MessageDialog.openInformation(new Shell(),
      // Messages.getString("GUIModificationQueryAction.Information.Msg"), info); //$NON-NLS-1$

      ErDiagramDialog erDiagramDialog =
          new ErDiagramDialog(
              dialog.getShell(),
              Messages.getString("GUIModificationQueryAction.Dialog.TitleText"),
              currentNode); //$NON-NLS-1$
      erDiagramDialog.setDialog(dialog);
      erDiagramDialog.setNodes(selectedNodes);
      erDiagramDialog.setSqlText(currentSql);
      EMFRepositoryNodeManager.getInstance().setRoot(currentNode);
      if (Window.OK == erDiagramDialog.open()) {
        query = erDiagramDialog.getSql();
      }
    }
    if (query == null) {
      return;
    }
    if (!query.endsWith(";\n") && !query.endsWith(";")) { // $NON-NLS-1$ //$NON-NLS-2$
      query += ";\n"; // $NON-NLS-1$
    }
    String targetSql = ""; // $NON-NLS-1$
    boolean isfirst = true;
    QueryTokenizer qt =
        new QueryTokenizer(currentSql, queryDelimiter, alternateDelimiter, commentDelimiter);
    while (qt.hasQuery()) {
      String querySql = qt.nextQuery();
      if (querySql.startsWith("--") || !isfirst) { // $NON-NLS-1$
        targetSql += querySql + ";\n"; // $NON-NLS-1$
      } else {
        targetSql += query;
        isfirst = false;
      }
    }
    if (!qt.hasQuery()) {
      targetSql = query;
    }
    // currentSql = currentSql.replaceFirst(queryStrings.get(0), query);
    getEditor().setEditorContent(targetSql);
  }

  public void setCurrentNode(RepositoryNode currentNode) {
    this.currentNode = currentNode;
  }
}
Esempio n. 26
0
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  @Override
  public boolean step(STEMTime time, long timeDelta, int cycle) {

    // Validate all decorators that return deltas to make sure
    // they are of deterministic nature. The Runge Kutta integratio
    // can only handle determininistic variants

    for (Decorator decorator : this.getDecorators())
      if (decorator instanceof IntegrationDecorator) {
        IntegrationDecorator idec = (IntegrationDecorator) decorator;
        if (!idec.isDeterministic()) {
          Activator.logError(
              "Error, decorator: "
                  + idec
                  + " is not deterministic. The Runge Kutta Integrator can only handle deterministic models.",
              new Exception());
          return false;
        }
      }

    Activator act = org.eclipse.stem.ui.Activator.getDefault();
    if (act != null) {
      final Preferences preferences = act.getPluginPreferences();
      num_threads =
          (short)
              preferences.getInt(
                  org.eclipse.stem.ui.preferences.PreferenceConstants.SIMULATION_THREADS);
    } else num_threads = 2; // Just so we can run inside junit test

    final int c = cycle;

    // Initialize latches
    stepSizeBarrier =
        new CyclicBarrier(
            num_threads,
            new Runnable() {
              public void run() {
                // All threads successfully advanced time by some step h.
                // Find the smallest
                smallestH = Double.MAX_VALUE;
                maximumError = -Double.MAX_VALUE;
                for (int i = 0; i < num_threads; ++i) {
                  if (jobs[i].h <= smallestH) {
                    if (maximumError < jobs[i].maxerror) maximumError = jobs[i].maxerror;
                    smallestH = jobs[i].h;
                  }
                }
              }
            });

    updateDoneBarrier = new CyclicBarrier(num_threads);

    // Find triggers and make sure they are invoked
    for (Decorator decorator : this.getDecorators()) {
      if (decorator instanceof Trigger) {
        decorator.updateLabels(time, timeDelta, cycle);
      }
    }

    // First initialize the probe and temp label values from the current
    // label values.

    for (Decorator decorator : this.getDecorators()) {
      EList<DynamicLabel> allLabels = decorator.getLabelsToUpdate();
      for (final Iterator<DynamicLabel> currentStateLabelIter = allLabels.iterator();
          currentStateLabelIter.hasNext(); ) {
        if (decorator instanceof IntegrationDecorator) {
          // It's a standard disease model with a standard disease model label
          final IntegrationLabel iLabel = (IntegrationLabel) currentStateLabelIter.next();
          ((IntegrationLabelValue) iLabel.getProbeValue())
              .set((IntegrationLabelValue) iLabel.getCurrentValue());
          ((IntegrationLabelValue) iLabel.getTempValue())
              .set((IntegrationLabelValue) iLabel.getCurrentValue());
          ((IntegrationLabelValue) iLabel.getTempValue()).prepareCycle();
          ((IntegrationLabelValue) iLabel.getProbeValue()).prepareCycle();
        } else currentStateLabelIter.next();
      }
    }

    if (jobs == null || jobs.length != num_threads) {
      // Initialize the jobs if not done yet or of the number of threads changes
      jobs = new RkJob[num_threads];

      for (short i = 0; i < num_threads; ++i) {
        final short threadnum = i;
        jobs[i] = new RkJob("Worker " + i, threadnum, this);
      } // For each job
    } // If not initialized

    // Initialize
    int thread = 0;
    for (RkJob j : jobs) {
      j.cycle = c;
      j.time = time;
      j.timeDelta = timeDelta;
    }
    // Schedule. Jobs can be rescheduled after finished
    for (RkJob j : jobs) j.schedule();

    // Wait until all jobs completed
    for (RkJob j : jobs) {
      try {
        j.join();
      } catch (InterruptedException ie) {
        Activator.logError(ie.getMessage(), ie);
      }
    }

    // Set the common time and step size here and validate everything is right
    double minStep = Double.MAX_VALUE;
    double currentT = jobs[0].t;
    for (RkJob j : jobs) {
      // The jobs have calculated new step sizes after they finished. Pick the
      // smallest one for the next cycle
      if (j.h < minStep) minStep = j.h;
      if (j.t != currentT)
        Activator.logError(
            "Error, one thread was in misstep with other threads, its time was "
                + j.t
                + " versus "
                + currentT,
            new Exception());
    }
    return true;
  }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#setMaxFileStateSize(long) */
 public void setMaxFileStateSize(long size) {
   preferences.setValue(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE, size);
 }
 public void setOperationsPerSnapshot(int value) {
   preferences.setValue(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT, value);
 }
  public WorkspacePreferences() {
    super("Workspace"); // $NON-NLS-1$
    this.preferences = ResourcesPlugin.getPlugin().getPluginPreferences();

    final String version = preferences.getString(ICoreConstants.PREF_VERSION_KEY);
    if (!ICoreConstants.PREF_VERSION.equals(version)) upgradeVersion(version);

    // initialize cached preferences (for better performance)
    super.setAutoBuilding(preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING));
    super.setSnapshotInterval(preferences.getInt(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL));
    super.setMaxBuildIterations(preferences.getInt(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS));
    super.setApplyFileStatePolicy(
        preferences.getBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY));
    super.setMaxFileStates(preferences.getInt(ResourcesPlugin.PREF_MAX_FILE_STATES));
    super.setMaxFileStateSize(preferences.getLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE));
    super.setFileStateLongevity(preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
    super.setOperationsPerSnapshot(
        preferences.getInt(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT));
    super.setDeltaExpiration(preferences.getLong(PreferenceInitializer.PREF_DELTA_EXPIRATION));

    // This property listener ensures we are being updated properly when changes
    // are done directly to the preference store.
    preferences.addPropertyChangeListener(
        new Preferences.IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            synchronizeWithPreferences(event.getProperty());
          }
        });
  }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#setSnapshotInterval(long) */
 public void setSnapshotInterval(long delay) {
   preferences.setValue(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL, delay);
 }