static {
   if (Platform.OS_MACOSX.equals(Platform.getOS())) {
     MODIFIER_NO_SNAPPING = SWT.CTRL;
   } else {
     MODIFIER_NO_SNAPPING = SWT.ALT;
   }
 }
 public void run(IAction action) {
   final TransformToGenModelWizard wiz = new TransformToGenModelWizard();
   wiz.setWindowTitle(action.getText());
   wiz.init(PlatformUI.getWorkbench(), sselection);
   WizardDialog wd = new WizardDialog(getShell(), wiz);
   wd.create();
   Rectangle mb = getShell().getMonitor().getClientArea();
   Point dpi = getShell().getDisplay().getDPI();
   if (Platform.OS_MACOSX.equals(Platform.getOS())) {
     dpi =
         new Point(110, 110); // OSX DPI is always 72; 110 is a common value for modern LCD screens
   }
   int width = dpi.x * WIZARD_WIDTH_INCH;
   int height = dpi.y * WIZARD_HEIGHT_INCH;
   int x = mb.x + (mb.width - width) / 2;
   if (x < mb.x) {
     x = mb.x;
   }
   int y = mb.y + (mb.height - height) / 2;
   if (y < mb.y) {
     y = mb.y;
   }
   wd.getShell().setLocation(x, y);
   wd.getShell().setSize(width, height);
   wd.open();
 }
  private void internalSetAuthCredentials(
      ICredentials credentials, URI link, String realm, boolean persist)
      throws CredentialsException {

    /* Store Credentials in In-Memory Store */
    if (!persist) {
      fInMemoryStore.put(toCacheKey(link, realm), credentials);
    }

    /* Store Credentials in secure Storage */
    else {
      ISecurePreferences securePreferences = getSecurePreferences();

      /* Check if Bundle is Stopped */
      if (securePreferences == null) return;

      /* Store in Equinox Security Storage */
      ISecurePreferences allFeedsPreferences = securePreferences.node(SECURE_FEED_NODE);
      ISecurePreferences feedPreferences =
          allFeedsPreferences.node(EncodingUtils.encodeSlashes(link.toString()));
      ISecurePreferences realmPreference =
          feedPreferences.node(EncodingUtils.encodeSlashes(realm != null ? realm : REALM));

      IPreferenceScope globalScope = Owl.getPreferenceService().getGlobalScope();

      /* OS Password is only supported on Windows and Mac */
      boolean useOSPassword = globalScope.getBoolean(DefaultPreferences.USE_OS_PASSWORD);
      if (!Platform.OS_WIN32.equals(Platform.getOS())
          && !Platform.OS_MACOSX.equals(Platform.getOS())) useOSPassword = false;

      boolean encryptPW =
          useOSPassword || globalScope.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD);
      try {
        if (credentials.getUsername() != null)
          realmPreference.put(USERNAME, credentials.getUsername(), encryptPW);

        if (credentials.getPassword() != null)
          realmPreference.put(PASSWORD, credentials.getPassword(), encryptPW);

        if (credentials.getDomain() != null)
          realmPreference.put(DOMAIN, credentials.getDomain(), encryptPW);

        realmPreference.flush(); // Flush to disk early
      } catch (StorageException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      } catch (IOException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      }
    }

    /* Uncache */
    removeUnprotected(link, realm);
  }
 public String getCompleteProgramArguments(String os) {
   if (Platform.OS_WIN32.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_WIN32), fProgramArgs);
   } else if (Platform.OS_LINUX.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_LINUX), fProgramArgs);
   } else if (Platform.OS_MACOSX.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_MACOS), fProgramArgs);
   } else if (Platform.OS_SOLARIS.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_SOLAR), fProgramArgs);
   } else {
     return getProgramArguments(L_ARGS_ALL);
   }
 }
  private ISecurePreferences getSecurePreferences() {
    if (!InternalOwl.IS_ECLIPSE) {
      IPreferenceScope prefs = Owl.getPreferenceService().getGlobalScope();
      boolean useOSPasswordProvider = prefs.getBoolean(DefaultPreferences.USE_OS_PASSWORD);

      /* Disable OS Password if Master Password shall be used */
      if (prefs.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD)) useOSPasswordProvider = false;

      /* Try storing credentials in profile folder */
      try {
        Activator activator = Activator.getDefault();

        /* Check if Bundle is Stopped */
        if (activator == null) return null;

        IPath stateLocation = activator.getStateLocation();
        stateLocation = stateLocation.append(SECURE_STORAGE_FILE);
        URL location = stateLocation.toFile().toURL();
        Map<String, String> options = null;

        /* Use OS dependent password provider if available */
        if (useOSPasswordProvider) {
          if (Platform.OS_WIN32.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, WIN_PW_PROVIDER_ID);
          } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, MACOS_PW_PROVIDER_ID);
          }
        }

        /* Use RSSOwl password provider */
        else {
          options = new HashMap<String, String>();
          options.put(IProviderHints.REQUIRED_MODULE_ID, RSSOWL_PW_PROVIDER_ID);
        }

        return SecurePreferencesFactory.open(location, options);
      } catch (MalformedURLException e) {
        Activator.safeLogError(e.getMessage(), e);
      } catch (IllegalStateException e1) {
        Activator.safeLogError(e1.getMessage(), e1);
      } catch (IOException e2) {
        Activator.safeLogError(e2.getMessage(), e2);
      }
    }

    /* Fallback to default location */
    return SecurePreferencesFactory.getDefault();
  }
 public static void explore(String name) {
   File file = new File(name);
   String command = null;
   if (file.isFile()) {
     command = getExploreFileCommand();
   } else {
     command = getExploreCommand();
   }
   if (command != null) {
     if (Platform.getOS().equals(Platform.OS_WIN32)) {
       name = name.replace('/', '\\');
     }
     try {
       if (Platform.OS_LINUX.equals(Platform.getOS())
           || Platform.OS_MACOSX.equals(Platform.getOS())) {
         int len = exploreFolderCommandArray.length;
         String name2 = file.isFile() ? new Path(name).removeLastSegments(1).toString() : name;
         exploreFolderCommandArray[len - 1] = name2;
         Runtime.getRuntime().exec(exploreFolderCommandArray);
       } else if (Platform.getOS().equals(Platform.OS_WIN32)) {
         if (file.isDirectory()) {
           int len = exploreFolderCommandArray.length;
           exploreFolderCommandArray[len - 1] = "\"" + name + "\""; // $NON-NLS-1$ //$NON-NLS-2$
           Runtime.getRuntime().exec(exploreFolderCommandArray);
         } else {
           int len = exploreFileCommandArray.length;
           exploreFileCommandArray[len - 1] = "\"" + name + "\""; // $NON-NLS-1$ //$NON-NLS-2$
           Runtime.getRuntime().exec(exploreFileCommandArray);
         }
       } else {
         command = command.replace(ExploreUtils.PATH, name);
         if (JBossServerUIPlugin.getDefault().isDebugging()) {
           IStatus status =
               new Status(
                   IStatus.WARNING,
                   JBossServerUIPlugin.PLUGIN_ID,
                   "command=" + command,
                   null); //$NON-NLS-1$
           JBossServerUIPlugin.getDefault().getLog().log(status);
         }
         Runtime.getRuntime().exec(command);
       }
     } catch (IOException e) {
       JBossServerUIPlugin.log(e.getMessage(), e);
     }
   }
 }
  private static void setExploreCommands() {
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      exploreFolderCommandArray =
          new String[] {
            "/usr/bin/open", "-a", "/System/Library/CoreServices/Finder.app", ""
          }; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
      exploreFolderCommand = ""; // $NON-NLS-1$
    } else if (Platform.OS_WIN32.equals(Platform.getOS())) {
      exploreFolderCommandArray = new String[5];
      exploreFolderCommandArray[0] = "cmd"; // $NON-NLS-1$
      exploreFolderCommandArray[1] = "/C"; // $NON-NLS-1$
      exploreFolderCommandArray[2] = "start"; // $NON-NLS-1$
      exploreFolderCommandArray[3] = "explorer"; // $NON-NLS-1$

      exploreFileCommandArray = new String[6];
      exploreFileCommandArray[0] = "cmd"; // $NON-NLS-1$
      exploreFileCommandArray[1] = "/C"; // $NON-NLS-1$
      exploreFileCommandArray[2] = "start"; // $NON-NLS-1$
      exploreFileCommandArray[3] = "explorer"; // $NON-NLS-1$
      exploreFileCommandArray[4] = "/select,"; // $NON-NLS-1$

      exploreFolderCommand =
          "cmd /C start explorer \"" //$NON-NLS-1$
              + PATH
              + "\""; //$NON-NLS-1$
      exploreFileCommand =
          "cmd /C start explorer /select,\"" //$NON-NLS-1$
              + PATH
              + "\""; //$NON-NLS-1$
    } else if (Platform.OS_LINUX.equals(Platform.getOS())) {

      if (new File("/usr/bin/nautilus").exists()) { // $NON-NLS-1$
        exploreFolderCommandArray = new String[3];
        exploreFolderCommandArray[0] = "/usr/bin/nautilus"; // $NON-NLS-1$
        exploreFolderCommandArray[1] = "--no-desktop"; // $NON-NLS-1$
        exploreFolderCommand = ""; // $NON-NLS-1$
      } else if (new File("/usr/bin/konqueror").exists()) { // $NON-NLS-1$
        exploreFolderCommandArray = new String[2];
        exploreFolderCommandArray[0] = "/usr/bin/konqueror"; // $NON-NLS-1$
        exploreFolderCommand = ""; // $NON-NLS-1$
      }
      exploreFileCommand = exploreFolderCommand;
    }
  }
Exemple #8
0
 public static ImageCapture getImageCapture() {
   if (instance == null) {
     if (Platform.OS_WIN32.equals(Platform.getOS())) instance = new Win32ImageCapture();
     else if (Platform.WS_GTK.equals(Platform.getWS())) {
       if (Platform.ARCH_IA64.equals(Platform.getOSArch())
           || Platform.ARCH_X86_64.equals(Platform.getOSArch()))
         instance = new org.eclipse.ve.internal.swt.targetvm.unix.bits64.ImageCapture();
       else instance = new org.eclipse.ve.internal.swt.targetvm.unix.ImageCapture();
     } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
       if (Platform.WS_COCOA.equals(Platform.getWS())) {
         instance = new org.eclipse.ve.internal.swt.targetvm.macosx.cocoa.ImageCapture();
       } else if (Platform.WS_CARBON.equals(Platform.getWS())) {
         instance = new org.eclipse.ve.internal.swt.targetvm.macosx.ImageCapture();
       } else {
         throw new UnsupportedOperationException(Platform.getOS());
       }
     } else {
       throw new UnsupportedOperationException(Platform.getOS());
     }
   }
   return instance;
 }
Exemple #9
0
  private static OS create() {
    String os = Platform.getOS();
    String ws = Platform.getWS();
    String arch = Platform.getOSArch();

    if (Platform.OS_WIN32.equals(os)) {
      if (Platform.ARCH_X86_64.equals(arch)) {
        return new Win64(ws);
      }

      return new Win32(ws, arch);
    }

    if (Platform.OS_MACOSX.equals(os)) {
      return new Mac(ws, arch);
    }

    if (Platform.OS_LINUX.equals(os)) {
      return new Linux(ws, arch);
    }

    throw new IllegalStateException("Operating system not supported: " + os);
  }
  @Test
  public void testDeleteTags() throws Exception {
    // TODO Remove once bug355200 has been fixed
    if (Platform.OS_MACOSX.equals(Platform.getOS())) return;

    SWTBotTree tree = getOrOpenView().bot().tree();
    int initialCount = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand().rowCount();

    createTag("Delete2", "The first tag");
    createTag("Delete3", "The second tag");
    refreshAndWait();
    SWTBotTreeItem tagsItem = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand();
    SWTBotTreeItem[] items = tagsItem.getItems();
    assertEquals("Wrong number of tags", initialCount + 2, items.length);
    tagsItem.select("Delete2", "Delete3");
    ContextMenuHelper.clickContextMenu(
        tree, myUtil.getPluginLocalizedValue("DeleteTagCommand.name"));
    bot.shell(UIText.DeleteTagCommand_titleConfirm).bot().button(IDialogConstants.OK_LABEL).click();
    TestUtil.joinJobs(JobFamilies.TAG);
    refreshAndWait();
    tagsItem = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand();
    items = tagsItem.getItems();
    assertEquals("Wrong number of tags", initialCount, items.length);
  }
 public static boolean isMac() {
   return Platform.OS_MACOSX.equals(Platform.getOS());
 }
  private Browser createSWTBrowser(Composite parent) {
    try {
      if (System.getProperty(XULRUNNER_ENV) == null) {
        Bundle bundle = null;
        if (CoreUIUtils.onWindows) {
          bundle = Platform.getBundle(XULRUNNER_WIN32_PLUGIN);
        } else if (CoreUIUtils.onMacOSX) {
          bundle = Platform.getBundle(XULRUNNER_MAC_PLUGIN);
        }
        if (bundle != null) {
          URL xulrunner = bundle.getEntry(XULRUNNER_PATH);
          if (xulrunner != null) {
            try {
              xulrunner = FileLocator.toFileURL(xulrunner);
              if (xulrunner != null) {
                File xulrunnerFolder = new File(xulrunner.getFile());
                String message =
                    MessageFormat.format(
                        Messages.getString("FirefoxBrowser.Setting_Path_To"), // $NON-NLS-1$
                        new Object[] {xulrunnerFolder.getAbsolutePath()});
                System.setProperty(XULRUNNER_ENV, xulrunnerFolder.getAbsolutePath());
                IdeLog.logInfo(Activator.getDefault(), message);
              }
            } catch (IOException e) {
              IdeLog.logError(
                  Activator.getDefault(),
                  Messages.getString("FirefoxBrowser.Error_Setting_Path"),
                  e); //$NON-NLS-1$
            }
          }
        }
      }
    } catch (Exception e) {
      IdeLog.logError(
          Activator.getDefault(),
          Messages.getString("FirefoxBrowser.Error_Setting_Path"),
          e); //$NON-NLS-1$
    }

    browser = new Browser(parent, SWT.MOZILLA);
    browser.addProgressListener(progressListener);
    browser.addOpenWindowListener(openWindowListener);

    // Disable Java
    nsIPrefService prefService =
        (nsIPrefService)
            Mozilla.getInstance()
                .getServiceManager()
                .getServiceByContractID(
                    "@mozilla.org/preferences-service;1",
                    nsIPrefService.NS_IPREFSERVICE_IID); // $NON-NLS-1$
    nsIPrefBranch prefBranch = prefService.getBranch(""); // $NON-NLS-1$
    prefBranch.setBoolPref("security.enable_java", 0); // $NON-NLS-1$

    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      nsIWebBrowserSetup webBrowserSetup =
          (nsIWebBrowserSetup)
              internalGetWebBrowser().queryInterface(nsIWebBrowserSetup.NS_IWEBBROWSERSETUP_IID);
      if (webBrowserSetup != null) {
        webBrowserSetup.setProperty(nsIWebBrowserSetup.SETUP_ALLOW_PLUGINS, 0);
      }
    }
    return browser;
  }
  /** Search for installed VMs in the file system */
  protected void search() {
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      doMacSearch();
      return;
    }
    // choose a root directory for the search
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(JREMessages.InstalledJREsBlock_9);
    dialog.setText(JREMessages.InstalledJREsBlock_10);
    String path = dialog.open();
    if (path == null) {
      return;
    }

    // ignore installed locations
    final Set<File> exstingLocations = new HashSet<File>();
    for (IVMInstall vm : fVMs) {
      exstingLocations.add(vm.getInstallLocation());
    }

    // search
    final File rootDir = new File(path);
    final List<File> locations = new ArrayList<File>();
    final List<IVMInstallType> types = new ArrayList<IVMInstallType>();

    IRunnableWithProgress r =
        new IRunnableWithProgress() {
          @Override
          public void run(IProgressMonitor monitor) {
            monitor.beginTask(JREMessages.InstalledJREsBlock_11, IProgressMonitor.UNKNOWN);
            search(rootDir, locations, types, exstingLocations, monitor);
            monitor.done();
          }
        };

    try {
      ProgressMonitorDialog progress =
          new ProgressMonitorDialog(getShell()) {
            /*
             * Overridden createCancelButton to replace Cancel label with Stop label
             * More accurately reflects action taken when button pressed.
             * Bug [162902]
             */
            @Override
            protected void createCancelButton(Composite parent) {
              cancel =
                  createButton(
                      parent, IDialogConstants.CANCEL_ID, IDialogConstants.STOP_LABEL, true);
              if (arrowCursor == null) {
                arrowCursor = new Cursor(cancel.getDisplay(), SWT.CURSOR_ARROW);
              }
              cancel.setCursor(arrowCursor);
              setOperationCancelButtonEnabled(enableCancelButton);
            }
          };
      progress.run(true, true, r);
    } catch (InvocationTargetException e) {
      JDIDebugUIPlugin.log(e);
    } catch (InterruptedException e) {
      // canceled
      return;
    }

    if (locations.isEmpty()) {
      String messagePath = path.replaceAll("&", "&&"); // @see bug 29855  //$NON-NLS-1$//$NON-NLS-2$
      MessageDialog.openInformation(
          getShell(),
          JREMessages.InstalledJREsBlock_12,
          NLS.bind(JREMessages.InstalledJREsBlock_13, new String[] {messagePath})); //
    } else {
      Iterator<IVMInstallType> iter2 = types.iterator();
      for (File location : locations) {
        IVMInstallType type = iter2.next();
        AbstractVMInstall vm = new VMStandin(type, createUniqueId(type));
        String name = location.getName();
        String nameCopy = new String(name);
        int i = 1;
        while (isDuplicateName(nameCopy)) {
          nameCopy = name + '(' + i++ + ')';
        }
        vm.setName(nameCopy);
        vm.setInstallLocation(location);
        if (type instanceof AbstractVMInstallType) {
          // set default java doc location
          AbstractVMInstallType abs = (AbstractVMInstallType) type;
          vm.setJavadocLocation(abs.getDefaultJavadocLocation(location));
          vm.setVMArgs(abs.getDefaultVMArguments(location));
        }
        vmAdded(vm);
      }
    }
  }