Пример #1
0
 private void addRule() {
   // We must add it just after the currently selected Rule.
   // Let's find which one it is. If there is none, we add it at the
   // end of the list.
   MultiInputPanel mip = new MultiInputPanel(I18N.tr("Choose a name for your rule"));
   mip.addInput("RuleName", I18N.tr("Name of the Rule : "), new TextBoxType(10));
   mip.addValidation(
       new MIPValidation() {
         @Override
         public String validate(MultiInputPanel mid) {
           String ruleName = mid.getInput("RuleName");
           return ruleName.isEmpty() ? I18N.tr("Rule name cannot be null or empty.") : null;
         }
       });
   if (UIFactory.showDialog(mip)) {
     String s = mip.getInput("RuleName");
     LegendTreeModel tm = (LegendTreeModel) tree.getModel();
     // We need to link our new RuleWrapper with the layer we are editing.
     Rule temp = new Rule(simpleStyleEditor.getStyleWrapper().getStyle().getLayer());
     temp.setName(s);
     Legend leg =
         LegendFactory.getLegend(temp.getCompositeSymbolizer().getSymbolizerList().get(0));
     // Initialize a panel for this legend.
     ILegendPanel ilp = ILegendPanelFactory.getILegendPanel(simpleStyleEditor, leg);
     List<ILegendPanel> list = new ArrayList<ILegendPanel>();
     list.add(ilp);
     RuleWrapper nrw = new RuleWrapper(simpleStyleEditor, temp, list);
     tm.addElement(tm.getRoot(), nrw, getSelectedRule());
     simpleStyleEditor.legendAdded(nrw.getPanel());
   }
 }
Пример #2
0
 /**
  * Copy the default docking layout to the specified file path.
  *
  * @param savedDockingLayout
  */
 private void copyDefaultDockingLayout(File savedDockingLayout) {
   InputStream xmlFileStream =
       DockingManagerImpl.class.getResourceAsStream("default_docking_layout.xml");
   if (xmlFileStream != null) {
     try {
       FileOutputStream writer = new FileOutputStream(savedDockingLayout);
       try {
         byte[] buffer = new byte[BUFFER_LENGTH];
         for (int n; (n = xmlFileStream.read(buffer)) != -1; ) {
           writer.write(buffer, 0, n);
         }
       } finally {
         writer.close();
       }
     } catch (FileNotFoundException ex) {
       LOGGER.error(I18N.tr("Unable to save the docking layout."), ex);
     } catch (IOException ex) {
       LOGGER.error(I18N.tr("Unable to save the docking layout."), ex);
     } finally {
       try {
         xmlFileStream.close();
       } catch (IOException ex) {
         LOGGER.error(I18N.tr("Unable to save the docking layout."), ex);
       }
     }
   }
 }
Пример #3
0
 /** A method to save the workspace : documents and layout */
 public void onMenuSaveApplication() {
   if (!isShutdownVetoed()) {
     mainContext.saveStatus(); // Save the services status
     // Save dialogs status
     saveSIFState();
     // Save layout
     dockManager.saveLayout();
     LOGGER.info(I18N.tr("The workspace has been saved."));
   } else {
     LOGGER.info(I18N.tr("The workspace hasn't been saved."));
   }
 }
Пример #4
0
 /**
  * Recursive function to parse a layer tree
  *
  * @param lt
  * @param parentLayer
  */
 private void parseJaxbLayer(LayerType lt, ILayer parentLayer) throws LayerException {
   // Test if lt is a group
   if (!lt.getLayer().isEmpty() || (lt.getDataURL() == null)) {
     // it will create a LayerCollection
     parseJaxbLayerCollection(lt, parentLayer);
   } else {
     // it corresponding to a leaf layer
     // We need to read the data declaration and create the layer
     URLType dataUrl = lt.getDataURL();
     if (dataUrl != null) {
       OnlineResourceType resType = dataUrl.getOnlineResource();
       try {
         URI layerURI = new URI(resType.getHref());
         // The resource is given as relative to MapContext location
         if (!layerURI.isAbsolute() && getLocation() != null) {
           try {
             // Resolve the relative resource ex: new Uri("myFile.shp")
             layerURI = getLocation().resolve(layerURI);
           } catch (IllegalArgumentException ex) {
             LOGGER.warn(
                 "Error while trying to find an absolute path for an external resource", ex);
           }
         }
         // Get table name
         ILayer leafLayer = createLayer(layerURI);
         leafLayer.setDescription(new Description(lt));
         leafLayer.setVisible(!lt.isHidden());
         // Parse styles
         if (lt.isSetStyleList()) {
           for (StyleType st : lt.getStyleList().getStyle()) {
             if (st.isSetSLD()) {
               if (st.getSLD().isSetAbstractStyle()) {
                 leafLayer.addStyle(
                     new Style(
                         (JAXBElement<net.opengis.se._2_0.core.StyleType>)
                             st.getSLD().getAbstractStyle(),
                         leafLayer));
               }
             }
           }
         }
         parentLayer.addLayer(leafLayer);
       } catch (URISyntaxException ex) {
         throw new LayerException(
             I18N.tr("Unable to parse the href URI {0}.", resType.getHref()), ex);
       } catch (InvalidStyle ex) {
         throw new LayerException(
             I18N.tr("Unable to load the description of the layer {0}", lt.getTitle().toString()),
             ex);
       }
     }
   }
 }
Пример #5
0
  private void initialize(ProgressMonitor parentProgress) {
    ProgressMonitor progress = parentProgress.startTask(I18N.tr("Loading the main window"), 100);
    makeMainFrame();
    progress.endTask();
    progress.setTaskName(I18N.tr("Loading docking system and frames"));
    // Initiate the docking management system
    DockingManagerImpl dockManagerImpl = new DockingManagerImpl(mainFrame);
    dockManager = dockManagerImpl;
    mainFrame.setDockingManager(dockManager);
    // Initiate the docking panel tracker
    singleFrameTracker =
        new DockingPanelTracker(pluginFramework.getHostBundleContext(), dockManager);
    singleFrameTracker.open();
    toolBarTracker =
        new MenuItemServiceTracker<MainWindow, ToolBarAction>(
            pluginFramework.getHostBundleContext(),
            ToolBarAction.class,
            dockManagerImpl,
            mainFrame);
    toolBarTracker.open();
    progress.endTask();

    // Load the log panels
    makeLoggingPanels();
    progress.endTask();

    // Load the editor factories manager
    makeEditorManager(dockManager);
    progress.endTask();

    // Load the GeoCatalog
    makeGeoCatalogPanel();
    progress.endTask();

    // Load Built-ins Editors
    loadEditorFactories();
    progress.endTask();

    progress.setTaskName(I18N.tr("Restore the former layout.."));
    // Load the docking layout and editors opened in last OrbisGis instance
    File savedDockingLayout = new File(viewWorkspace.getDockingLayoutPath());
    if (!savedDockingLayout.exists()) {
      // Copy the default docking layout
      // First OrbisGIS start
      copyDefaultDockingLayout(savedDockingLayout);
    }
    dockManager.setDockingLayoutPersistanceFilePath(viewWorkspace.getDockingLayoutPath());
    progress.endTask();
    addCoreMenu();
  }
Пример #6
0
 /** Add new menu to the OrbisGIS core */
 private void addCoreMenu() {
   DefaultAction def =
       new DefaultAction(
           MainFrameAction.MENU_SAVE,
           I18N.tr("&Save"),
           OrbisGISIcon.getIcon("save"),
           EventHandler.create(ActionListener.class, this, "onMenuSaveApplication"));
   def.setParent(MainFrameAction.MENU_FILE).setBefore(MainFrameAction.MENU_EXIT);
   mainFrame.addMenu(def);
   def.setToolTipText(I18N.tr("Save the workspace"));
   JButton saveBt = new CustomButton(def);
   saveBt.setHideActionText(true);
   mainFrame.addToolBarComponent(saveBt, "align left");
 }
Пример #7
0
 public PluginShell(final BundleContext hostBundle) {
   super(new BorderLayout());
   this.hostBundle = hostBundle;
   parameters.setName("plugin-shell");
   parameters.setTitle(I18N.tr("Plugin Shell"));
   parameters.setTitleIcon(new ImageIcon(PluginShell.class.getResource("panel_icon.png")));
   outputField.setEditable(false);
   outputField.setText(I18N.tr("Plugin shell, type \"help\" for command list.\n"));
   // Initialising components
   // The shell is composed by a logging part and a command line part
   add(new JScrollPane(outputField), BorderLayout.CENTER);
   add(commandField, BorderLayout.SOUTH);
   commandField.addActionListener(
       EventHandler.create(ActionListener.class, this, "onValidateCommand"));
 }
Пример #8
0
 /** Adds the empty dialog to the card layout. */
 private void addEmptyDialog() {
   JPanel textHolder = new JPanel(new BorderLayout());
   JLabel text = new JLabel(I18N.tr("Add or select a legend."));
   text.setHorizontalAlignment(SwingConstants.CENTER);
   textHolder.add(text, BorderLayout.CENTER);
   dialogContainer.add(NO_LEGEND_ID, textHolder);
 }
Пример #9
0
 @Override
 public ILayer createLayer(URI source) throws LayerException {
   if (!source.isAbsolute()) {
     // If URI is not absolute ex URI.create("../folder/myfile.shp"), then create a canonical URI
     try {
       source =
           new File(location != null ? new File(location) : new File("./"), source.toString())
               .getCanonicalFile()
               .toURI();
     } catch (IOException ex) {
       throw new LayerException(ex);
     }
   }
   String layerName;
   try {
     layerName = FileUtils.getNameFromURI(source);
   } catch (UnsupportedOperationException ex) {
     try {
       layerName = dataManager.findUniqueTableName(I18N.tr("Layer"));
     } catch (SQLException ex2) {
       throw new LayerException(ex2);
     }
   }
   return createLayer(layerName, source);
 }
Пример #10
0
 private void setJAXBObject(OWSContextType jaxbObject) {
   if (isOpen()) {
     throw new IllegalStateException(
         I18N.tr("The map must be closed to invoke this method")); // $NON-NLS-1$
   }
   this.jaxbMapContext = (OWSContextType) jaxbObject;
 }
Пример #11
0
  @Override
  public void close(ProgressMonitor pm) {

    checkIsOpen();

    // Backup Consistent data
    jaxbMapContext = getJAXBObject();

    // Close the layers
    if (pm == null) {
      pm = new NullProgressMonitor();
    }
    ILayer[] layers = layerModel.getLayersRecursively();
    for (int i = 0; i < layers.length; i++) {
      pm.progressTo(i * 100 / layers.length);
      if (!layers[i].acceptsChilds()) {
        try {
          layers[i].close();
        } catch (LayerException e) {
          LOGGER.error(I18N.tr("Cannot close layer {0}", layers[i].getName()));
        }
      }
    }
    layerModel.removeLayerListenerRecursively(openerListener);
    this.open = false;
  }
Пример #12
0
  /**
   * Validates this descriptor based on the passed query parameters.
   *
   * @param queryParams parameters to validate against
   * @throws ParameterValidationException when a validation fails
   */
  public void validate(MultivaluedMap<String, String> queryParams)
      throws ParameterValidationException {
    if (!queryParams.containsKey(name)) {
      // Check for mandatory property
      if (isMandatory) {
        throw new ParameterValidationException(name, i18n.tr("Required parameter."));
      }
      // If this parameter was not specified and is
      // not mandatory there is nothing to validate.
      return;
    }

    if (this.mustBeInt) {
      validateInteger(queryParams.get(name));
    }

    if (this.dateFormat != null && !this.dateFormat.isEmpty()) {
      validateDate(queryParams.get(name));
    }

    if (this.mustBeTimeZone) {
      validateTimeZone(queryParams.get(name));
    }

    if (this.validators.size() > 0) {
      verifyValidatorsPass(queryParams.get(name));
    }

    verifyMustHaves(queryParams);
    verifyMustNotHaves(queryParams);
  }
Пример #13
0
 /** Init the SIF ui factory */
 private void initSIF() {
   UIFactory.setDefaultImageIcon(OrbisGISIcon.getIcon("orbisgis")); // Load SIF properties
   try {
     UIFactory.loadState(new File(viewWorkspace.getSIFPath()));
   } catch (IOException ex) {
     LOGGER.error(I18N.tr("Error while loading dialogs informations."), ex);
   }
 }
Пример #14
0
  private Pool findPool(String poolId) {
    Pool pool = poolCurator.find(poolId);

    if (pool == null) {
      throw new BadRequestException(i18n.tr("Pool with id {0} could not be found.", poolId));
    }
    return pool;
  }
Пример #15
0
 private void verifyMustHaves(MultivaluedMap<String, String> queryParams) {
   for (String paramToCheck : this.mustHaveParams) {
     if (!queryParams.containsKey(paramToCheck)) {
       throw new ParameterValidationException(
           name, i18n.tr("Parameter must be used with {0}.", paramToCheck));
     }
   }
 }
Пример #16
0
 private void saveSIFState() {
   // Load SIF properties
   try {
     UIFactory.saveState(new File(viewWorkspace.getSIFPath()));
   } catch (IOException ex) {
     LOGGER.error(I18N.tr("Error while saving dialogs informations."), ex);
   }
 }
Пример #17
0
  private Cdn verifyAndLookupCdn(String label) {
    Cdn cdn = curator.lookupByLabel(label);

    if (cdn == null) {
      throw new NotFoundException(i18n.tr("No such content delivery network: {0}", label));
    }
    return cdn;
  }
Пример #18
0
  /** Initialize all the buttons that can be used to manage the tree content. */
  private void initButtons() {
    toolBar = new JToolBar();
    toolBar.setFloatable(false);

    jButtonMenuUp = new JButton();
    jButtonMenuUp.setIcon(OrbisGISIcon.getIcon("go-up"));
    jButtonMenuUp.setToolTipText(I18N.tr("Up"));
    ActionListener alu = EventHandler.create(ActionListener.class, this, "moveSelectedElementUp");
    jButtonMenuUp.addActionListener(alu);
    toolBar.add(jButtonMenuUp);

    jButtonMenuDown = new JButton();
    jButtonMenuDown.setIcon(OrbisGISIcon.getIcon("go-down"));
    jButtonMenuDown.setToolTipText(I18N.tr("Down"));
    ActionListener ald = EventHandler.create(ActionListener.class, this, "moveSelectedElementDown");
    jButtonMenuDown.addActionListener(ald);
    toolBar.add(jButtonMenuDown);

    JButton jButtonMenuAdd = new JButton();
    jButtonMenuAdd.setIcon(OrbisGISIcon.getIcon("picture_add"));
    jButtonMenuAdd.setToolTipText(I18N.tr("Add"));
    ActionListener aladd = EventHandler.create(ActionListener.class, this, "addElement");
    jButtonMenuAdd.addActionListener(aladd);
    jButtonMenuAdd.setFocusPainted(false);
    toolBar.add(jButtonMenuAdd);

    jButtonMenuDel = new JButton();
    jButtonMenuDel.setIcon(OrbisGISIcon.getIcon("picture_delete"));
    jButtonMenuDel.setToolTipText(I18N.tr("Delete"));
    ActionListener alrem = EventHandler.create(ActionListener.class, this, "removeSelectedElement");
    jButtonMenuDel.addActionListener(alrem);
    toolBar.add(jButtonMenuDel);

    jButtonMenuRename = new JButton();
    jButtonMenuRename.setIcon(OrbisGISIcon.getIcon("picture_edit"));
    jButtonMenuRename.setToolTipText(I18N.tr("Rename"));
    jButtonMenuRename.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            renameElement(evt);
          }
        });
    toolBar.add(jButtonMenuRename);
  }
Пример #19
0
 public MapTransform() {
   adjustExtent = true;
   if (!GraphicsEnvironment.isHeadless()) {
     this.dpi = Toolkit.getDefaultToolkit().getScreenResolution();
   } else {
     LOGGER.trace(I18N.tr("Headless graphics environment, set current DPI to 96.0"));
     this.dpi = DEFAULT_DPI;
   }
 }
Пример #20
0
  private ActivationKey findKey(String activationKeyId) {
    ActivationKey key = activationKeyCurator.find(activationKeyId);

    if (key == null) {
      throw new BadRequestException(
          i18n.tr("ActivationKey with id {0} could not be found.", activationKeyId));
    }
    return key;
  }
Пример #21
0
 @Override
 public void draw(MapTransform mt, ProgressMonitor pm, ILayer layer) {
   // Layer must be from this layer model
   if (!isLayerFromThisLayerModel(layer)) {
     throw new IllegalStateException(
         I18N.tr("Layer provided for drawing is not from the map context layer model."));
   }
   drawImpl(mt, pm, layer);
 }
Пример #22
0
 @Override
 public Color getColor(Map<String, Object> map) throws ParameterException {
   try {
     return Color.getColor(getFieldValue(map).toString());
   } catch (ParameterException e) {
     throw new ParameterException(
         I18N.tr("Could not fetch feature attribute \"{0}\"", getColumnName()), e);
   }
 }
Пример #23
0
 /** Returns an ImageIcon, or null if the path was invalid. */
 protected static ImageIcon createImageIcon(String path) {
   java.net.URL imgURL = LegendUIChooser.class.getResource(path);
   if (imgURL != null) {
     return new ImageIcon(imgURL);
   } else {
     LOGGER.error(I18N.tr("Couldn't find file") + ": " + path);
     return null;
   }
 }
Пример #24
0
 /**
  * Core constructor, init Model instances
  *
  * @param debugMode Show additional information for debugging purposes
  * @note Call startup() to init Swing
  */
 public Core(CoreWorkspaceImpl coreWorkspace, boolean debugMode, LoadingFrame splashScreen)
     throws InvocationTargetException, InterruptedException {
   ProgressMonitor parentProgress = splashScreen.getProgressMonitor();
   ProgressMonitor progressInfo = parentProgress.startTask(I18N.tr("Loading Workspace.."), 100);
   MainContext.initConsoleLogger(debugMode);
   // Declare empty main frame
   mainFrame = new MainFrame();
   // Set the main frame position and size
   mainFrame.setSize(MAIN_VIEW_SIZE);
   // Try to set the frame at the center of the default screen
   try {
     GraphicsDevice device =
         GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     Rectangle screenBounds = device.getDefaultConfiguration().getBounds();
     mainFrame.setLocation(
         screenBounds.x + screenBounds.width / 2 - MAIN_VIEW_SIZE.width / 2,
         screenBounds.y + screenBounds.height / 2 - MAIN_VIEW_SIZE.height / 2);
   } catch (Throwable ex) {
     LOGGER.error(ex.getLocalizedMessage(), ex);
   }
   UIFactory.setMainFrame(mainFrame);
   initMainContext(debugMode, coreWorkspace, splashScreen);
   progressInfo.progressTo(10);
   this.viewWorkspace = new ViewWorkspace(this.mainContext.getCoreWorkspace());
   Services.registerService(
       ViewWorkspace.class, I18N.tr("Contains view folders path"), viewWorkspace);
   progressInfo.setTaskName(I18N.tr("Register GUI Sql functions.."));
   addSQLFunctions();
   progressInfo.progressTo(11);
   // Load plugin host
   progressInfo.setTaskName(I18N.tr("Load the plugin framework.."));
   startPluginHost();
   progressInfo.progressTo(18);
   progressInfo.setTaskName(I18N.tr("Connecting to the database.."));
   // Init database
   try {
     mainContext.initDataBase(
         coreWorkspace.getDataBaseUser(), coreWorkspace.getDataBasePassword());
   } catch (SQLException ex) {
     throw new RuntimeException(ex.getLocalizedMessage(), ex);
   }
   initSIF();
   progressInfo.progressTo(20);
 }
Пример #25
0
 private void validateInteger(List<String> values) {
   for (String val : values) {
     try {
       Integer.parseInt(val);
     } catch (NumberFormatException nfe) {
       throw new ParameterValidationException(
           name, i18n.tr("Parameter must be an Integer value."));
     }
   }
 }
Пример #26
0
  /**
   * Retrieves a Product instance for the product with the specified id. If no matching product
   * could be found, this method throws an exception.
   *
   * @param productUuid The ID of the product to retrieve
   * @throws NotFoundException if no matching product could be found with the specified id
   * @return the Product instance for the product with the specified id
   */
  protected Product fetchProduct(String productUuid) {
    Product product = this.productCurator.find(productUuid);

    if (product == null) {
      throw new NotFoundException(
          i18n.tr("Product with UUID ''{0}'' could not be found.", productUuid));
    }

    return product;
  }
Пример #27
0
  @Override
  public Color getColor(ResultSet rs, long fid) throws ParameterException {
    try {
      return Color.getColor(getFieldValue(rs, fid).toString());
    } catch (SQLException e) {

      throw new ParameterException(
          I18N.tr("Could not fetch feature attribute \"{0}\"", getColumnName()), e);
    }
  }
Пример #28
0
  /**
   * Execute the command with this shell line.
   *
   * @param _line The shell line enter by the user.
   * @return The shell string return to display at the user.
   * @throws InterruptedIOException The execution can cause a interruption of the console screen.
   *     (Exit/Quit/Shutdown)
   * @see com.connectlife.coreserver.console.ShellCmd#execute(java.lang.String)
   */
  @Override
  public String execute(String _line) throws InterruptedIOException {

    String response = "";
    m_logger.debug(SHELL_CMD);

    // TODO: Complete command
    response = SHELL_CMD + i18n.tr(" not supported yet!");

    return response;
  }
Пример #29
0
 private void startPluginHost() {
   try {
     mainContext.startBundleHost(BundleFromResources.SPECIFIC_BEHAVIOUR_BUNDLES);
     pluginFramework = mainContext.getPluginHost();
     pluginFramework
         .getHostBundleContext()
         .registerService(org.orbisgis.viewapi.workspace.ViewWorkspace.class, viewWorkspace, null);
   } catch (Exception ex) {
     LOGGER.error(I18N.tr("Loading of plugins is aborted"), ex);
   }
 }
Пример #30
0
 /**
  * Creates a CDN
  *
  * @return a Cdn object
  * @httpcode 200
  */
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Cdn create(Cdn cdn, @Context Principal principal) {
   Cdn existing = curator.lookupByLabel(cdn.getLabel());
   if (existing != null) {
     throw new BadRequestException(
         i18n.tr("A CDN with the label {0}" + "already exists", cdn.getLabel()));
   }
   return curator.create(cdn);
 }