Browse Source

代码质量

research/10.0
yaoh.wu 6 years ago
parent
commit
366810a296
  1. 12
      designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java
  2. 26
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java
  3. 31
      designer-base/src/main/java/com/fr/file/FileNodeFILE.java
  4. 54
      designer-base/src/test/java/com/fr/env/RemoteEnvPaneTest.java

12
designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java

@ -21,7 +21,7 @@ import com.fr.stable.ProductConstants;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.third.org.apache.commons.io.FilenameUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.server.lock.TplLockOperator; import com.fr.workspace.server.lock.TplOperator;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ButtonModel; import javax.swing.ButtonModel;
@ -693,18 +693,16 @@ public class MutilTempalteTabPane extends JComponent {
specifiedTemplate.saveTemplate(); specifiedTemplate.saveTemplate();
HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate);
// release lock // release lock
if (!WorkContext.getCurrent().isLocal()) { WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(specifiedTemplate.getPath());
WorkContext.getCurrent().get(TplLockOperator.class).closeAndFreeFile(specifiedTemplate.getPath());
}
activeTemplate(filename); activeTemplate(filename);
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName()));
} }
} else { } else {
HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate);
// release lock // release lock
if (!WorkContext.getCurrent().isLocal()) { WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(specifiedTemplate.getPath());
WorkContext.getCurrent().get(TplLockOperator.class).closeAndFreeFile(specifiedTemplate.getPath());
}
activeTemplate(filename); activeTemplate(filename);
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName()));
} }

26
designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

@ -4,7 +4,6 @@
package com.fr.design.file; package com.fr.design.file;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.io.FileAssistUtilsOperator;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
@ -22,7 +21,7 @@ import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.server.lock.TplLockOperator; import com.fr.workspace.server.lock.TplOperator;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -312,19 +311,10 @@ public class TemplateTreePane extends JPanel implements FileOperations {
if (node instanceof FileNode) { if (node instanceof FileNode) {
FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node); FileNodeFILE nodeFILE = new FileNodeFILE((FileNode) node);
if (nodeFILE.exists()) { if (nodeFILE.exists()) {
if (isLocal) { if (WorkContext.getCurrent().get(TplOperator.class).delete(nodeFILE.getPath())) {
FileAssistUtilsOperator fileAssistUtils = WorkContext.getCurrent().get(FileAssistUtilsOperator.class); HistoryTemplateListCache.getInstance().deleteFile(nodeFILE);
if (fileAssistUtils.moveToTrash(nodeFILE.getPath())) {
HistoryTemplateListCache.getInstance().deleteFile(nodeFILE);
} else {
success = false;
}
} else { } else {
if (WorkContext.getCurrent().get(TplLockOperator.class).delete(nodeFILE.getPath())) { success = false;
HistoryTemplateListCache.getInstance().deleteFile(nodeFILE);
} else {
success = false;
}
} }
} }
} }
@ -422,12 +412,8 @@ public class TemplateTreePane extends JPanel implements FileOperations {
} }
try { try {
if (WorkContext.getCurrent().isLocal()) { // 接收的是WEB-INF下的路径
// com.fr.io.utils.ResourceIOUtils 接收的是WEB-INF下的路径 return WorkContext.getCurrent().get(TplOperator.class).rename(from, to);
return WorkContext.getWorkResource().rename(from, to);
} else {
return WorkContext.getCurrent().get(TplLockOperator.class).rename(from, to);
}
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false; return false;

31
designer-base/src/main/java/com/fr/file/FileNodeFILE.java

@ -15,7 +15,7 @@ import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.resource.WorkResourceTempRenameStream; import com.fr.workspace.resource.WorkResourceTempRenameStream;
import com.fr.workspace.server.lock.TplLockOperator; import com.fr.workspace.server.lock.TplOperator;
import javax.swing.Icon; import javax.swing.Icon;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -357,26 +357,15 @@ public class FileNodeFILE implements FILE {
if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) { if (!envPath.startsWith(ProjectConstants.REPORTLETS_NAME)) {
return null; return null;
} }
InputStream in; InputStream in = new ByteArrayInputStream(
if (WorkContext.getCurrent().isLocal()) { WorkContext.getCurrent().get(TplOperator.class).readAndLockFile(
in = new ByteArrayInputStream( StableUtils.pathJoin(
WorkContext.getWorkResource().readFully( ProjectConstants.REPORTLETS_NAME,
StableUtils.pathJoin( envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)
ProjectConstants.REPORTLETS_NAME, )
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1) )
) );
)
);
} else {
in = new ByteArrayInputStream(
WorkContext.getCurrent().get(TplLockOperator.class).readAndLockFile(
StableUtils.pathJoin(
ProjectConstants.REPORTLETS_NAME,
envPath.substring(ProjectConstants.REPORTLETS_NAME.length() + 1)
)
)
);
}
return envPath.endsWith(".cpt") || envPath.endsWith(".frm") return envPath.endsWith(".cpt") || envPath.endsWith(".frm")
? XMLEncryptUtils.decodeInputStream(in) : in; ? XMLEncryptUtils.decodeInputStream(in) : in;
} }

54
designer-base/src/test/java/com/fr/env/RemoteEnvPaneTest.java vendored

@ -0,0 +1,54 @@
package com.fr.env;
import org.fest.swing.annotation.RunsInEDT;
import org.fest.swing.core.ComponentLookupScope;
import org.fest.swing.core.Robot;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.fixture.JPanelFixture;
import org.fest.swing.junit.testcase.FestSwingJUnitTestCase;
import org.junit.Test;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import static org.fest.swing.edt.GuiActionRunner.execute;
public class RemoteEnvPaneTest extends FestSwingJUnitTestCase {
@Override
protected void onSetUp() {
}
@Test
public void test() {
Robot robot = robot();
robot.settings().componentLookupScope(ComponentLookupScope.ALL);
JPanelFixture rootFixture = new JPanelFixture(robot, createNewEditor());
rootFixture.checkBox("httpsCheckbox").check();
rootFixture.checkBox("httpsCheckbox").requireSelected();
}
@RunsInEDT
private static RemoteEnvPane createNewEditor() {
return execute(new GuiQuery<RemoteEnvPane>() {
@Override
protected RemoteEnvPane executeInEDT() {
RemoteEnvPane envPane = new RemoteEnvPane();
JFrame frame = new JFrame();
frame.getContentPane().add(envPane);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
return envPane;
}
});
}
}
Loading…
Cancel
Save