Пример #1
0
  protected void openSXFM(BasicGraphEditor editor, File file)
      throws IOException, FeatureModelException {

    VariamosGraphEditor variamosEditor = (VariamosGraphEditor) editor;
    variamosEditor.editModelReset();

    SXFMReader reader = new SXFMReader();
    AbstractModel pl = reader.readFile(file.getAbsolutePath());

    variamosEditor.editModel(pl);

    editor.setCurrentFile(file);
    resetEditor(variamosEditor);
  }
Пример #2
0
  public void actionPerformed(ActionEvent e) {
    BasicGraphEditor editor = getEditor(e);

    if (editor != null) {
      ((MainFrame) editor.getFrame()).waitingCursor(true);
      if (!editor.isModified()
          || JOptionPane.showConfirmDialog(editor, mxResources.get("loseChanges"))
              == JOptionPane.YES_OPTION) {
        mxGraph graph = editor.getGraphComponent().getGraph();

        if (graph != null) {
          String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir");

          JFileChooser fc = new JFileChooser(wd);

          // Adds file filter for supported file format
          DefaultFileFilter defaultFilter =
              new DefaultFileFilter(".plg", mxResources.get("defaultExtension") + " (.plg)") {

                public boolean accept(File file) {
                  String lcase = file.getName().toLowerCase();

                  return lcase.endsWith(".plg") || lcase.endsWith(".sxfm");
                }
              };
          // fc.addChoosableFileFilter(defaultFilter);

          fc.addChoosableFileFilter(
              new DefaultFileFilter(".sxfm", mxResources.get("sxfmExtension") + " (.sxfm)"));

          fc.setFileFilter(defaultFilter);

          int rc = fc.showDialog(null, mxResources.get("openFile"));

          if (rc == JFileChooser.APPROVE_OPTION) {
            lastDir = fc.getSelectedFile().getParent();

            try {
              if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".sxfm")) {
                openSXFM(editor, fc.getSelectedFile());
              }
              //							else if (fc.getSelectedFile().getAbsolutePath()
              //									.toLowerCase().endsWith(".txt"))
              //							{
              //								openGD(editor, fc.getSelectedFile(),
              //										mxUtils.readFile(fc
              //												.getSelectedFile()
              //												.getAbsolutePath()));
              //							}
              else {
                //								Document document = mxXmlUtils
                //										.parseXml(mxUtils.readFile(fc
                //												.getSelectedFile()
                //												.getAbsolutePath()));
                //
                //								mxCodec codec = new mxCodec(document);
                //								codec.decode(
                //										document.getDocumentElement(),
                //										graph.getModel());
                VariamosGraphEditor variamosEditor = (VariamosGraphEditor) editor;
                // variamosEditor.editModelReset();

                PLGReader.loadPLG(fc.getSelectedFile(), graph);
                editor.setCurrentFile(fc.getSelectedFile());
                SharedActions.afterSaveGraph(graph, variamosEditor);
                variamosEditor.populateIndex(((AbstractGraph) graph).getProductLine());
                resetEditor(variamosEditor);
              }
            } catch (IOException | FeatureModelException ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  editor.getGraphComponent(),
                  ex.toString(),
                  mxResources.get("error"),
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        }
      }
      ((MainFrame) editor.getFrame()).waitingCursor(false);
    }
  }