示例#1
0
  @Override
  public EditorCell findCell(final EditorComponent editorComponent) {
    if (myCellId != null) {
      final EditorContext editorContext = editorComponent.getEditorContext();
      if (myNodeReference == null) return null;

      final EditorCell[] cell = new EditorCell[] {null};
      editorContext
          .getRepository()
          .getModelAccess()
          .runReadAction(
              new Runnable() {
                @Override
                public void run() {
                  cell[0] =
                      editorComponent.findCellWithId(
                          myNodeReference.resolve(editorContext.getRepository()), myCellId);
                }
              });
      return cell[0];
    } else if (myParentInfo != null) {
      EditorCell parentCell = myParentInfo.findCell(editorComponent);
      if (!(parentCell instanceof EditorCell_Collection)) {
        return null;
      }
      EditorCell_Collection parentCollection = (EditorCell_Collection) parentCell;
      if (myCellNumber >= parentCollection.getCellsCount()) {
        return null;
      }
      EditorCell editorCell = parentCollection.getChildAt(myCellNumber);
      // This editorCell should not have any cellId due to corresponding conditions in constructor
      return editorCell.getCellId() == null ? editorCell : null;
    }
    return null;
  }
示例#2
0
 /*package*/ static void runEditorComponentAction(
     EditorComponent editorComponent, CellActionType actionType) {
   EditorCellAction action = editorComponent.getComponentAction(CellActionType.UP);
   EditorContext editorContext = editorComponent.getEditorContext();
   if (action != null && action.canExecute(editorContext)) {
     action.execute(editorContext);
   }
 }
示例#3
0
 @Nullable
 public EditorState saveState(boolean full) {
   BaseEditorState result = new BaseEditorState();
   EditorContext editorContext = getEditorContext();
   if (editorContext != null) {
     result.myMemento = editorContext.createMemento(full);
     EditorComponent editorComponent = getCurrentEditorComponent();
     if (editorComponent instanceof NodeEditorComponent) {
       NodeEditorComponent nodeEditorComponent = (NodeEditorComponent) editorComponent;
       EditorComponent inspector = nodeEditorComponent.getInspector();
       if (inspector != null) {
         EditorContext inspectorContext = inspector.getEditorContext();
         if (inspectorContext != null) {
           result.myInspectorMemento = inspectorContext.createMemento(full);
         }
       }
     }
   }
   return result;
 }
示例#4
0
  public void loadState(@NotNull EditorState state) {
    if (!(state instanceof BaseEditorState)) return;

    final BaseEditorState s = (BaseEditorState) state;
    if (s.myMemento != null) {
      assert myEditorComponent != null;
      assert myEditorComponent.getEditorContext() != null;

      getEditorContext().setMemento(s.myMemento);
    }
    if (s.myInspectorMemento != null) {
      final NodeEditorComponent editorComponent = (NodeEditorComponent) getCurrentEditorComponent();
      if (editorComponent != null) {
        if (editorComponent.getInspector() != null) {
          editorComponent.getInspector().getEditorContext().setMemento(s.myInspectorMemento);
        } else {
          SwingUtilities.invokeLater(
              new Runnable() {
                int tries = 0;

                @Override
                public void run() {
                  EditorComponent inspector = editorComponent.getInspector();
                  if (inspector != null) {
                    inspector.getEditorContext().setMemento(s.myInspectorMemento);
                  } else if ((tries++) < 3) {
                    try {
                      Thread.sleep(tries * 500);
                    } catch (InterruptedException ignore) {
                    }
                    SwingUtilities.invokeLater(this);
                  } else {
                    LOG.error("couln't restore inspector state: no inspector tool");
                  }
                }
              });
        }
      }
    }
  }
示例#5
0
 public EditorContext getEditorContext() {
   return myEditorComponent == null ? null : myEditorComponent.getEditorContext();
 }